Skip to content

Latest commit

 

History

History
65 lines (54 loc) · 8.54 KB

client-configuration.md

File metadata and controls

65 lines (54 loc) · 8.54 KB

createClient configuration

Property Default Description
url redis[s]://[[username][:password]@][host][:port][/db-number] (see redis and rediss IANA registration for more details)
socket Object defining socket connection properties. Any net.createConnection option that is not listed here is supported as well
socket.port 6379 Port to connect to
socket.host 'localhost' Hostname to connect to
socket.family 0 Version of IP stack. Must be 4 | 6 | 0. The value 0 indicates that both IPv4 and IPv6 addresses are allowed.
socket.path UNIX Socket to connect to
socket.connectTimeout 5000 The timeout for connecting to the Redis Server (in milliseconds)
socket.noDelay true Enable/disable the use of Nagle's algorithm
socket.keepAlive 5000 Enable/disable the keep-alive functionality
socket.tls See explanation and examples below
socket.reconnectStrategy retries => Math.min(retries * 50, 500) A function containing the Reconnect Strategy logic
username ACL username (see ACL guide)
password ACL password or the old "--requirepass" password
name Connection name (see CLIENT SETNAME)
database Database number to connect to (see SELECT command)
modules Object defining which Redis Modules to include
scripts Object defining Lua Scripts to use with this client (see Lua Scripts)
commandsQueueMaxLength Maximum length of the client's internal command queue
disableOfflineQueue false Disables offline queuing, see the FAQ for details
readonly false Connect in READONLY mode
legacyMode false Maintain some backwards compatibility (see the Migration Guide)
isolationPoolOptions See the Isolated Execution Guide

Reconnect Strategy

You can implement a custom reconnect strategy as a function:

  • Receives the number of retries attempted so far.
  • Returns number | Error:
    • number: the wait time in milliseconds prior attempting to reconnect.
    • Error: closes the client and flushes the internal command queues.

TLS

When creating a client, set socket.tls to true to enable TLS. 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: '...'
  }
});