K6 Redis Extension

In my never ending quest to migrate from jmeter to K6 (i’m close, so close) I now need to implement redis which we use to centrally store large volumes of test data.

I installed the K6 redis extension from GitHub - dgzlopes/xk6-redis: A k6 extension for Redis. but as far as i can tell it only supports the following commands. (unless I’m mistaken)

  • client connect
  • set (creates a string element)
  • get (gets a string element)
  • del (deletes a string element)

In jmeter we make extensive use of sets (a set of strings) with the following commands.

  • pipeline (to load large volumes of data)
  • sadd (to add sets)
  • srandmember (get a random value from a set)
  • srem (remove a value from a set)

Any idea whether this is possible or should I start learning to code in go :slight_smile:

Hi @BobRuub,
the extension’s API has a Do method, and as you can read from the comment, it can run any arbitrary or custom commands.

Using it, you should be able to write a raw Redis command using any provided by Redis’ protocol.

I did see that but have been unable to get it working despite many attempts.

redis.do(client,“sadd”,“foo”,“bar”);
redis.do(client,“sadd”,“foo bar”);
redis.do(client,“sadd”,“foo ,bar”);
redis.do(client,“sadd”,“‘foo’,‘bar’”);

all return “ERR wrong number of arguments for ‘sadd’ command Failed to do command”

As far as i am aware sadd only has two arguments, a setname and a string value.

I’m sure this is just a syntax issues but boy is it frustrating :slight_smile:

Hi @BobRuub,
a patch for supporting your case has been merged, you can check and re-build with the latest version from the main branch.

You should be able to do it now:

redis.do(client, "sadd", "foo", "bar");

Let me know if the fix worked for you.

Build failed for me, something I’m missing?

/Users/bob/go/bin/xk6 build --with github.com/dgzlopes/xk6-redis@latest
2022/01/19 22:22:23 [INFO] Temporary folder: /Users/bob/Documents/xk6/buildenv_2022-01-19-2222.1682490089
2022/01/19 22:22:23 [INFO] Writing main module: /Users/bob/Documents/xk6/buildenv_2022-01-19-2222.1682490089/main.go
2022/01/19 22:22:23 [INFO] Initializing Go module
2022/01/19 22:22:23 [INFO] exec (timeout=10s): /usr/local/go/bin/go mod init k6 
go: creating new go.mod: module k6
go: to add module requirements and sums:
        go mod tidy
2022/01/19 22:22:23 [INFO] Pinning versions
2022/01/19 22:22:23 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod edit -require go.k6.io/k6@latest 
2022/01/19 22:22:23 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod tidy 
go: finding module for package github.com/dgzlopes/xk6-redis
go: found github.com/dgzlopes/xk6-redis in github.com/dgzlopes/xk6-redis v0.0.0-20220118171753-64a721adc908
2022/01/19 22:22:25 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod edit -require github.com/dgzlopes/xk6-redis@latest 
2022/01/19 22:22:25 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod tidy 
2022/01/19 22:22:27 [INFO] Build environment ready
2022/01/19 22:22:27 [INFO] Building k6
2022/01/19 22:22:27 [INFO] exec (timeout=0s): /usr/local/go/bin/go mod tidy 
2022/01/19 22:22:27 [INFO] exec (timeout=0s): /usr/local/go/bin/go build -o /Users/bob/Documents/xk6/k6 -ldflags -w -s -trimpath 
# github.com/dgzlopes/xk6-redis
../../../go/pkg/mod/github.com/dgzlopes/xk6-redis@v0.0.0-20220118171753-64a721adc908/redis.go:33:19: not enough arguments in call to client.cmdable.Set
        have (string, interface {}, time.Duration)
        want (context.Context, string, interface {}, time.Duration)
../../../go/pkg/mod/github.com/dgzlopes/xk6-redis@v0.0.0-20220118171753-64a721adc908/redis.go:41:24: not enough arguments in call to client.cmdable.Get
        have (string)
        want (context.Context, string)
../../../go/pkg/mod/github.com/dgzlopes/xk6-redis@v0.0.0-20220118171753-64a721adc908/redis.go:50:19: cannot use key (type string) as type context.Context in argument to client.cmdable.Del:
        string does not implement context.Context (missing Deadline method)
../../../go/pkg/mod/github.com/dgzlopes/xk6-redis@v0.0.0-20220118171753-64a721adc908/redis.go:58:23: not enough arguments in call to client.Do
        have (...interface {})
        want (context.Context, ...interface {})
2022/01/19 22:22:27 [INFO] Cleaning up temporary folder: /Users/bob/Documents/xk6/buildenv_2022-01-19-2222.1682490089
2022/01/19 22:22:27 [FATAL] exit status 2

Hi @BobRuub,
I’m sorry for this error.

I pushed a fix in the repository, you should be able to build it now. If you get again the error it could be generated by the go proxy’s cache if you are using the @latest. You can use the @main version in the meanwhile as a workaround.

xk6 build --with github.com/dgzlopes/xk6-redis@main

Brilliant, sadd, srandmember and srem work a treat.

Haven’t had a chance to see If the pipeline works as yet but I’ll give it a try after work today.

Thanks for the help, I really appreciate it.

Hi,

Have been unable to get pipelining to work, not surprising as it creates a pipeline object which must be utilised for this purpose.

No biggy the user case for pipeline is limited (loading large data sets) and I can probably work on a better data management technique for this. Testing scripts are not the ideal place for this activity.

Thanks again,