我和docker
和redis
一起玩,我想从官方码头形象开始
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应用程序中,我试图连接到容器,但是它失败了,我得到了以下错误:
➜ 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)
这是我的密码:
(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);
})();
为什么我不能连接到红色容器?
发布于 2022-10-02 08:44:01
只能设置字符串或数字:
client.set("bla", true);
应该是
client.set("bla", "true");
https://stackoverflow.com/questions/73924324
复制相似问题