|
1 | 1 | ---
|
2 |
| -title: 'Redis options' |
| 2 | +title: 'Options' |
3 | 3 | excerpt: 'Options allow to fine tune how a Redis client behaves and interacts with a Redis server or cluster.'
|
4 | 4 | weight: 20
|
5 | 5 | ---
|
6 | 6 |
|
7 | 7 | # Redis options
|
8 | 8 |
|
9 |
| -You can configure the [Redis Client](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/redis/client) at construction time with the [Options](#options) object. |
10 |
| -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. |
| 9 | +You can configure the [Redis Client](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/redis/client) either by using a Redis connection URL as demonstrated in the [client documentation](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/redis/client#usage) or using an [Options](#options) object to access more advanced configuration. |
11 | 10 |
|
12 |
| -The following snippet provides an example: |
| 11 | +## Options |
13 | 12 |
|
14 |
| -```javascript |
15 |
| -import redis from 'k6/experimental/redis'; |
| 13 | +Configuration for the overall Redis client, including authentication and connection settings. |
16 | 14 |
|
17 |
| -// Get the redis instance(s) address and password from the environment |
18 |
| -const redis_addrs = __ENV.REDIS_ADDRS || ''; |
19 |
| -const redis_password = __ENV.REDIS_PASSWORD || ''; |
| 15 | +| Option Name | Type | Description | |
| 16 | +| ---------------- | ------------------------------------------------------------------ | ----------------------------------------------------------------------- | |
| 17 | +| socket | [SocketOptions](#socket-connection-options-socketoptions) | Configuration of connection socket used to connect to the redis server. | |
| 18 | +| username | String (optional) | Username for client authentication. | |
| 19 | +| password | String (optional) | Password for client authentication. | |
| 20 | +| clientName | String (optional) | Name for the client connection. | |
| 21 | +| database | Number (optional) | Database ID to select after connecting. | |
| 22 | +| masterName | String (optional) | Master instance name for Sentinel. | |
| 23 | +| sentinelUsername | String (optional) | Username for Sentinel authentication. | |
| 24 | +| sentinelPassword | String (optional) | Password for Sentinel authentication. | |
| 25 | +| cluster | [ClusterOptions](#redis-cluster-options-clusteroptions) (optional) | Configuration for Redis Cluster connections. | |
20 | 26 |
|
21 |
| -// Instantiate a new redis client |
22 |
| -const redisClient = new redis.Client({ |
23 |
| - addrs: redis_addrs.split(',') || new Array('localhost:6379'), // in the form of 'host:port', separated by commas |
24 |
| - password: redis_password, |
25 |
| -}); |
| 27 | +### Socket Connection Options |
26 | 28 |
|
27 |
| -export default function () { |
28 |
| - // do something with the redis client |
29 |
| -} |
30 |
| -``` |
| 29 | +Socket-level settings for connecting to a Redis server. |
31 | 30 |
|
32 |
| -## Options |
| 31 | +| Option Name | Type | Description | |
| 32 | +| ------------------ | -------------------------------------------------------------- | -------------------------------------------------------------------------------------- | |
| 33 | +| host | String | IP address or hostname of the Redis server. | |
| 34 | +| port | Number (optional) | Port number of the Redis server. | |
| 35 | +| tls | [TLSOptions](#tls-configuration-options-tlsoptions) (optional) | Configuration for TLS/SSL. | |
| 36 | +| dialTimeout | Number (optional, default is _5(seconds)_) | Timeout for establishing a connection, expressed in seconds. | |
| 37 | +| readTimeout | Number (optional, default is _3(seconds)_) | Timeout for socket reads, expressed in seconds. A value of `-1` disables the timeout. | |
| 38 | +| writeTimeout | Number (optional, default is `readTimeout`) | Timeout for socket writes, expressed in seconds. A value of `-1` disables the timeout. | |
| 39 | +| poolSize | Number (optional, default is _10 (per CPU)_) | Number of socket connections in the pool per CPU. | |
| 40 | +| minIdleConns | Number (optional) | Minimum number of idle connections in the pool. | |
| 41 | +| maxConnAge | Number (optional, default is _0_ (no maximum idle time)) | Maximum idle time before closing a connection. | |
| 42 | +| poolTimeout | Number (optional, `readTimeout + 1`) | Timeout for acquiring a connection from the pool. | |
| 43 | +| idleTimeout | Number (optional, `readTimeout + 1`) | Timeout for idle connections in the pool. | |
| 44 | +| idleCheckFrequency | Number (optional, default is _1 (minute)_) | Frequency of idle connection checks, in minutes. A value of `-1` disables the checks. | |
| 45 | + |
| 46 | +#### TLS Configuration Options |
| 47 | + |
| 48 | +Options for establishing a secure TLS connection. |
| 49 | + |
| 50 | +| Option Name | Type | Description | |
| 51 | +| ----------- | ---------------------- | --------------------------------------------------- | |
| 52 | +| ca | ArrayBuffer[] | Array of CA certificates. | |
| 53 | +| cert | ArrayBuffer (optional) | Client certificate for mutual TLS. | |
| 54 | +| key | ArrayBuffer (optional) | Private key associated with the client certificate. | |
| 55 | + |
| 56 | +### Redis Cluster Options |
| 57 | + |
| 58 | +Options for behavior in a Redis Cluster setup. |
33 | 59 |
|
34 |
| -| Option name | type | default | description | |
35 |
| -| :------------------- | :---------------- | :---------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
36 |
| -| `addrs` | string[] | | 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. | |
37 |
| -| `db` | number (optional) | 0 | The id of the database to be selected after connecting to the server. Only used when connecting to a single-node use. | |
38 |
| -| `username` | string (optional) | | Username to authenticate the client connection with. | |
39 |
| -| `password` | string (optional) | | Password to authenticate the client connection with. | |
40 |
| -| `sentinelUsername` | string (optional) | | Username to authenticate the client connection with when connecting to a sentinel. | |
41 |
| -| `sentinelPassword` | string (optional) | | Password to authenticate the client connection with when connecting to a sentinel. | |
42 |
| -| `masterName` | string (optional) | | The name of the master to connect to when connecting to a Redis cluster. | |
43 |
| -| `maxRetries` | number (optional) | 0 | The maximum number of retries to attempt when connecting to a Redis server before giving up. | |
44 |
| -| `minRetryBackoff` | number (optional) | 8 (ms) | The minimum amount of time to wait between retries when connecting to a Redis server. | |
45 |
| -| `maxRetryBackoff` | number (optional) | 512 (ms) | The maximum amount of time to wait between retries when connecting to a Redis server. | |
46 |
| -| `dialTimeout` | number (optional) | 5 (seconds) | The maximum amount of time to wait for a connection to a Redis server to be established. | |
47 |
| -| `readTimeout` | number (optional) | 3 (seconds) | The maximum amount of time to wait for socket reads to succeed. Use `-1` for no timeout. | |
48 |
| -| `writeTimeout` | number (optional) | `readTimeout` | The maximum amount of time to wait for a socket write to succeed. Use `-1` for no timeout. | |
49 |
| -| `poolSize` | number (optional) | 10 (per CPU) | The maximum number of socket connections to keep open in the connection pool. | |
50 |
| -| `minIdleConns` | number (optional) | | The minimum number of idle connections to keep open in the connection pool. | |
51 |
| -| `maxIdleConns` | number (optional) | | The maximum number of idle connections to keep open in the connection pool. | |
52 |
| -| `maxConnAge` | number (optional) | 0 | The maximum amount of time a connection can be idle in the connection pool before being closed. | |
53 |
| -| `poolTimeout` | number (optional) | `readTimeout + 1` | The maximum amount of time to wait for a connection to the Redis server to be returned from the pool. | |
54 |
| -| `idleTimeout` | number (optional) | `readTimeout + 1` | The maximum amount of time the client waits for a connection to become active before timing out. | |
55 |
| -| `idleCheckFrequency` | number (optional) | 1 (minute) | The frequency at which the client checks for idle connections in the connection pool. Use `-1` to disable the checks. | |
| 60 | +| Option Name | Type | Description | |
| 61 | +| -------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | |
| 62 | +| maxRedirects | Number (optional, default is _3_ retries) | Maximum number of command redirects. | |
| 63 | +| readOnly | Boolean (optional) | Enables read-only mode for replicas. | |
| 64 | +| routeByLatency | Boolean (optional) | Route read commands by latency. | |
| 65 | +| routeRandomly | Boolean (optional) | Random routing for read commands. | |
| 66 | +| nodes | String[] or [SocketOptions](#socket-connection-options-socketoptions)[] | List of cluster nodes as URLs or [SocketOptions](#socket-connection-options-socketoptions). | |
0 commit comments