question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

redis 4: ERR_INVALID_ARG_TYPE The "chunk" argument must be of type string

See original GitHub issue

Error

TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer. Received type function ([Function])

at validChunk (_stream_writable.js:281:10)
at Socket.Writable.write (_stream_writable.js:316:21)
at RedisSocket.writeCommand (\node_modules\@node-redis\client\dist\lib\client\socket.js:57:130)
at Commander._RedisClient_tick (\node_modules\@node-redis\client\dist\lib\client\index.js:421:64)
at Commander._RedisClient_sendCommand (\node_modules\@node-redis\client\dist\lib\client\index.js:402:82)
at Commander.sendCommand (\node_modules\@node-redis\client\dist\lib\client\index.js:356:93)
at Commander.<computed>.<computed> (\node_modules\@node-redis\client\dist\lib\client\index.js:390:27)
at new RedisAdapter (\node_modules\@socket.io\redis-adapter\dist\index.js:75:28)
at new <anonymous> (\node_modules\@socket.io\redis-adapter\dist\index.js:45:16)
at Namespace._initAdapter (\node_modules\socket.io\dist\namespace.js:40:24)

package.json

"dependencies": {
    "@socket.io/redis-adapter": "^7.1.0",
    "express": "^4.17.2",
    "express-socket.io-session": "^1.3.5",
    "redis": "^4.0.1",
    "socket.io": "^4.4.1",
    "socket.io-client": "^4.4.1",
}

Example of implementation

import { createAdapter } from '@socket.io/redis-adapter';
import * as redis from 'redis';
import * as SocketIO from 'socket.io';

// ...

const socketServer = new SocketIO.Server( ... );

const pubClient = redis.createClient({
    url: `redis://localhost:6379`,
    legacyMode: true,
});
const subClient = pubClient.duplicate();

await pubClient.connect();
await subClient.connect();

socketServer.adapter(createAdapter(pubClient, subClient));

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cesco69commented, Jan 11, 2022

yes, with legacyMode: false it works!

0reactions
darrachequesnecommented, Jan 13, 2022

@cesco69 that’s an interesting idea! Would you have time to open a pull request?

Read more comments on GitHub >

github_iconTop Results From Across the Web

The "chunk" argument must be of type string or an instance of ...
In case this may help someone, I was using data type other than String , Number to be exact, so I changed it...
Read more >
TypeError [ERR_INVALID_ARG_TYPE] - appsloveworld
Coding example for the question TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array ...
Read more >
The "chunk" argument must be one of type string or Buffer ...
TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be one of type string or Buffer. Received type object.
Read more >
Redis-specific parameters - Amazon ElastiCache for Redis
If you do not specify a parameter group for your Redis cluster, then a default ... If you need to use one of...
Read more >
Understanding the Top 5 Redis Performance Metrics - Datadog
Using critical Redis metrics to troubleshoot performance issues ... 4. Redis stores more than just strings . ... only string data types as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found