Wrapper for NodeRedis including node-redlock.
Overview
redis 模块提供了 promisified redis 命令函数以及 Redlock 算法的实现。
Installation
npm install @abeai/redis --save
Instantiation
const redis = require('@abeai/redis');
redis.init(host, options);
redis.client().get('some_key')
.then((value) => {
console.log(value);
})
.catch((err) => {
console.log(err, 'Failed to get some_key');
})
;
Interface
init(host[, options])
创建一个新的 redis 客户端实例,其中包含 的实例节点红锁模块。
Options
redis
NodeRedis 选项的键值字典。
redlock
node-redlock options 的键值字典。
client()
通过 返回包含所有标准 redis 命令 的 redis 客户端实例NodeRedis 如此处所述。 命令函数名称是小写的,所有函数都返回一个承诺。
虽然这个包确实在后台使用了 NodeRedis,但客户端的 promisified 函数名称不包含 NodeRedis 文档。
本文档将仅涵盖与 redis 命令无关的客户端功能,因为此信息在其他地方广泛可用。
client.lock(resource, ttl, fn)
使用 Redlock 算法锁定给定资源。 接受一个资源字符串,应该持有锁的毫秒 TTL,以及一个应该在资源被锁定时执行的承诺返回函数。
client.error(…args)
在 redis 连接的生命周期内用于错误事件的主要错误处理程序和 Redlock 处理。 覆盖此函数以提供自定义错误处理逻辑。
不应直接调用此函数。
client.retry(options)
在 redis 连接的生命周期内用于连接错误事件的主要重试处理程序。 覆盖此函数以提供自定义重试处理逻辑。
该功能由底层 NodeRedis 实例直接实现作为其重试策略,因此其实现细节可以在 此处 retry_strategy
选项下。
不应直接调用此函数。
Wrapper for NodeRedis including node-redlock.
Overview
The redis module provides promisified redis command functions along with an implementation of the Redlock algorithm.
Installation
npm install @abeai/redis --save
Instantiation
const redis = require('@abeai/redis');
redis.init(host, options);
redis.client().get('some_key')
.then((value) => {
console.log(value);
})
.catch((err) => {
console.log(err, 'Failed to get some_key');
})
;
Interface
init(host[, options])
Creates a new redis client instance which includes an instance of the node-redlock module.
Options
redis
Key value dictionary of NodeRedis options.
redlock
Key value dictionary of node-redlock options.
client()
Returns the redis client instance which includes all standard redis commands via NodeRedis as described here. The command function names are lowercase and all functions return a promise.
While this package does use NodeRedis under the hood, the client's promisified function names do not include the 'Async' suffix as described in the NodeRedis documentation.
This document will only cover client functions not related to redis commands as this information is widely available elsewhere.
client.lock(resource, ttl, fn)
Locks a given resource using the Redlock algorithm. Accepts a resource string, TTL of milliseconds that the lock should be held, and a promise returning function that should be executed while the resource is locked.
client.error(…args)
Main error handler used for error events over the lifetime of the redis connection and Redlock handling. Override this function to provide custom error handling logic.
This function should not be called directly.
client.retry(options)
Main retry handler used for connection error events over the lifetime of the redis connection. Override this function to provide custom retry handling logic.
This function is directly implemented by the underlying NodeRedis instance as its retry strategy and as such its implementation details can be found here under the retry_strategy
option.
This function should not be called directly.