@keyv/redis 4.3.1 → 4.3.3

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 CHANGED
@@ -54,7 +54,7 @@ Here is the same example but with the `Keyv` instance created with the `createKe
54
54
  ```js
55
55
  import { createKeyv } from '@keyv/redis';
56
56
 
57
- const keyv = createKeyv('redis://user:pass@localhost:6379', { namespace: 'my-namespace' });
57
+ const keyv = createKeyv('redis://user:pass@localhost:6379');
58
58
  ```
59
59
 
60
60
  You only have to import the `@keyv/redis` library if you are using the `createKeyv` function. 🎉 Otherwise, you can import `Keyv` and `@keyv/redis` independently.
@@ -82,26 +82,28 @@ const redisOptions = {
82
82
  const keyv = new Keyv(new KeyvRedis(redisOptions));
83
83
  ```
84
84
 
85
- Or you can create a new Redis instance and pass it in with `KeyvOptions`:
85
+ Or you can create a new Redis instance and pass it in with `KeyvOptions` such as setting the `store`:
86
86
 
87
87
  ```js
88
88
  import Keyv from 'keyv';
89
89
  import KeyvRedis, { createClient } from '@keyv/redis';
90
90
 
91
- const redis = createClient('redis://user:pass@localhost:6379', { namespace: 'my-namespace'});
91
+ const redis = createClient('redis://user:pass@localhost:6379');
92
92
  const keyvRedis = new KeyvRedis(redis);
93
- const keyv = new Keyv({ store: keyvRedis });
93
+ const keyv = new Keyv({ store: keyvRedis});
94
94
  ```
95
95
 
96
96
  # Namespaces
97
97
 
98
- You can set a namespace for your keys. This is useful if you want to manage your keys in a more organized way. Here is an example of how to set a namespace:
98
+ You can set a namespace for your keys. This is useful if you want to manage your keys in a more organized way. Here is an example of how to set a `namespace` with the `store` option:
99
99
 
100
100
  ```js
101
101
  import Keyv from 'keyv';
102
- import KeyvRedis from '@keyv/redis';
102
+ import KeyvRedis, { createClient } from '@keyv/redis';
103
103
 
104
- const keyv = new Keyv(new KeyvRedis('redis://user:pass@localhost:6379', { namespace: 'my-namespace' }));
104
+ const redis = createClient('redis://user:pass@localhost:6379');
105
+ const keyvRedis = new KeyvRedis(redis);
106
+ const keyv = new Keyv({ store: keyvRedis, namespace: 'my-namespace' });
105
107
  ```
106
108
 
107
109
  This will prefix all keys with `my-namespace:`. You can also set the namespace after the fact:
package/dist/index.cjs CHANGED
@@ -177,8 +177,12 @@ var KeyvRedis = class extends import_node_events.default {
177
177
  * Get the Redis URL used to connect to the server. This is used to get a connected client.
178
178
  */
179
179
  async getClient() {
180
- if (!this._client.isOpen) {
181
- await this._client.connect();
180
+ try {
181
+ if (!this._client.isOpen) {
182
+ await this._client.connect();
183
+ }
184
+ } catch (error) {
185
+ this.emit("error", error);
182
186
  }
183
187
  return this._client;
184
188
  }
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import EventEmitter from 'node:events';
2
- import { RedisClientType, RedisClusterType, RedisModules, RedisFunctions, RedisScripts, RedisClientOptions, RedisClusterOptions } from 'redis';
2
+ import { RedisClientOptions, RedisClusterOptions, RedisClientType, RedisClusterType, RedisModules, RedisFunctions, RedisScripts } from 'redis';
3
3
  export { RedisClientOptions, RedisClientType, RedisClusterOptions, RedisClusterType, createClient, createCluster } from 'redis';
4
4
  import { KeyvStoreAdapter, KeyvEntry, Keyv } from 'keyv';
5
5
  export { Keyv } from 'keyv';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import EventEmitter from 'node:events';
2
- import { RedisClientType, RedisClusterType, RedisModules, RedisFunctions, RedisScripts, RedisClientOptions, RedisClusterOptions } from 'redis';
2
+ import { RedisClientOptions, RedisClusterOptions, RedisClientType, RedisClusterType, RedisModules, RedisFunctions, RedisScripts } from 'redis';
3
3
  export { RedisClientOptions, RedisClientType, RedisClusterOptions, RedisClusterType, createClient, createCluster } from 'redis';
4
4
  import { KeyvStoreAdapter, KeyvEntry, Keyv } from 'keyv';
5
5
  export { Keyv } from 'keyv';
package/dist/index.js CHANGED
@@ -147,8 +147,12 @@ var KeyvRedis = class extends EventEmitter {
147
147
  * Get the Redis URL used to connect to the server. This is used to get a connected client.
148
148
  */
149
149
  async getClient() {
150
- if (!this._client.isOpen) {
151
- await this._client.connect();
150
+ try {
151
+ if (!this._client.isOpen) {
152
+ await this._client.connect();
153
+ }
154
+ } catch (error) {
155
+ this.emit("error", error);
152
156
  }
153
157
  return this._client;
154
158
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keyv/redis",
3
- "version": "4.3.1",
3
+ "version": "4.3.3",
4
4
  "description": "Redis storage adapter for Keyv",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -36,16 +36,16 @@
36
36
  "dependencies": {
37
37
  "cluster-key-slot": "^1.1.2",
38
38
  "redis": "^4.7.0",
39
- "keyv": "^5.3.1"
39
+ "keyv": "^5.3.2"
40
40
  },
41
41
  "devDependencies": {
42
- "@vitest/coverage-v8": "^3.0.7",
42
+ "@vitest/coverage-v8": "^3.1.1",
43
43
  "rimraf": "^6.0.1",
44
44
  "timekeeper": "^2.3.1",
45
45
  "tsd": "^0.31.2",
46
- "vitest": "^3.0.7",
46
+ "vitest": "^3.1.1",
47
47
  "xo": "^0.60.0",
48
- "@keyv/test-suite": "^2.0.5"
48
+ "@keyv/test-suite": "^2.0.6"
49
49
  },
50
50
  "tsd": {
51
51
  "directory": "test"
@@ -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 --typecheck",
63
- "test:ci": "xo && vitest --run --sequence.setupFiles=list --typecheck",
62
+ "test": "xo --fix && vitest run --coverage",
63
+ "test:ci": "xo && vitest --run --sequence.setupFiles=list",
64
64
  "clean": "rimraf ./node_modules ./coverage ./dist"
65
65
  }
66
66
  }