redis

package module
v0.0.0-...-6e153c2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2021 License: AGPL-3.0 Imports: 5 Imported by: 0

README

xk6-redis

This is a Redis client library for k6, implemented as an extension using the xk6 system.

❗ This is a proof of concept, isn't supported by the k6 team, and may break in the future. USE AT YOUR OWN RISK!

Note that there is already a k6 Redis extension that uses a different Go library and slightly different API. The extension in this current repo served as an example for an xk6 tutorial article, but using one or the other is up to the user. :)

Build

To build a k6 binary with this extension, first ensure you have the prerequisites:

Then:

  1. Install xk6:
go get -u github.com/k6io/xk6/cmd/xk6
  1. Build the binary:
xk6 build v0.29.0 --with github.com/k6io/xk6-redis

Example test script

// test.js
import redis from 'k6/x/redis';

const client = new redis.Client({
  addr: 'localhost:6379',
  password: '',
  db: 0,
});

export default function () {
  client.set('mykey', 'myvalue', 0);
  console.log(`mykey => ${client.get('mykey')}`);
}

Result output:

$ ./k6 run test.js

          /\      |‾‾| /‾‾/   /‾‾/
     /\  /  \     |  |/  /   /  /
    /  \/    \    |     (   /   ‾‾\
   /          \   |  |\  \ |  (‾)  |
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: test.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0000] mykey => myvalue                              source=console

running (00m00.0s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  00m00.0s/10m0s  1/1 iters, 1 per VU

    data_received........: 0 B 0 B/s
    data_sent............: 0 B 0 B/s
    iteration_duration...: avg=834.68µs min=834.68µs med=834.68µs max=834.68µs p(90)=834.68µs p(95)=834.68µs
    iterations...........: 1   54.622575/s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the Redis client wrapper.

func (*Client) Get

func (c *Client) Get(key string) (string, error)

Get returns the value for the given key.

func (*Client) Incr

func (c *Client) Incr(key string) int64

increase the given key with the given value and expiration time.

func (*Client) Set

func (c *Client) Set(key, value string, exp time.Duration)

Set the given key with the given value and expiration time.

type Redis

type Redis struct{}

Redis is the k6 extension for a Redis client.

func (*Redis) XClient

func (r *Redis) XClient(ctxPtr *context.Context, opts *redis.Options) interface{}

XClient represents the Client constructor (i.e. `new redis.Client()`) and returns a new Redis client object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL