我已经习惯了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);
    }
}

最佳答案

我终于找到了。因为当我的redis启动进程时,我的redis会尝试获取密钥。现在我把它放入redis的回调函数get function into redis start everything works fine

关于node.js - Catbox-redis在我的hapijs应用程序上显示断开连接的错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41779511/

10-12 12:26