Skip to content

Memorystore Redis Code Sample - Out of Sync with Node.js Redis 4.X Upgrade - Leads to ClientClosedError #3600

@rohank-gcp

Description

@rohank-gcp

In which file did you encounter the issue?

https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/memorystore/redis/server.js

Did you change the file? If so, how?

Not yet. But the recommendation is to replace below line -

const client = redis.createClient(REDISPORT, REDISHOST);

with

const client = redis.createClient({socket: {host: REDISHOST, port: REDISPORT}});
client.connect();

Describe the issue

  • The Github sample tutorial package.json was updated for Node redis package dependency from 3.X to 4.X recently.
  • Based on Node Redis package v3 to v4 migration guide, the new client no longer supports auto-connect functionality.
  • The main server.js code is not updated and still relies on auto-connect feature which got disabled as described earlier.
  • I tried running this code sample locally and get ClientClosedError error consistently -
    /home/test-user/nodejs-samples-latest/memorystore/redis/node_modules/@redis/client/dist/lib/client/index.js:511
          return Promise.reject(new errors_1.ClientClosedError());
                                ^
    ClientClosedError: The client is closed
      at Commander._RedisClient_sendCommand (/home/test-user/nodejs-samples- 
    latest/memorystore/redis/node_modules/@redis/client/dist/lib/client/index.js:511:31)
      at Commander.commandsExecutor (/home/test-user/nodejs-samples- 
    latest/memorystore/redis/node_modules/@redis/client/dist/lib/client/index.js:190:154)
      at Commander.BaseClass.<computed> [as incr] (/home/test-user/nodejs-samples- 
    latest/memorystore/redis/node_modules/@redis/client/dist/lib/commander.js:8:29)
      at Server.<anonymous> (/home/test-user/nodejs-samples-latest/memorystore/redis/server.js:30:12)
      at Server.emit (node:events:513:28)
      at parserOnIncoming (node:_http_server:998:12)
      at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)
    
  • Please update the code sample to fix this anomaly.

Thanks!

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.samplesIssues that are directly related to samples.triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions