@keyv/redis 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -0
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ Redis storage adapter for [Keyv](https://github.com/jaredwray/keyv).
|
|
|
26
26
|
# Table of Contents
|
|
27
27
|
* [Usage](#usage)
|
|
28
28
|
* [Namespaces](#namespaces)
|
|
29
|
+
* [Typescript](#typescript)
|
|
29
30
|
* [Performance Considerations](#performance-considerations)
|
|
30
31
|
* [High Memory Usage on Redis Server](#high-memory-usage-on-redis-server)
|
|
31
32
|
* [Using Cacheable with Redis](#using-cacheable-with-redis)
|
|
@@ -110,6 +111,34 @@ keyv.namespace = 'my-namespace';
|
|
|
110
111
|
|
|
111
112
|
NOTE: If you plan to do many clears or deletes, it is recommended to read the [Performance Considerations](#performance-considerations) section.
|
|
112
113
|
|
|
114
|
+
## Typescript
|
|
115
|
+
|
|
116
|
+
When initializing `KeyvRedis`, you can specify the type of the values you are storing and you can also specify types when calling methods:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import Keyv from 'keyv';
|
|
120
|
+
import KeyvRedis, { createClient } from '@keyv/redis';
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
interface User {
|
|
124
|
+
id: number
|
|
125
|
+
name: string
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const redis = createClient('redis://user:pass@localhost:6379');
|
|
129
|
+
|
|
130
|
+
const keyvRedis = new KeyvRedis<User>(redis);
|
|
131
|
+
const keyv = new Keyv({ store: keyvRedis });
|
|
132
|
+
|
|
133
|
+
await keyv.set("user:1", { id: 1, name: "Alice" })
|
|
134
|
+
const user = await keyv.get("user:1")
|
|
135
|
+
console.log(user.name) // 'Alice'
|
|
136
|
+
|
|
137
|
+
// specify types when calling methods
|
|
138
|
+
const user = await keyv.get<User>("user:1")
|
|
139
|
+
console.log(user.name) // 'Alice'
|
|
140
|
+
```
|
|
141
|
+
|
|
113
142
|
# Performance Considerations
|
|
114
143
|
|
|
115
144
|
With namespaces being prefix based it is critical to understand some of the performance considerations we have made:
|
package/dist/index.d.cts
CHANGED
|
@@ -53,7 +53,7 @@ type KeyvRedisEntry<T> = {
|
|
|
53
53
|
ttl?: number;
|
|
54
54
|
};
|
|
55
55
|
type RedisClientConnectionType = RedisClientType | RedisClusterType<RedisModules, RedisFunctions, RedisScripts>;
|
|
56
|
-
declare class KeyvRedis extends EventEmitter implements KeyvStoreAdapter {
|
|
56
|
+
declare class KeyvRedis<T> extends EventEmitter implements KeyvStoreAdapter {
|
|
57
57
|
private _client;
|
|
58
58
|
private _namespace;
|
|
59
59
|
private _keyPrefixSeparator;
|
|
@@ -162,13 +162,13 @@ declare class KeyvRedis extends EventEmitter implements KeyvStoreAdapter {
|
|
|
162
162
|
* @param {string} key - the key to get
|
|
163
163
|
* @returns {Promise<string | undefined>} - the value or undefined if the key does not exist
|
|
164
164
|
*/
|
|
165
|
-
get<T>(key: string): Promise<
|
|
165
|
+
get<U = T>(key: string): Promise<U | undefined>;
|
|
166
166
|
/**
|
|
167
167
|
* Get many values from the store. If a key does not exist, it will return undefined.
|
|
168
168
|
* @param {Array<string>} keys - the keys to get
|
|
169
169
|
* @returns {Promise<Array<string | undefined>>} - array of values or undefined if the key does not exist
|
|
170
170
|
*/
|
|
171
|
-
getMany<T>(keys: string[]): Promise<Array<
|
|
171
|
+
getMany<U = T>(keys: string[]): Promise<Array<U | undefined>>;
|
|
172
172
|
/**
|
|
173
173
|
* Delete a key from the store.
|
|
174
174
|
* @param {string} key - the key to delete
|
|
@@ -216,7 +216,7 @@ declare class KeyvRedis extends EventEmitter implements KeyvStoreAdapter {
|
|
|
216
216
|
* @param {string} [namespace] - the namespace to iterate over
|
|
217
217
|
* @returns {AsyncGenerator<[string, T | undefined], void, unknown>} - async iterator with key value pairs
|
|
218
218
|
*/
|
|
219
|
-
iterator<
|
|
219
|
+
iterator<U = T>(namespace?: string): AsyncGenerator<[string, U | undefined], void, unknown>;
|
|
220
220
|
/**
|
|
221
221
|
* Clear all keys in the store.
|
|
222
222
|
* IMPORTANT: this can cause performance issues if there are a large number of keys in the store and worse with clusters. Use with caution as not recommended for production.
|
package/dist/index.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ type KeyvRedisEntry<T> = {
|
|
|
53
53
|
ttl?: number;
|
|
54
54
|
};
|
|
55
55
|
type RedisClientConnectionType = RedisClientType | RedisClusterType<RedisModules, RedisFunctions, RedisScripts>;
|
|
56
|
-
declare class KeyvRedis extends EventEmitter implements KeyvStoreAdapter {
|
|
56
|
+
declare class KeyvRedis<T> extends EventEmitter implements KeyvStoreAdapter {
|
|
57
57
|
private _client;
|
|
58
58
|
private _namespace;
|
|
59
59
|
private _keyPrefixSeparator;
|
|
@@ -162,13 +162,13 @@ declare class KeyvRedis extends EventEmitter implements KeyvStoreAdapter {
|
|
|
162
162
|
* @param {string} key - the key to get
|
|
163
163
|
* @returns {Promise<string | undefined>} - the value or undefined if the key does not exist
|
|
164
164
|
*/
|
|
165
|
-
get<T>(key: string): Promise<
|
|
165
|
+
get<U = T>(key: string): Promise<U | undefined>;
|
|
166
166
|
/**
|
|
167
167
|
* Get many values from the store. If a key does not exist, it will return undefined.
|
|
168
168
|
* @param {Array<string>} keys - the keys to get
|
|
169
169
|
* @returns {Promise<Array<string | undefined>>} - array of values or undefined if the key does not exist
|
|
170
170
|
*/
|
|
171
|
-
getMany<T>(keys: string[]): Promise<Array<
|
|
171
|
+
getMany<U = T>(keys: string[]): Promise<Array<U | undefined>>;
|
|
172
172
|
/**
|
|
173
173
|
* Delete a key from the store.
|
|
174
174
|
* @param {string} key - the key to delete
|
|
@@ -216,7 +216,7 @@ declare class KeyvRedis extends EventEmitter implements KeyvStoreAdapter {
|
|
|
216
216
|
* @param {string} [namespace] - the namespace to iterate over
|
|
217
217
|
* @returns {AsyncGenerator<[string, T | undefined], void, unknown>} - async iterator with key value pairs
|
|
218
218
|
*/
|
|
219
|
-
iterator<
|
|
219
|
+
iterator<U = T>(namespace?: string): AsyncGenerator<[string, U | undefined], void, unknown>;
|
|
220
220
|
/**
|
|
221
221
|
* Clear all keys in the store.
|
|
222
222
|
* IMPORTANT: this can cause performance issues if there are a large number of keys in the store and worse with clusters. Use with caution as not recommended for production.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keyv/redis",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Redis storage adapter for Keyv",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"cluster-key-slot": "^1.1.2",
|
|
38
38
|
"redis": "^4.7.0",
|
|
39
|
-
"keyv": "^5.2.
|
|
39
|
+
"keyv": "^5.2.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@vitest/coverage-v8": "^2.1.8",
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
],
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
|
|
62
|
-
"test": "xo --fix && vitest run --coverage",
|
|
63
|
-
"test:ci": "xo && vitest --run --sequence.setupFiles=list",
|
|
62
|
+
"test": "xo --fix && vitest run --coverage --typecheck",
|
|
63
|
+
"test:ci": "xo && vitest --run --sequence.setupFiles=list --typecheck",
|
|
64
64
|
"clean": "rimraf ./node_modules ./coverage ./dist"
|
|
65
65
|
}
|
|
66
66
|
}
|