1
0
mirror of https://github.com/redis/node-redis.git synced 2025-07-31 05:44:24 +03:00
Files
node-redis/docs/client-configuration.md
Leibale Eidelman 3b1bad2296 Add support for sharded PubSub (#2373)
* refactor pubsub, add support for sharded pub sub

* run tests in redis 7 only, fix PUBSUB SHARDCHANNELS test

* add some comments and fix some bugs

* PubSubType, not PubSubTypes 🤦‍♂️

* remove test.txt

* fix some bugs, add tests

* add some tests

* fix #2345 - allow PING in PubSub mode (remove client side validation)

* remove .only

* revert changes in cluster/index.ts

* fix tests minimum version

* handle server sunsubscribe

* add 'sharded-channel-moved' event to docs, improve the events section in the main README (fix #2302)

* exit "resubscribe" if pubsub not active

* Update commands-queue.ts

* Release client@1.5.0-rc.0

* WIP

* use `node:util` instead of `node:util/types` (to support node 14)

* run PubSub resharding test with Redis 7+

* fix inconsistency in live resharding test

* add some tests

* fix iterateAllNodes when starting from a replica

* fix iterateAllNodes random

* fix slotNodesIterator

* fix slotNodesIterator

* clear pubSubNode when node in use

* wait for all nodes cluster state to be ok before testing

* `cluster.minimizeConections` tests

* `client.reconnectStrategry = false | 0` tests

* sharded pubsub + cluster 🎉

* add minimum version to sharded pubsub tests

* add cluster sharded pubsub live reshard test, use stable dockers for tests, make sure to close pubsub clients when a node disconnects from the cluster

* fix "ssubscribe & sunsubscribe" test

* lock search docker to 2.4.9

* change numberOfMasters default to 2

* use edge for bloom

* add tests

* add back getMasters and getSlotMaster as deprecated functions

* add some tests

* fix reconnect strategy + docs

* sharded pubsub docs

* Update pub-sub.md

* some jsdoc, docs, cluster topology test

* clean pub-sub docs

Co-authored-by: Simon Prickett <simon@redislabs.com>

* reconnect startegy docs and bug fix

Co-authored-by: Simon Prickett <simon@redislabs.com>

* refine jsdoc and some docs

Co-authored-by: Simon Prickett <simon@redislabs.com>

* I'm stupid

* fix cluster topology test

* fix cluster topology test

* Update README.md

* Update clustering.md

* Update pub-sub.md

Co-authored-by: Simon Prickett <simon@redislabs.com>
2023-01-25 11:00:39 -05:00

9.4 KiB

createClient configuration

Property Default Description
url redis[s]://[[username][:password]@][host][:port][/db-number] (see redis and rediss IANA registration for more details)
socket Socket connection properties. Unlisted net.connect properties (and tls.connect) are also supported
socket.port 6379 Redis server port
socket.host 'localhost' Redis server hostname
socket.family 0 IP Stack version (one of 4 | 6 | 0)
socket.path Path to the UNIX Socket
socket.connectTimeout 5000 Connection Timeout (in milliseconds)
socket.noDelay true Toggle Nagle's algorithm
socket.keepAlive 5000 Toggle 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 Client name (see CLIENT SETNAME)
database Redis database number (see SELECT command)
modules Included Redis Modules
scripts Script definitions (see Lua Scripts)
functions Function definitions (see Functions)
commandsQueueMaxLength Maximum length of the client's internal command queue
disableOfflineQueue false Disables offline queuing, see FAQ
readonly false Connect in READONLY mode
legacyMode false Maintain some backwards compatibility (see the Migration Guide)
isolationPoolOptions See the Isolated Execution Guide
pingInterval Send 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 is Math.min(retries * 50, 500), but it can be overwritten like so:

createClient({
  socket: {
    reconnectStrategy: retries => Math.min(retries * 50, 1000)
  }
});

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: '...'
  }
});