redis客户端node.js版本,支持连接池。
安装
npm i @td/node-redis;
Redis
客户端使用的是ioredis
example
import Redis from '@td/node-redis';
const redis = new Redis({
sentinels: [{ host: '10.57.17.210', port: 11110 }, { host: '10.57.17.210', port: 11112 }, { host: '10.57.17.210', port: 11113 }, { host: '10.57.17.210', port: 11114 }],
keyPrefix: 'prelude_',
name: 'master1',
password: 'testpass'
});
redis.set('test', 'xxx');
redis.disconnect();
RedisPool 连接池的使用
RedisPool(options)构造方法参数说明:
example
import { RedisPool } from '@td/node-redis';
const pool = new RedisPool({
redisOptions: {
sentinels: [{ host: '10.57.17.210', port: 11110 }, { host: '10.57.17.210', port: 11112 }, { host: '10.57.17.210', port: 11113 }, { host: '10.57.17.210', port: 11114 }],
keyPrefix: 'prelude_',
name: 'master1',
password: 'testpass'
},
poolOptions: {
min: 2,
max: 10
}
});
pool.acquire().then(client => {
client.set('test', 'xxx');
client.release();
});