我使用redis与docker-compose和socket-io,我得到未定义的值后,设置为redis

gj3fmq9x  于 12个月前  发布在  Redis
关注(0)|答案(1)|浏览(133)

[[My示例代码看起来像这样,它在localhost上工作得很好,我用docker run -p 6379:6379 -it启动了redis服务器redis/redis-stack-server:latest命令,但是当我用docker-compose文件启动redis服务器时,我在set命令上没有得到错误,但是在get命令上得到了未定义的值,为什么
docker-compose.yml文件是这样的版本:'3'服务:nginx:image:127.0.0.1:5000/socketmw_nginx build:./nginx链接:- socketio-1 - socketio-2 - socketio-3 - socketio-4端口:- '88:88'重启:总是
socketio-1:image:127.0.0.1:5000/socketmw_s1 build:./service links:- redis-adapter - redis-cache-db environment:- NAME=socketio-1 restart:always depends_on:- redis-adapter - redis-cache-db
socketio-2:image:127.0.0.1:5000/socketmw_s2 build:./service links:- redis-adapter - redis-cache-db environment:- NAME=socketio-2 restart:always depends_on:- redis-adapter - redis-cache-db
socketio-3:image:127.0.0.1:5000/socketmw_s3 build:./service links:- redis-adapter - redis-cache-db environment:- NAME=socketio-3 restart:always depends_on:- redis-adapter - redis-cache-db
socketio-4:image:127.0.0.1:5000/socketmw_s4 build:./service links:- redis-adapter - redis-cache-db environment:- NAME=socketio-4 restart:always depends_on:- redis-adapter - redis-cache-db
redis-adapter:image:redis:alpine restart:always
redis-cache-db:image:'redis:7.2.3' ports:- '6380:6380'命令:redis-server --保存10 1 --appendonly yes --port 6380

jexiocij

jexiocij1#

`my node js code is like this 
const redis_client = await createClient({
  url: `redis://${config.redis_db.redis_db_addr}:${config.redis_db.redis_db_port}`,
  legacyMode: true,
}).on('error', (err) => console.log('Redis Client Error', err)).connect();

await redis_client.set('sda', 'vasdsadsadsadaaalue');
const value = await redis_client.get('sda');
console.log('🚀 ~ file: index.js:9 ~ value:', value);
]

字符串

相关问题