@keyv/redis 4.5.0 → 5.0.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 +95 -10
- package/dist/index.cjs +226 -117
- package/dist/index.d.cts +68 -19
- package/dist/index.d.ts +68 -19
- package/dist/index.js +225 -117
- package/package.json +10 -9
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { RedisClientOptions, RedisClusterOptions, RedisClientType, RedisClusterType, RedisModules, RedisFunctions, RedisScripts } from '@redis/client';
|
|
1
|
+
import { RedisClientOptions, RedisClusterOptions, RedisClientType, RedisModules, RedisFunctions, RedisScripts, RespVersions, TypeMapping, RedisClusterType } from '@redis/client';
|
|
3
2
|
export { RedisClientOptions, RedisClientType, RedisClusterOptions, RedisClusterType, createClient, createCluster } from '@redis/client';
|
|
3
|
+
import { Hookified } from 'hookified';
|
|
4
4
|
import { KeyvStoreAdapter, KeyvEntry, Keyv } from 'keyv';
|
|
5
5
|
export { Keyv } from 'keyv';
|
|
6
6
|
|
|
@@ -28,10 +28,24 @@ type KeyvRedisOptions = {
|
|
|
28
28
|
*/
|
|
29
29
|
noNamespaceAffectsAll?: boolean;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* This is used to throw an error if the client is not connected when trying to connect. By default, this is
|
|
32
|
+
* set to true so that it throws an error when trying to connect to the Redis server fails.
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
throwOnConnectError?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* This is used to throw an error if at any point there is a failure. Use this if you want to
|
|
37
|
+
* ensure that all operations are successful and you want to handle errors. By default, this is
|
|
38
|
+
* set to false so that it does not throw an error on every operation and instead emits an error event
|
|
39
|
+
* and returns no-op responses.
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
throwOnErrors?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Timeout in milliseconds for the connection. Default is undefined, which uses the default timeout of the Redis client.
|
|
45
|
+
* If set, it will throw an error if the connection does not succeed within the specified time.
|
|
46
|
+
* @default undefined
|
|
47
|
+
*/
|
|
48
|
+
connectionTimeout?: number;
|
|
35
49
|
};
|
|
36
50
|
type KeyvRedisPropertyOptions = KeyvRedisOptions & {
|
|
37
51
|
/**
|
|
@@ -59,21 +73,24 @@ type KeyvRedisEntry<T> = {
|
|
|
59
73
|
};
|
|
60
74
|
declare enum RedisErrorMessages {
|
|
61
75
|
/**
|
|
62
|
-
* Error message when the Redis client is not connected.
|
|
76
|
+
* Error message when the Redis client is not connected and throwOnConnectError is set to true.
|
|
63
77
|
*/
|
|
64
|
-
|
|
78
|
+
RedisClientNotConnectedThrown = "Redis client is not connected or has failed to connect. This is thrown because throwOnConnectError is set to true."
|
|
65
79
|
}
|
|
66
80
|
declare const defaultReconnectStrategy: (attempts: number) => number | Error;
|
|
67
|
-
type
|
|
68
|
-
|
|
81
|
+
type RedisConnectionClientType = RedisClientType | RedisClientType<RedisModules, RedisFunctions, RedisScripts, RespVersions> | RedisClientType<RedisModules, RedisFunctions, RedisScripts, RespVersions, TypeMapping>;
|
|
82
|
+
type RedisConnectionClusterType = RedisClusterType | RedisClusterType<RedisModules, RedisFunctions, RedisScripts, RespVersions> | RedisClusterType<RedisModules, RedisFunctions, RedisScripts, RespVersions, TypeMapping>;
|
|
83
|
+
type RedisClientConnectionType = RedisConnectionClientType | RedisConnectionClusterType;
|
|
84
|
+
declare class KeyvRedis<T> extends Hookified implements KeyvStoreAdapter {
|
|
69
85
|
private _client;
|
|
70
86
|
private _namespace;
|
|
71
87
|
private _keyPrefixSeparator;
|
|
72
88
|
private _clearBatchSize;
|
|
73
89
|
private _useUnlink;
|
|
74
90
|
private _noNamespaceAffectsAll;
|
|
75
|
-
private
|
|
76
|
-
private
|
|
91
|
+
private _throwOnConnectError;
|
|
92
|
+
private _throwOnErrors;
|
|
93
|
+
private _connectionTimeout;
|
|
77
94
|
/**
|
|
78
95
|
* KeyvRedis constructor.
|
|
79
96
|
* @param {string | RedisClientOptions | RedisClientType} [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.
|
|
@@ -144,19 +161,49 @@ declare class KeyvRedis<T> extends EventEmitter implements KeyvStoreAdapter {
|
|
|
144
161
|
*/
|
|
145
162
|
set noNamespaceAffectsAll(value: boolean);
|
|
146
163
|
/**
|
|
147
|
-
* Get
|
|
148
|
-
*
|
|
164
|
+
* Get if throwOnConnectError is set to true.
|
|
165
|
+
* This is used to throw an error if the client is not connected when trying to connect. By default, this is
|
|
166
|
+
* set to true so that it throws an error when trying to connect to the Redis server fails.
|
|
167
|
+
* @default true
|
|
168
|
+
*/
|
|
169
|
+
get throwOnConnectError(): boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Set if throwOnConnectError is set to true.
|
|
172
|
+
* This is used to throw an error if the client is not connected when trying to connect. By default, this is
|
|
173
|
+
* set to true so that it throws an error when trying to connect to the Redis server fails.
|
|
149
174
|
*/
|
|
150
|
-
|
|
175
|
+
set throwOnConnectError(value: boolean);
|
|
151
176
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
177
|
+
* Get if throwOnErrors is set to true.
|
|
178
|
+
* This is used to throw an error if at any point there is a failure. Use this if you want to
|
|
179
|
+
* ensure that all operations are successful and you want to handle errors. By default, this is
|
|
180
|
+
* set to false so that it does not throw an error on every operation and instead emits an error event
|
|
181
|
+
* and returns no-op responses.
|
|
182
|
+
* @default false
|
|
183
|
+
*/
|
|
184
|
+
get throwOnErrors(): boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Set if throwOnErrors is set to true.
|
|
187
|
+
* This is used to throw an error if at any point there is a failure. Use this if you want to
|
|
188
|
+
* ensure that all operations are successful and you want to handle errors. By default, this is
|
|
189
|
+
* set to false so that it does not throw an error on every operation and instead emits an error event
|
|
190
|
+
* and returns no-op responses.
|
|
191
|
+
*/
|
|
192
|
+
set throwOnErrors(value: boolean);
|
|
193
|
+
/**
|
|
194
|
+
* Get the connection timeout in milliseconds such as 5000 (5 seconds). Default is undefined. If undefined, it will use the default.
|
|
195
|
+
* @default undefined
|
|
196
|
+
*/
|
|
197
|
+
get connectionTimeout(): number | undefined;
|
|
198
|
+
/**
|
|
199
|
+
* Set the connection timeout in milliseconds such as 5000 (5 seconds). Default is undefined. If undefined, it will use the default.
|
|
200
|
+
* @default undefined
|
|
154
201
|
*/
|
|
155
|
-
set
|
|
202
|
+
set connectionTimeout(value: number | undefined);
|
|
156
203
|
/**
|
|
157
204
|
* Get the Redis URL used to connect to the server. This is used to get a connected client.
|
|
158
205
|
*/
|
|
159
|
-
getClient(): Promise<RedisClientConnectionType
|
|
206
|
+
getClient(): Promise<RedisClientConnectionType>;
|
|
160
207
|
/**
|
|
161
208
|
* Set a key value pair in the store. TTL is in milliseconds.
|
|
162
209
|
* @param {string} key - the key to set
|
|
@@ -275,6 +322,7 @@ declare class KeyvRedis<T> extends EventEmitter implements KeyvStoreAdapter {
|
|
|
275
322
|
private isClientCluster;
|
|
276
323
|
private setOptions;
|
|
277
324
|
private initClient;
|
|
325
|
+
private createTimeoutPromise;
|
|
278
326
|
}
|
|
279
327
|
/**
|
|
280
328
|
* Will create a Keyv instance with the Redis adapter. This will also set the namespace and useKeyPrefix to false.
|
|
@@ -283,5 +331,6 @@ declare class KeyvRedis<T> extends EventEmitter implements KeyvStoreAdapter {
|
|
|
283
331
|
* @returns {Keyv} - Keyv instance with the Redis adapter
|
|
284
332
|
*/
|
|
285
333
|
declare function createKeyv(connect?: string | RedisClientOptions | RedisClientType, options?: KeyvRedisOptions): Keyv;
|
|
334
|
+
declare function createKeyvNonBlocking(connect?: string | RedisClientOptions | RedisClientType, options?: KeyvRedisOptions): Keyv;
|
|
286
335
|
|
|
287
|
-
export { type KeyvRedisEntry, type KeyvRedisOptions, type KeyvRedisPropertyOptions, type RedisClientConnectionType, RedisErrorMessages, createKeyv, KeyvRedis as default, defaultReconnectStrategy };
|
|
336
|
+
export { type KeyvRedisEntry, type KeyvRedisOptions, type KeyvRedisPropertyOptions, type RedisClientConnectionType, type RedisConnectionClientType, type RedisConnectionClusterType, RedisErrorMessages, createKeyv, createKeyvNonBlocking, KeyvRedis as default, defaultReconnectStrategy };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { RedisClientOptions, RedisClusterOptions, RedisClientType, RedisClusterType, RedisModules, RedisFunctions, RedisScripts } from '@redis/client';
|
|
1
|
+
import { RedisClientOptions, RedisClusterOptions, RedisClientType, RedisModules, RedisFunctions, RedisScripts, RespVersions, TypeMapping, RedisClusterType } from '@redis/client';
|
|
3
2
|
export { RedisClientOptions, RedisClientType, RedisClusterOptions, RedisClusterType, createClient, createCluster } from '@redis/client';
|
|
3
|
+
import { Hookified } from 'hookified';
|
|
4
4
|
import { KeyvStoreAdapter, KeyvEntry, Keyv } from 'keyv';
|
|
5
5
|
export { Keyv } from 'keyv';
|
|
6
6
|
|
|
@@ -28,10 +28,24 @@ type KeyvRedisOptions = {
|
|
|
28
28
|
*/
|
|
29
29
|
noNamespaceAffectsAll?: boolean;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* This is used to throw an error if the client is not connected when trying to connect. By default, this is
|
|
32
|
+
* set to true so that it throws an error when trying to connect to the Redis server fails.
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
throwOnConnectError?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* This is used to throw an error if at any point there is a failure. Use this if you want to
|
|
37
|
+
* ensure that all operations are successful and you want to handle errors. By default, this is
|
|
38
|
+
* set to false so that it does not throw an error on every operation and instead emits an error event
|
|
39
|
+
* and returns no-op responses.
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
throwOnErrors?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Timeout in milliseconds for the connection. Default is undefined, which uses the default timeout of the Redis client.
|
|
45
|
+
* If set, it will throw an error if the connection does not succeed within the specified time.
|
|
46
|
+
* @default undefined
|
|
47
|
+
*/
|
|
48
|
+
connectionTimeout?: number;
|
|
35
49
|
};
|
|
36
50
|
type KeyvRedisPropertyOptions = KeyvRedisOptions & {
|
|
37
51
|
/**
|
|
@@ -59,21 +73,24 @@ type KeyvRedisEntry<T> = {
|
|
|
59
73
|
};
|
|
60
74
|
declare enum RedisErrorMessages {
|
|
61
75
|
/**
|
|
62
|
-
* Error message when the Redis client is not connected.
|
|
76
|
+
* Error message when the Redis client is not connected and throwOnConnectError is set to true.
|
|
63
77
|
*/
|
|
64
|
-
|
|
78
|
+
RedisClientNotConnectedThrown = "Redis client is not connected or has failed to connect. This is thrown because throwOnConnectError is set to true."
|
|
65
79
|
}
|
|
66
80
|
declare const defaultReconnectStrategy: (attempts: number) => number | Error;
|
|
67
|
-
type
|
|
68
|
-
|
|
81
|
+
type RedisConnectionClientType = RedisClientType | RedisClientType<RedisModules, RedisFunctions, RedisScripts, RespVersions> | RedisClientType<RedisModules, RedisFunctions, RedisScripts, RespVersions, TypeMapping>;
|
|
82
|
+
type RedisConnectionClusterType = RedisClusterType | RedisClusterType<RedisModules, RedisFunctions, RedisScripts, RespVersions> | RedisClusterType<RedisModules, RedisFunctions, RedisScripts, RespVersions, TypeMapping>;
|
|
83
|
+
type RedisClientConnectionType = RedisConnectionClientType | RedisConnectionClusterType;
|
|
84
|
+
declare class KeyvRedis<T> extends Hookified implements KeyvStoreAdapter {
|
|
69
85
|
private _client;
|
|
70
86
|
private _namespace;
|
|
71
87
|
private _keyPrefixSeparator;
|
|
72
88
|
private _clearBatchSize;
|
|
73
89
|
private _useUnlink;
|
|
74
90
|
private _noNamespaceAffectsAll;
|
|
75
|
-
private
|
|
76
|
-
private
|
|
91
|
+
private _throwOnConnectError;
|
|
92
|
+
private _throwOnErrors;
|
|
93
|
+
private _connectionTimeout;
|
|
77
94
|
/**
|
|
78
95
|
* KeyvRedis constructor.
|
|
79
96
|
* @param {string | RedisClientOptions | RedisClientType} [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.
|
|
@@ -144,19 +161,49 @@ declare class KeyvRedis<T> extends EventEmitter implements KeyvStoreAdapter {
|
|
|
144
161
|
*/
|
|
145
162
|
set noNamespaceAffectsAll(value: boolean);
|
|
146
163
|
/**
|
|
147
|
-
* Get
|
|
148
|
-
*
|
|
164
|
+
* Get if throwOnConnectError is set to true.
|
|
165
|
+
* This is used to throw an error if the client is not connected when trying to connect. By default, this is
|
|
166
|
+
* set to true so that it throws an error when trying to connect to the Redis server fails.
|
|
167
|
+
* @default true
|
|
168
|
+
*/
|
|
169
|
+
get throwOnConnectError(): boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Set if throwOnConnectError is set to true.
|
|
172
|
+
* This is used to throw an error if the client is not connected when trying to connect. By default, this is
|
|
173
|
+
* set to true so that it throws an error when trying to connect to the Redis server fails.
|
|
149
174
|
*/
|
|
150
|
-
|
|
175
|
+
set throwOnConnectError(value: boolean);
|
|
151
176
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
177
|
+
* Get if throwOnErrors is set to true.
|
|
178
|
+
* This is used to throw an error if at any point there is a failure. Use this if you want to
|
|
179
|
+
* ensure that all operations are successful and you want to handle errors. By default, this is
|
|
180
|
+
* set to false so that it does not throw an error on every operation and instead emits an error event
|
|
181
|
+
* and returns no-op responses.
|
|
182
|
+
* @default false
|
|
183
|
+
*/
|
|
184
|
+
get throwOnErrors(): boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Set if throwOnErrors is set to true.
|
|
187
|
+
* This is used to throw an error if at any point there is a failure. Use this if you want to
|
|
188
|
+
* ensure that all operations are successful and you want to handle errors. By default, this is
|
|
189
|
+
* set to false so that it does not throw an error on every operation and instead emits an error event
|
|
190
|
+
* and returns no-op responses.
|
|
191
|
+
*/
|
|
192
|
+
set throwOnErrors(value: boolean);
|
|
193
|
+
/**
|
|
194
|
+
* Get the connection timeout in milliseconds such as 5000 (5 seconds). Default is undefined. If undefined, it will use the default.
|
|
195
|
+
* @default undefined
|
|
196
|
+
*/
|
|
197
|
+
get connectionTimeout(): number | undefined;
|
|
198
|
+
/**
|
|
199
|
+
* Set the connection timeout in milliseconds such as 5000 (5 seconds). Default is undefined. If undefined, it will use the default.
|
|
200
|
+
* @default undefined
|
|
154
201
|
*/
|
|
155
|
-
set
|
|
202
|
+
set connectionTimeout(value: number | undefined);
|
|
156
203
|
/**
|
|
157
204
|
* Get the Redis URL used to connect to the server. This is used to get a connected client.
|
|
158
205
|
*/
|
|
159
|
-
getClient(): Promise<RedisClientConnectionType
|
|
206
|
+
getClient(): Promise<RedisClientConnectionType>;
|
|
160
207
|
/**
|
|
161
208
|
* Set a key value pair in the store. TTL is in milliseconds.
|
|
162
209
|
* @param {string} key - the key to set
|
|
@@ -275,6 +322,7 @@ declare class KeyvRedis<T> extends EventEmitter implements KeyvStoreAdapter {
|
|
|
275
322
|
private isClientCluster;
|
|
276
323
|
private setOptions;
|
|
277
324
|
private initClient;
|
|
325
|
+
private createTimeoutPromise;
|
|
278
326
|
}
|
|
279
327
|
/**
|
|
280
328
|
* Will create a Keyv instance with the Redis adapter. This will also set the namespace and useKeyPrefix to false.
|
|
@@ -283,5 +331,6 @@ declare class KeyvRedis<T> extends EventEmitter implements KeyvStoreAdapter {
|
|
|
283
331
|
* @returns {Keyv} - Keyv instance with the Redis adapter
|
|
284
332
|
*/
|
|
285
333
|
declare function createKeyv(connect?: string | RedisClientOptions | RedisClientType, options?: KeyvRedisOptions): Keyv;
|
|
334
|
+
declare function createKeyvNonBlocking(connect?: string | RedisClientOptions | RedisClientType, options?: KeyvRedisOptions): Keyv;
|
|
286
335
|
|
|
287
|
-
export { type KeyvRedisEntry, type KeyvRedisOptions, type KeyvRedisPropertyOptions, type RedisClientConnectionType, RedisErrorMessages, createKeyv, KeyvRedis as default, defaultReconnectStrategy };
|
|
336
|
+
export { type KeyvRedisEntry, type KeyvRedisOptions, type KeyvRedisPropertyOptions, type RedisClientConnectionType, type RedisConnectionClientType, type RedisConnectionClusterType, RedisErrorMessages, createKeyv, createKeyvNonBlocking, KeyvRedis as default, defaultReconnectStrategy };
|