td-redis
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

redis客户端node.js版本,支持连接池。

安装

npm i @td/node-redis;

Redis

客户端使用的是ioredis

example

import Redis from '@td/node-redis';
// Redis的使用请参考ioredis库
// 哨兵模式使用demo
 
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)构造方法参数说明:

  • logger 日志实例,默认为console
  • poolOptions 连接池配置,详细配置参见generic-pool opts
  • redisOptions redis客户端配置,详细配置参见ioredis

example

import { RedisPool } from '@td/node-redis';
// Redis的使用请参考ioredis库
// 哨兵模式使用demo
 
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: { // 默认最小连接数为1,最大连接数为10,根据实际需要设置
    min: 2,
    max: 10
  }
});
pool.acquire().then(client => {
  client.set('test', 'xxx');
  client.release(); // 使用完后一定要记得释放连接。
});

Readme

Keywords

none

Package Sidebar

Install

npm i td-redis

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

167 kB

Total Files

7

Last publish

Collaborators

  • zhengfeng.yao