tractr / catbox-fallback

Catbox engine allowing you to use two engines, a primary and a secondary, and if the primary is down, the secondary takes over.
MIT License
11 stars 0 forks source link

using catbox-fallback with Glue manifest? #1

Open emckean opened 5 years ago

emckean commented 5 years ago

I'm unclear on how to use catbox-fallback in my hapi project Glue manifest for server.cache -- any pointers to examples available?

I promise to do a pull request for the docs if I get enough examples to understand it. :)

simlevesque commented 5 years ago

if you can show me your code I could try to run it and help you. I think you can use catbox-fallback like any other plugin.

edit: I added an example, hope it helps: https://github.com/Tractr/catbox-fallback/blob/master/examples/simple.js

emckean commented 5 years ago

yes, thank you! That helps a lot! I was also wondering how to reference it in server methods (as in this gist: https://gist.github.com/emckean/3565c1c0d43a20c07df7b101d1bcc995) -- can the client be referenced by name?

emckean commented 5 years ago

hi! I'm still working on this, I'm trying this inside the Glue manifest:

const Glue = require('glue');
const manifest = {
    server: {
        cache: [ 
            // {
            //     name: 'redisCache',
            //     engine: require('catbox-redis'),
            //     url: redisConfig.url,
            //     password: redisConfig.password,
            //     partition: redisConfig.partition
            // }
            new Catbox.Client(CatboxFallback, {
                primary: {
                    engine: new CatboxRedis({
                        partition: redisConfig.partition,
                        url: redisConfig.url,
                        password: redisConfig.password
                    })
                },
                secondary: {
                    engine: new CatboxMemory()
                }
            })
        ],

(commented out is previously working code) But I get this error: AssertionError [ERR_ASSERTION]: Must set a primary engine

Enclosing the new Catbox.Client in {} gets SyntaxError: Unexpected identifier (on Catbox) Setting up a separate const client = also gets the "Must set a primary engine" error.

Any suggestions gratefully received!

EdouardDem commented 5 years ago

This post is a bit old but this may help someone. I fixed the example: https://github.com/Tractr/catbox-fallback/blob/master/examples/simple.js

Using Hapi17, the configuration is working like this:

const server = Hapi.server({
    port: 3000,
    host: 'localhost',
    cache: {
        name: 'fallback',
        engine: CatboxFallback,
        primary: {
            engine: CatboxRedis,
            options: {
                partition: 'example',
                host: '127.0.0.1',
                port: 6379,
            }
        },
        secondary: {
            engine: CatboxMemory,
        }
    }
});

Using Hapi18, this works:

const server = Hapi.server({
    port: 3000,
    host: 'localhost',
    cache: {
        name: 'fallback',
        provider: {
            constructor: CatboxFallback,
            options: {
                primary: {
                    engine: CatboxRedis,
                    options: {
                        partition: 'example',
                        host: '127.0.0.1',
                        port: 6379,
                    }
                },
                secondary: {
                    engine: CatboxMemory,
                }
            }
        }
    }
});

Hope this helps