This is an official k6 extension, it's a client library for Redis database. Check out the extension's documentation here.
Add the extension's import
import redis from "k6/x/redis";Define the client
import redis from "k6/x/redis";
// Instantiate a new Redis client using a URL.
// The connection will be established on the first command call.
const client = new redis.Client('redis://localhost:6379');Call the API from the VU context
export default function () {
redisClient.sadd("crocodile_ids", ...crocodileIDs);
...
}The most common and simple case is to use k6 with automatic extension resolution. Simply add the extension's import and k6 will resolve the dependency automtically.
However, if you prefer to build it from source using xk6, first ensure you have the prerequisites:
- Go toolchain
- Git
Then:
- Install
xk6:
go install go.k6.io/xk6/cmd/xk6@latest- Build the binary:
xk6 build --with github.com/grafana/xk6-redis