Skip to content

Latest commit

 

History

History
83 lines (70 loc) · 10.2 KB

client-configuration.md

File metadata and controls

83 lines (70 loc) · 10.2 KB

createClient configuration

PropertyDefaultDescription
urlredis[s]://[[username][:password]@][host][:port][/db-number] (see redis and rediss IANA registration for more details)
socketSocket connection properties. Unlisted net.connect properties (and tls.connect) are also supported
socket.port6379Redis server port
socket.host'localhost'Redis server hostname
socket.family0IP Stack version (one of 4 | 6 | 0)
socket.pathPath to the UNIX Socket
socket.connectTimeout5000Connection timeout (in milliseconds)
socket.noDelaytrueToggle Nagle's algorithm
socket.keepAlivetrueToggle keep-alive functionality
socket.keepAliveInitialDelay5000If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket
socket.tlsSee explanation and examples below
socket.reconnectStrategyExponential backoff with a maximum of 2000 ms; plus 0-200 ms random jitter.A function containing the Reconnect Strategy logic
usernameACL username (see ACL guide)
passwordACL password or the old "--requirepass" password
nameClient name (see CLIENT SETNAME)
databaseRedis database number (see SELECT command)
modulesIncluded Redis Modules
scriptsScript definitions (see Lua Scripts)
functionsFunction definitions (see Functions)
commandsQueueMaxLengthMaximum length of the client's internal command queue
disableOfflineQueuefalseDisables offline queuing, see FAQ
readonlyfalseConnect in READONLY mode
legacyModefalseMaintain some backwards compatibility (see the Migration Guide)
isolationPoolOptionsSee the Isolated Execution Guide
pingIntervalSend PING command at interval (in ms). Useful with "Azure Cache for Redis"

Reconnect Strategy

When the socket closes unexpectedly (without calling .quit()/.disconnect()), the client uses reconnectStrategy to decide what to do. The following values are supported:

  1. false -> do not reconnect, close the client and flush the command queue.
  2. number -> wait for X milliseconds before reconnecting.
  3. (retries: number, cause: Error) => false | number | Error -> number is the same as configuring a number directly, Error is the same as false, but with a custom error.

By default the strategy uses exponential backoff, but it can be overwritten like so:

createClient({socket: {reconnectStrategy: retries=>{// Generate a random jitter between 0 – 200 ms:constjitter=Math.floor(Math.random()*200);// Delay is an exponential back off, (times^2) * 50 ms, with a maximum value of 2000 ms:constdelay=Math.min(Math.pow(2,retries)*50,2000);returndelay+jitter;}}});

TLS

To enable TLS, set socket.tls to true. Below are some basic examples.

For configuration options see tls.connect and tls.createSecureContext, as those are the underlying functions used by this library.

Create a SSL client

createClient({socket: {tls: true,ca: '...',cert: '...'}});

Create a SSL client using a self-signed certificate

createClient({socket: {tls: true,rejectUnauthorized: false,cert: '...'}});
close