nodejs-docs-samples icon indicating copy to clipboard operation
nodejs-docs-samples copied to clipboard

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

Open rohank-gcp opened this issue 1 year ago • 1 comments

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!

rohank-gcp avatar Jan 08 '24 09:01 rohank-gcp

thanks @rohank-gcp; I'm working through this and will hopefully get the walk-throughs and this sample updated. Appreciate the thorough update here.

iennae avatar Jun 27 '24 07:06 iennae