Zero-dependency storage adapter for Keyv that works with many different Redis clients and supports cluster mode.
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:
- Using ioredis in cluster mode.
- Using a different client
keyv-anyredis works with any Redis client that implements a standard callback or Promise interface.
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 | ✅ |
npm install --save keyv-anyredis
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 });
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.