【发布时间】:2017-03-15 21:54:48
【问题描述】:
我曾经使用过 catbox-redis 插件,但是当我运行代码时出现断开连接错误。当我搜索出现此错误的位置时,我发现它来自 catbox lib client.js isReady 函数
如果有这方面的问题,请帮助我
{
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);
}
}
【问题讨论】:
-
您不是在测试 client.start 函数中的错误吗?另外,我不会在处理程序中启动 redis 客户端,而是通过插件。
-
在 client.start 函数中我没有得到任何错误。我只会在插件中启动redis,目前我这样检查以便于理解