Skip to content

Latest commit

 

History

History
64 lines (46 loc) · 3.97 KB

README.md

File metadata and controls

64 lines (46 loc) · 3.97 KB

keyv-anyredis npm dependencies license

Zero-dependency storage adapter for Keyv that works with many different Redis clients and supports cluster mode.

Background

The official @keyv/redis adapter is built on the assumption that you are using the ioredis client in its normal (non-cluster) mode.

While this covers many use cases, it doesn’t work for the following:

keyv-anyredis works with any Redis client that implements a standard callback or Promise interface.

Tested clients

Client Compatible? Notes
redis
ioredis Standalone and cluster mode
fakeredis
fast-redis-cluster2
handy-redis
noderis ⛔️ smembers is missing
redis-clustr couldn’t get client can be resolved by using an IP address instead of a hostname
tedis 🟡 Non-standard get return type; cast the client to CompatibleRedisClient in TypeScript
thunk-redis usePromise: true must be set; works in cluster mode
xredis

Install

npm install --save keyv-anyredis

Usage

const Keyv = require('keyv');
const { KeyvAnyRedis } = require('keyv-anyredis');

// Create a client here, using ioredis, redis, or any
// compatible library.
//
// For example, to create a cluster client using ioredis as
// described at https://github.com/luin/ioredis#cluster:
//
// const Redis = require('ioredis');
// const client = new Redis.Cluster(…cluster configuration…);

const store = new KeyvAnyRedis(client);
const keyv = new Keyv({ store });

Testing

To run the unit tests, it’s easiest to use Docker:

npm run test:docker

If you choose to run the tests locally (with npm test) you’ll need to have a standalone instance of Redis on port 6379 and a cluster instance of Redis on port 7000.