Catbox-redis在我的hapijs应用程序上显示断开连接的错误 [英] Catbox-redis is showing disconnected error on my hapijs application

查看:108
本文介绍了Catbox-redis在我的hapijs应用程序上显示断开连接的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经使用过catbox-redis插件,但是当我运行代码时,出现了断开连接错误.当我搜索出现此错误的位置时,发现它来自catbox库 client.js isReady函数

I have used to catbox-redis plugin but when i run the code i got disconnected error. When i search where i get this error, i found that it was coming from the catbox lib client.js isReady function

如有任何疑问,请帮助我

If any about this please help me

    {
    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的回调中,将函数放入redis中,开始一切正常

Finally i found that. Because async when my redis start process going my redis is tried to get the key. Now i put that into callback of redis get function into redis start everything works fine

这篇关于Catbox-redis在我的hapijs应用程序上显示断开连接的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆