redis

package module
v0.0.0-...-7e73bfa Latest Latest
Warning

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

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

README

xk6-redis

This is a k6 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!

Build

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

Then:

  1. Clone xk6:
git clone https://github.com/k6io/xk6.git
cd xk6
  1. Build the binary:
CGO_ENABLED=1 go run ./cmd/xk6/main.go build master \
  --with github.com/skryukov/xk6-redis

Example

import redis from 'k6/x/redis';

const client = redis.newClient();

export function setup() {
  redis.set(client,"snake","camel",0)
  redis.set(client,"foo",100,10)
}

export default function () {
  console.log(redis.get(client,"snake"))
  console.log(redis.get(client,"foo"))
  if (redis.do(client,"PING","bzzz") == "bzzz"){
    console.log("PONG!")
  }
}

export function teardown () {
  redis.del(client,"foo")
}

Result output:

$ ./k6 run script.js

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

  execution: local
     script: ../example.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] bar                                           source=console
INFO[0000] PONG!                                         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

    █ setup

    █ teardown

    data_received........: 0 B 0 B/s
    data_sent............: 0 B 0 B/s
    iteration_duration...: avg=544.06µs min=428.6µs med=597.41µs max=606.18µs p(90)=604.43µs p(95)=605.31µs
    iterations...........: 1   46.10603/s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReportError

func ReportError(err error, msg string)

ReportError is a handy function to show errors

Types

type REDIS

type REDIS struct{}

REDIS is the k6 Redis extension.

func (*REDIS) Del

func (*REDIS) Del(client *redis.Client, keys ...string)

Del removes a key/value

func (*REDIS) Do

func (*REDIS) Do(client *redis.Client, args ...interface{}) interface{}

Do runs arbitrary/custom commands

func (*REDIS) Get

func (*REDIS) Get(client *redis.Client, key string) string

Get gets a key/value

func (*REDIS) NewClient

func (*REDIS) NewClient(addr string, password string, bd int) *redis.Client

NewClient creates a new Redis client

func (*REDIS) Set

func (*REDIS) Set(client *redis.Client, key string, value interface{}, expiration time.Duration)

Set adds a key/value

Jump to

Keyboard shortcuts

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