Catbox-redis 在我的 hapijs 应用程序上显示断开连接错误
Catbox-redis is showing disconnected error on my hapijs application
我曾经使用过 catbox-redis 插件,但是当我 运行 代码时,我遇到了断开连接的错误。当我搜索出现此错误的位置时,我发现它来自 catbox 库 client.js isReady function
如果有任何关于这方面的问题请帮助我
{
method : 'POST',
path : "/signup",
config : {
tags : ['api'],
description : 'Customer signup',
validate : {
failAction: Relish.failAction,
options : {
abortEarly: false,
},
payload : signupSchema,
}
},
handler: function(request, response){
let responseData = {
'message': 'Data inserted',
'errors': [],
'data': [
{
'id': 'name'
}
]
};
const options = {
//partition: 'examples', // For redis this will store items under keys that start with examples:
host: '127.0.0.1', // If you don't supply, 127.0.0.1 is the default
port: 6379, // If you don't supply, 6379 is the default
password: '' // If you don't supply, auth command not sent to redis
};
var client = new Catbox.Client(require('catbox-redis'), options); // Chance require('../') to 'catbox-redis' when running in your project
client.start((error) => {
console.log('Cache server started');
console.log('---------------------------------');
});
const key = {
segment: 'example',
id: 'myExample'
};
const cacheValue = 'my example';
const ttl = 10000; // How long item will be cached in milliseconds
client.get(key, (err, cached) => {
if (err) {
console.log(err);
}
else if (cached) {
return callback(null, 'From cache: ' + cached.item);
}
client.set(key, cacheValue, ttl, (error) => {
if(error)
console.log(error);
console.log("Cache was set on the redis");
console.log('---------------------------------');
});
});
return response(responseData);
}
}
我终于找到了。因为当我的 redis 启动进程进行异步时,我的 redis 试图获取密钥。现在我把它放到 redis 的回调中 get 函数进入 redis start 一切正常
我曾经使用过 catbox-redis 插件,但是当我 运行 代码时,我遇到了断开连接的错误。当我搜索出现此错误的位置时,我发现它来自 catbox 库 client.js isReady function
如果有任何关于这方面的问题请帮助我
{
method : 'POST',
path : "/signup",
config : {
tags : ['api'],
description : 'Customer signup',
validate : {
failAction: Relish.failAction,
options : {
abortEarly: false,
},
payload : signupSchema,
}
},
handler: function(request, response){
let responseData = {
'message': 'Data inserted',
'errors': [],
'data': [
{
'id': 'name'
}
]
};
const options = {
//partition: 'examples', // For redis this will store items under keys that start with examples:
host: '127.0.0.1', // If you don't supply, 127.0.0.1 is the default
port: 6379, // If you don't supply, 6379 is the default
password: '' // If you don't supply, auth command not sent to redis
};
var client = new Catbox.Client(require('catbox-redis'), options); // Chance require('../') to 'catbox-redis' when running in your project
client.start((error) => {
console.log('Cache server started');
console.log('---------------------------------');
});
const key = {
segment: 'example',
id: 'myExample'
};
const cacheValue = 'my example';
const ttl = 10000; // How long item will be cached in milliseconds
client.get(key, (err, cached) => {
if (err) {
console.log(err);
}
else if (cached) {
return callback(null, 'From cache: ' + cached.item);
}
client.set(key, cacheValue, ttl, (error) => {
if(error)
console.log(error);
console.log("Cache was set on the redis");
console.log('---------------------------------');
});
});
return response(responseData);
}
}
我终于找到了。因为当我的 redis 启动进程进行异步时,我的 redis 试图获取密钥。现在我把它放到 redis 的回调中 get 函数进入 redis start 一切正常