@keyv/redis
Advanced tools
Comparing version
import EventEmitter from 'node:events'; | ||
import { RedisClientType, RedisClusterType, RedisModules, RedisFunctions, RedisScripts, RedisClientOptions, RedisClusterOptions } from 'redis'; | ||
export { RedisClientOptions, RedisClientType, RedisClusterOptions, RedisClusterType, createClient, createCluster } from 'redis'; | ||
import { KeyvStoreAdapter, Keyv } from 'keyv'; | ||
import { KeyvStoreAdapter, KeyvEntry, Keyv } from 'keyv'; | ||
export { Keyv } from 'keyv'; | ||
@@ -145,5 +145,5 @@ | ||
* Will set many key value pairs in the store. TTL is in milliseconds. This will be done as a single transaction. | ||
* @param {Array<KeyvRedisEntry<string>>} entries - the key value pairs to set with optional ttl | ||
* @param {KeyvEntry[]} entries - the key value pairs to set with optional ttl | ||
*/ | ||
setMany(entries: Array<KeyvRedisEntry<string>>): Promise<void>; | ||
setMany(entries: KeyvEntry[]): Promise<boolean[]>; | ||
/** | ||
@@ -188,4 +188,6 @@ * Check if a key exists in the store. | ||
* @returns {Promise<void>} | ||
* @param {boolean} [force] - it will send a quit command if false, otherwise it will send a disconnect command to forcefully disconnect. | ||
* @see {@link https://github.com/redis/node-redis/tree/master/packages/redis#disconnecting} | ||
*/ | ||
disconnect(): Promise<void>; | ||
disconnect(force?: boolean): Promise<void>; | ||
/** | ||
@@ -257,4 +259,4 @@ * Helper function to create a key with a namespace. | ||
* Will create a Keyv instance with the Redis adapter. This will also set the namespace and useKeyPrefix to false. | ||
* @param connect | ||
* @param options | ||
* @param connect - How to connect to the Redis server. If string pass in the url, if object pass in the options, if RedisClient pass in the client. If nothing is passed in, it will default to 'redis://localhost:6379'. | ||
* @param {KeyvRedisOptions} options - Options for the adapter such as namespace, keyPrefixSeparator, and clearBatchSize. | ||
* @returns {Keyv} - Keyv instance with the Redis adapter | ||
@@ -261,0 +263,0 @@ */ |
@@ -172,3 +172,3 @@ // src/index.ts | ||
* Will set many key value pairs in the store. TTL is in milliseconds. This will be done as a single transaction. | ||
* @param {Array<KeyvRedisEntry<string>>} entries - the key value pairs to set with optional ttl | ||
* @param {KeyvEntry[]} entries - the key value pairs to set with optional ttl | ||
*/ | ||
@@ -187,2 +187,3 @@ async setMany(entries) { | ||
await multi.exec(); | ||
return entries.map(() => true); | ||
} | ||
@@ -282,6 +283,8 @@ /** | ||
* @returns {Promise<void>} | ||
* @param {boolean} [force] - it will send a quit command if false, otherwise it will send a disconnect command to forcefully disconnect. | ||
* @see {@link https://github.com/redis/node-redis/tree/master/packages/redis#disconnecting} | ||
*/ | ||
async disconnect() { | ||
async disconnect(force) { | ||
if (this._client.isOpen) { | ||
await this._client.disconnect(); | ||
await (force ? this._client.disconnect() : this._client.quit()); | ||
} | ||
@@ -491,2 +494,3 @@ } | ||
function createKeyv(connect, options) { | ||
connect ??= "redis://localhost:6379"; | ||
const adapter = new KeyvRedis(connect, options); | ||
@@ -493,0 +497,0 @@ const keyv = new Keyv({ store: adapter, namespace: options?.namespace, useKeyPrefix: false }); |
{ | ||
"name": "@keyv/redis", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"description": "Redis storage adapter for Keyv", | ||
@@ -39,12 +39,12 @@ "type": "module", | ||
"redis": "^4.7.0", | ||
"keyv": "^5.2.2" | ||
"keyv": "^5.3.0" | ||
}, | ||
"devDependencies": { | ||
"@vitest/coverage-v8": "^2.1.8", | ||
"@vitest/coverage-v8": "^3.0.7", | ||
"rimraf": "^6.0.1", | ||
"timekeeper": "^2.3.1", | ||
"tsd": "^0.31.2", | ||
"vitest": "^2.1.8", | ||
"vitest": "^3.0.7", | ||
"xo": "^0.60.0", | ||
"@keyv/test-suite": "^2.0.3" | ||
"@keyv/test-suite": "^2.0.5" | ||
}, | ||
@@ -51,0 +51,0 @@ "tsd": { |
@@ -35,2 +35,3 @@ # @keyv/redis [<img width="100" align="right" src="https://jaredwray.com/images/keyv-symbol.svg" alt="keyv">](https://github.com/jaredwra/keyv) | ||
* [API](#api) | ||
* [Using Custom Redis Client Events](#using-custom-redis-client-events) | ||
* [Migrating from v3 to v4](#migrating-from-v3-to-v4) | ||
@@ -258,5 +259,30 @@ * [About Redis Sets and its Support in v4](#about-redis-sets-and-its-support-in-v4) | ||
* **clear** - Clear all keys in the namespace. If the namespace is not set it will clear all keys that are not prefixed with a namespace unless `noNamespaceAffectsAll` is set to `true`. | ||
* **disconnect** - Disconnect from the Redis server. | ||
* **disconnect** - Disconnect from the Redis server using `Quit` command. If you set `force` to `true` it will force the disconnect. | ||
* **iterator** - Create a new iterator for the keys. If the namespace is not set it will iterate over all keys that are not prefixed with a namespace unless `noNamespaceAffectsAll` is set to `true`. | ||
# Using Custom Redis Client Events | ||
Keyv by default supports the `error` event across all storage adapters. If you want to listen to other events you can do so by accessing the `client` property of the `KeyvRedis` instance. Here is an example of how to do that: | ||
```js | ||
import {createKeyv} from '@keyv/redis'; | ||
const keyv = createKeyv('redis://user:pass@localhost:6379'); | ||
const redisClient = keyv.store.client; | ||
redisClient.on('connect', () => { | ||
console.log('Redis client connected'); | ||
}); | ||
redisClient.on('reconnecting', () => { | ||
console.log('Redis client reconnecting'); | ||
}); | ||
redisClient.on('end', () => { | ||
console.log('Redis client disconnected'); | ||
}); | ||
``` | ||
Here are some of the events you can listen to: https://www.npmjs.com/package/redis#events | ||
# Migrating from v3 to v4 | ||
@@ -263,0 +289,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
71994
3.82%1294
0.78%315
9%Updated