Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Got Invalid argument type error when connect to redis container

I’m playing with docker and redis and I want to start redis from the official docker image:

docker run -p 6379:6379 redis
1:C 02 Oct 2022 08:11:14.410 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 02 Oct 2022 08:11:14.410 # Redis version=7.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 02 Oct 2022 08:11:14.410 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 02 Oct 2022 08:11:14.410 * monotonic clock: POSIX clock_gettime
1:M 02 Oct 2022 08:11:14.411 * Running mode=standalone, port=6379.
1:M 02 Oct 2022 08:11:14.411 # Server initialized
1:M 02 Oct 2022 08:11:14.412 * Ready to accept connections

In my nodejs application I try to connect to the container but it failed and I got this error:

âžś  red node app
connect!!! Promise { <pending> }
/Users/user/myapp/red/node_modules/@redis/client/dist/lib/client/RESP2/encoder.js:17
            throw new TypeError('Invalid argument type');
                  ^

TypeError: Invalid argument type
    at encodeCommand (/Users/user/myapp/red/node_modules/@redis/client/dist/lib/client/RESP2/encoder.js:17:19)
    at RedisCommandsQueue.getCommandToSend (/Users/user/myapp/red/node_modules/@redis/client/dist/lib/client/commands-queue.js:187:45)
    at Commander._RedisClient_tick (/Users/user/myapp/red/node_modules/@redis/client/dist/lib/client/index.js:440:76)
    at Commander._RedisClient_sendCommand (/Users/user/myapp/red/node_modules/@redis/client/dist/lib/client/index.js:424:82)
    at Commander.commandsExecutor (/Users/user/myapp/red/node_modules/@redis/client/dist/lib/client/index.js:170:154)
    at Commander.BaseClass.<computed> [as set] (/Users/user/myapp/red/node_modules/@redis/client/dist/lib/commander.js:8:29)
    at /Users/user/myapp/red/app.js:17:10
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

This is my code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

(async () => {
  const redis = require("redis");
  const client = redis.createClient({
    socket: {
      host: "localhost",
      port: 6379,
    },
    // password: '<password>'
  });

  client.on("error", (err) => {
    console.log("Error " + err);
  });

  await client.connect();

  client.set("bla", true);
  const y = client.get("bla");

  console.log("connect!!!", y);
})();

Why I can’t able to connect to redis container?

>Solution :

You can only set strings or numbers:

client.set("bla", true);

should be

client.set("bla", "true");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading