语法
2025年02月22日
一、认识
支持集群模式的客户端(例如 ioredis
、Jedis
等)可以直接连接任意一个节点,并自动获取集群槽映射信息,之后会根据键所在槽转发命令。
二、语法
const Redis = require('ioredis');
const cluster = new Redis.Cluster([
{ host: '127.0.0.1', port: 7000 },
{ host: '127.0.0.1', port: 7001 },
{ host: '127.0.0.1', port: 7002 },
]);
cluster.set('foo', 'bar')
.then(() => cluster.get('foo'))
.then(result => console.log(result))
.catch(err => console.error(err));