@hapi/catbox-redis v7.0.2
console
npm install @hapi/catbox-redis@7.0.2console
yarn add @hapi/catbox-redis@7.0.2console
pnpm add @hapi/catbox-redis@7.0.2Redis adapter for catbox.
Compatibility
| Major version | License | Node.js |
|---|---|---|
| 7 | BSD | >= 16 |
new CatboxRedis.Engine(options)
The connection can be specified with one (and only one) of:
client- a custom Redis client instance whereclientmust:- be manually started and stopped,
- be compatible with the ioredis module API, and
- expose the
statusproperty that must be set to'ready'when connected.
url- a Redis server URL.socket- a unix socket string.cluster- an array of{ host, port }pairs.
Or:
host- a Redis server hostname. Defaults to'127.0.0.1'if no other connection method specified from the above.port- a Redis server port or unix domain socket path. Defaults to6379if no other connection method specified from the above.
catbox options:
partition- a string used to prefix all item keys with. Defaults to''.
Other supported Redis options:
password- the Redis authentication password when required.db- a Redis database name or number.sentinels- an array of{ host, port }sentinel address pairs.sentinelName- the name of the sentinel master (whensentinelsis specified).tls- an object representing TLS config options for ioredis.
The plugin also accepts other redis options not mentioned above.
Usage
Sample catbox cache initialization:
js
const Catbox = require('@hapi/catbox');
const { Engine: CatboxRedis } = require('@hapi/catbox-redis');
const cache = new Catbox.Client(CatboxRedis, {
partition: 'my_cached_data',
host: 'redis-cluster.domain.com',
port: 6379,
db: 0,
tls: {},
});When used in a hapi server (hapi version 18 or newer):
js
const Hapi = require('hapi');
const { Engine: 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: {},
},
},
},
],
});Tests
The test suite expects:
- a redis server to be running on port 6379
- a redis server listenning to port 6378 and requiring a password: 'secret'
- a redis cluster contains nodes running on ports 7000 to 7005