Skip to content

Commit

Permalink
Add support for node-redis v4.0.0 and newer
Browse files Browse the repository at this point in the history
- Fixes #8420
- v4.0.0 and newer of node-redis will no longer auto-connect, so we need to add that step
- For backwards compatibility, we check for the existence of a "v4" property so we don't try to call `connect` on older versions of the client
- A `legacyMode` flag exists in the new v4.0.0 of node-redis to keep a similar calling style without having to change any code
- This option can be passed via the createClient options, so I've added documentation to indicate that this is required if users would like to use v4.0.0 of node-redis
- Note that the legacyMode flag is **required** to be passed if the calling code isn't going to be changed
  • Loading branch information
aardvarkk committed Dec 3, 2021
1 parent a0f09de commit 3a4474b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ Example:
}
```

"options" can be [node_redis specific options](https://github.com/NodeRedis/node_redis#options-object-properties) or [ioredis specific options](https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options) depending on what type you're using.
"options" can be [node_redis specific options](https://github.com/redis/node-redis/blob/master/docs/client-configuration.md) or [ioredis specific options](https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options) depending on what type you're using.

If you are using node-redis v4.0.0 or newer, make sure to pass `legacyMode: true` in the "options" for the client to operate correctly.

In case you want to connect to a redis-cluster using IORedis's cluster functionality, you can do that as well by doing the following:

Expand Down
3 changes: 3 additions & 0 deletions src/cache/RedisQueryResultCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export class RedisQueryResultCache implements QueryResultCache {
} else {
this.client = this.redis.createClient();
}
if ("v4" in this.client) {
await this.client.connect();
}
} else if (this.clientType === "ioredis") {
if (cacheOptions && cacheOptions.port) {
if (cacheOptions.options) {
Expand Down

0 comments on commit 3a4474b

Please sign in to comment.