redis客户端node.js版本,支持连接池。
安装
npm i @td/node-redis;
Redis
客户端使用的是ioredis
example
;// Redis的使用请参考ioredis库// 哨兵模式使用demo const 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;redis;
RedisPool 连接池的使用
RedisPool(options)构造方法参数说明:
- logger 日志实例,默认为console
- poolOptions 连接池配置,详细配置参见generic-pool opts
- redisOptions redis客户端配置,详细配置参见ioredis
example
;// Redis的使用请参考ioredis库// 哨兵模式使用demo const pool = 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: // 默认最小连接数为1,最大连接数为10,根据实际需要设置 min: 2 max: 10 ;pool;