@abeai/node-redis 中文文档教程
Wrapper for ioredis.
Overview
redis 模块提供了 promisified redis 命令。
Installation
npm install @abeai/node-redis
Instantiation
With afterInitialization
hook
const redis = require('@abeai/node-redis');
redis.init(host, options);
// Will wait until the redis client is created and connected to server
redis.afterInitialization(function() {
redis.client().get('some_key')
.then((value) => {
console.log(value);
})
.catch((err) => {
console.log(err, 'Failed to get some_key');
})
;
});
Without afterInitialization
hook
const redis = require('@abeai/node-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
ioredis 选项的键值字典。
logger
客户端使用的自定义记录器。
client()
通过 返回包含所有标准 redis 命令 的 redis 客户端实例奥雷迪斯。 命令函数名称是小写的,所有函数都返回一个承诺。
afterInitialization()
附加到底层 redis 客户端的 ready
事件 的处理程序。 这只会在客户端第一次连接到服务器时调用一次。
onReady()
附加到底层 redis 客户端的 ready
事件 的处理程序。 每次客户端连接到服务器(包括重新连接)时都会调用此方法。
Wrapper for ioredis.
Overview
The redis module provides promisified redis commands.
Installation
npm install @abeai/node-redis
Instantiation
With afterInitialization
hook
const redis = require('@abeai/node-redis');
redis.init(host, options);
// Will wait until the redis client is created and connected to server
redis.afterInitialization(function() {
redis.client().get('some_key')
.then((value) => {
console.log(value);
})
.catch((err) => {
console.log(err, 'Failed to get some_key');
})
;
});
Without afterInitialization
hook
const redis = require('@abeai/node-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.
Options
redis
Key value dictionary of ioredis options.
logger
Custom logger to be used by client.
client()
Returns the redis client instance which includes all standard redis commands via ioredis. The command function names are lowercase and all functions return a promise.
afterInitialization()
Handler attached to the underlying redis client's ready
event. This is only called once when the client connects to the server for the first time.
onReady()
Handler attached to the underlying redis client's ready
event. This is called every time the client connects to the server including reconnects.