Socket
Book a DemoInstallSign in
Socket

mc-node-redis

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mc-node-redis

redis客户端node版,基于ioredis与generic-pool

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

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

安装

npm i @mc/node-redis;

Redis

客户端使用的是ioredis

example

import Redis from '@mc/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 '@mc/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(); // 使用完后一定要记得释放连接。
});

FAQs

Package last updated on 28 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.