hapijs / catbox-redis

Redis adapter for catbox
Other
69 stars 63 forks source link

Catbox Redis Configuration Document #129

Closed wako057 closed 1 year ago

wako057 commented 1 year ago

Context

What are you trying to achieve or the steps to reproduce ?

I'm trying to configure the catbox-redis at the server level, according the documentation

const Hapi = require('hapi')
const CatboxRedis = require('@hapi/catbox-redis');

const server = new Hapi.Server({
    cache : [
        {
            name: 'my_cache',
            provider: {
                constructor: CatboxRedis,
                options: {
                    partition : 'my_cached_data',
                    host: 'redis-cluster.domain.com',
                    port: 6379,
                    db: 0,
                    tls: {},
                }
            }
        }
    ]
});

is not working, I'm meeting this error:

/app/node_modules/@hapi/validate/lib/annotate.js:52
                    refAnnotations.errors[cacheKey].push(pos);
                                                    ^

TypeError: refAnnotations.errors[cacheKey].push is not a function

Fixup for the constructor to CatboxRedis.Engine

...
  cache : [
    {
      name: 'redisCache',
      provider: {
        constructor: CatboxRedis.Engine,
        options: {
          partition : 'hapi-cache-internal',
          host: process.env.REDIS_HOST,
          port: process.env.REDIS_PORT,
        }
      }
    }
  ]
...

Thanks Stack Overflow user for the help

Nargonath commented 1 year ago

Thanks @wako057 for noticing this error. You're right, if you look into hapi tests suite you can see that they use CatboxMemory.Engine: https://github.com/hapijs/hapi/blob/master/test/server.js#L146.

Do you want to open a PR to fix the documentation?

wako057 commented 1 year ago

fixed with the proper require sorry for the noise const { Engine: CatboxRedis } = require('@hapi/catbox-redis'); It is correct on the repository but not on the website, it probably need to be re-generated