Registry / storage / keyv-anyredis

keyv-anyredis

JSON →
library3.3.0jsnpmunverified

A storage adapter for the Keyv key-value store that supports multiple Redis clients, including ioredis, node-redis, and cluster-mode Redis. This adapter works where the official @keyv/redis does not, particularly with Redis cluster configurations. It is zero-dependency and passes the full Keyv test suite. Current stable version is 3.3.0, with regular updates. Key differentiator: works with many Redis clients and clusters, unlike @keyv/redis which bundles a specific ioredis version and lacks cluster support.

npm install keyv-anyredis
INSTALL
IMPORT
SIG · KEYV-ANYREDIS
K
keyv-anyredis
storagejavascriptv3.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

KeyvAnyRedis
import KeyvAnyRedis from 'keyv-anyredis'
const KeyvAnyRedis = require('keyv-anyredis')
TypeScript types are included. Default import provides the class.
Keyv
import Keyv from 'keyv'
Keyv is a peer dependency and must be installed separately. Used to instantiate the store.
CompatibleRedisClient
import type { CompatibleRedisClient } from 'keyv-anyredis'
TypeScript type for defining custom compatible Redis clients. Only available in TypeScript.

Shows how to instantiate Keyv with keyv-anyredis using ioredis client, set a key with TTL, retrieve it, and delete.

import Keyv from 'keyv'; import KeyvAnyRedis from 'keyv-anyredis'; import Redis from 'ioredis'; const redisClient = new Redis({ host: process.env.REDIS_HOST ?? 'localhost', port: Number(process.env.REDIS_PORT ?? 6379) }); const keyv = new Keyv({ store: new KeyvAnyRedis(redisClient) }); async function demo() { await keyv.set('foo', 'bar', 10000); // TTL 10 seconds const value = await keyv.get('foo'); console.log(value); // 'bar' await keyv.delete('foo'); } demo().catch(console.error);
Debug
Known issues
gotchaThe redis client must expose a standard callback or Promise interface. Clients like noderis that omit methods (e.g., smembers) will fail.
fix
Use a tested client from the README table, such as ioredis, node-redis, or fakeredis.
affects: >=1.0.0
gotchaWhen using handy-redis, pass client.nodeRedis to the KeyvAnyRedis constructor, not the handy-redis client directly.
fix
new KeyvAnyRedis(client.nodeRedis)
affects: >=1.0.0
gotchaFor tedis, TypeScript users must cast the client to CompatibleRedisClient because tedis types may not match the expected interface.
fix
new KeyvAnyRedis(client as CompatibleRedisClient)
affects: >=1.0.0
gotchaFor thunk-redis, set usePromise: true on the client instance before passing to KeyvAnyRedis.
fix
const client = thunkRedis.createClient({ usePromise: true }); new KeyvAnyRedis(client)
affects: >=1.0.0
gotchaThe adapter does not support Redis Sentinel natively; use a client that handles sentinel and pass the resulting connection.
fix
Configure sentinel in your client (e.g., ioredis's sentinel options) and pass the client instance.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: client.on is not a function
The Redis client does not implement an EventEmitter interface required by KeyvAnyRedis for connection error handling.
fix
Use a compatible client like ioredis or node-redis which implement EventEmitter.
Error: The provided client is not compatible. It must implement 'get', 'set', 'del', 'keys', 'mget', 'exists' methods.
The Redis client passed to KeyvAnyRedis does not support required Redis commands or uses a non-standard API.
fix
Check the client's documentation and ensure it supports the required methods. Use a supported client from the README.
Upgrade
Version history
3.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
18
Resources
keyv-anyredis — npm install keyv-anyredis · libregistry