No results for

Powered byAlgolia
⚠️ This is archived documentation for v0.40.

You can configure the Redis Client at construction time with the Options object. We recommend passing the options to the constructor as an argument, then passing the most common options, such as the addrs and password, to the constructor from the environment.

The following snippet provides an example:

import redis from 'k6/experimental/redis';
// Get the redis instance(s) address and password from the environment
const redis_addrs = __ENV.REDIS_ADDRS || '';
const redis_password = __ENV.REDIS_PASSWORD || '';
// Instantiate a new redis client
const redisClient = new redis.Client({
addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas
password: redis_password,
});
export default function () {
// do something with the redis client
}

Options

Option nametypedefaultdescription
addrsstring[]Array of addresses in the 'host:port' defining which connect Redis to connect to. Supplying a single entry would connect the client to a single Redis instance. Supplying multiple entries would connect the client to a cluster/sentinel nodes.
dbnumber (optional)0The id of the database to be selected after connecting to the server. Only used when connecting to a single-node use.
usernamestring (optional)Username to authenticate the client connection with.
passwordstring (optional)Password to authenticate the client connection with.
sentinelUsernamestring (optional)Username to authenticate the client connection with when connecting to a sentinel.
sentinelPasswordstring (optional)Password to authenticate the client connection with when connecting to a sentinel.
masterNamestring (optional)The name of the master to connect to when connecting to a Redis cluster.
maxRetriesnumber (optional)0The maximum number of retries to attempt when connecting to a Redis server before giving up.
minRetryBackoffnumber (optional)8 (ms)The minimum amount of time to wait between retries when connecting to a Redis server.
maxRetryBackoffnumber (optional)512 (ms)The maximum amount of time to wait between retries when connecting to a Redis server.
dialTimeoutnumber (optional)5 (seconds)The maximum amount of time to wait for a connection to a Redis server to be established.
readTimeoutnumber (optional)3 (seconds)The maximum amount of time to wait for socket reads to succeed. Use -1 for no timeout.
writeTimeoutnumber (optional)readTimeoutThe maximum amount of time to wait for a socket write to succeed. Use -1 for no timeout.
poolSizenumber (optional)10 (per CPU)The maximum number of socket connections to keep open in the connection pool.
minIdleConnsnumber (optional)The minimum number of idle connections to keep open in the connection pool.
maxIdleConnsnumber (optional)The maximum number of idle connections to keep open in the connection pool.
maxConnAgenumber (optional)0The maximum amount of time a connection can be idle in the connection pool before being closed.
poolTimeoutnumber (optional)readTimeout + 1The maximum amount of time to wait for a connection to the Redis server to be returned from the pool.
idleTimeoutnumber (optional)readTimeout + 1The maximum amount of time the client waits for a connection to become active before timing out.
idleCheckFrequencynumber (optional)1 (minute)The frequency at which the client checks for idle connections in the connection pool. Use -1 to disable the checks.