首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当连接到redis容器时出现无效的参数类型错误

当连接到redis容器时出现无效的参数类型错误
EN

Stack Overflow用户
提问于 2022-10-02 08:16:35
回答 1查看 212关注 0票数 -1

我和dockerredis一起玩,我想从官方码头形象开始

代码语言:javascript
运行
复制
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

在我的nodejs应用程序中,我试图连接到容器,但是它失败了,我得到了以下错误:

代码语言:javascript
运行
复制
➜  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)

这是我的密码:

代码语言:javascript
运行
复制
(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);
})();

为什么我不能连接到红色容器?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-02 08:44:01

只能设置字符串或数字:

代码语言:javascript
运行
复制
client.set("bla", true);

应该是

代码语言:javascript
运行
复制
client.set("bla", "true");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73924324

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档