@keyv/redis 4.0.0 → 4.0.1

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
@@ -47,6 +47,16 @@ const keyv = new Keyv(new KeyvRedis('redis://user:pass@localhost:6379'));
47
47
  keyv.on('error', handleConnectionError);
48
48
  ```
49
49
 
50
+ Here is the same example but with the `Keyv` instance created with the `createKeyv` function:
51
+
52
+ ```js
53
+ import { createKeyv } from '@keyv/redis';
54
+
55
+ const keyv = createKeyv('redis://user:pass@localhost:6379', { namespace: 'my-namespace' });
56
+ ```
57
+
58
+ 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.
59
+
50
60
  Here you can pass in the Redis options directly:
51
61
 
52
62
  ```js
@@ -81,17 +91,7 @@ const keyvRedis = new KeyvRedis(redis);
81
91
  const keyv = new Keyv({ store: keyvRedis });
82
92
  ```
83
93
 
84
- Here is the same example but with the `Keyv` instance created with the `createKeyv` function:
85
-
86
- ```js
87
- import { createKeyv } from '@keyv/redis';
88
-
89
- const keyv = createKeyv('redis://user:pass@localhost:6379', { namespace: 'my-namespace' });
90
- ```
91
-
92
- 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.
93
-
94
- # Namspaces
94
+ # Namespaces
95
95
 
96
96
  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:
97
97
 
@@ -121,7 +121,7 @@ With namespaces being prefix based it is critical to understand some of the perf
121
121
 
122
122
  * `useUnlink` - This option is set to `true` by default. This is because `UNLINK` is a non-blocking command that is more efficient than `DEL`. If you are not using `UNLINK` and are doing a lot of deletes it is recommended to set this option to `true`.
123
123
 
124
- * `setMany`, `getMany`, `deleteMany` - These methods are more efficient than their singular counterparts. If you are doing multiple operations it is recommended to use these methods.
124
+ * `setMany`, `getMany`, `deleteMany` - These methods are more efficient than their singular counterparts. These will be used by default in the `Keyv` library such as when using `keyv.delete(string[])` it will use `deleteMany()`.
125
125
 
126
126
  If you want to see even better performance please see the [Using Cacheable with Redis](#using-cacheable-with-redis) section as it has non-blocking and in-memory primary caching that goes along well with this library and Keyv.
127
127
 
@@ -183,6 +183,8 @@ const cluster = createCluster({
183
183
  const keyv = new Keyv({ store: new KeyvRedis(cluster) });
184
184
  ```
185
185
 
186
+ You can learn more about the `createCluster` function in the [documentation](https://github.com/redis/node-redis/blob/master/docs/clustering.md) at https://github.com/redis/node-redis/tree/master/docs.
187
+
186
188
  Here is an example of how to use TLS:
187
189
 
188
190
  ```js
@@ -227,7 +229,25 @@ const keyv = new Keyv({ store: new KeyvRedis(tlsOptions) });
227
229
 
228
230
  # Migrating from v3 to v4
229
231
 
230
- The main change in v4 is the removal of the `ioredis` library in favor of the `@keyv/redis` library. This was done to provide a more consistent experience across all Keyv storage adapters. The `@keyv/redis` library is a wrapper around the `redis` library and provides a more consistent experience across all Keyv storage adapters. The only other change is that we no longer do redis sets as they caused performance issues.
232
+ Overall the API is the same as v3 with additional options and performance improvements. Here are the main changes:
233
+ * The `ioredis` library has been removed in favor of the `redis` aka `node-redis` library. If you want to use ioredis you can use `@keyv/keyval`
234
+ * The `useUnlink` option has been added to use `UNLINK` instead of `DEL` and set to true by default.
235
+ * The `clearBatchSize` option has been added to set the number of keys to delete in a single batch.
236
+ * The `clear()` and `delete()` methods now use `UNLINK` instead of `DEL`. If you want to use `DEL` you can set the `useUnlink` option to `false`.
237
+ * BREAKING: We no longer support redis sets. This is due to the fact that it caused significant performance issues and was not a good fit for the library.
238
+ * BREAKING: YOUR PREVIOUS KEYS WILL NOT BE VALID. This is because of the fixe of the namespace support and how it is handled. Now, when using `keyv` with `@keyv/redis` as the storage adapter you can do the following:
239
+
240
+ ```js
241
+ import Keyv from 'keyv';
242
+ import KeyvRedis from '@keyv/redis';
243
+
244
+ const redis = new KeyvRedis('redis://user:pass@localhost:6379');
245
+ const keyv = new Keyv({ store: redis, namespace: 'my-namespace', useKeyPrefix: false });
246
+ ```
247
+
248
+ This will make it so the storage adapter `@keyv/redis` will handle the namespace and not the `keyv` instance. If you leave it on it will just look duplicated like `my-namespace:my-namespace:key`.
249
+
250
+
231
251
 
232
252
  # About Redis Sets and its Support in v4
233
253
 
package/dist/index.cjs CHANGED
@@ -409,7 +409,7 @@ var KeyvRedis = class extends import_events.default {
409
409
  };
410
410
  function createKeyv(connect, options) {
411
411
  const adapter = new KeyvRedis(connect, options);
412
- const keyv = new import_keyv.Keyv({ store: adapter, namespace: options?.namespace });
412
+ const keyv = new import_keyv.Keyv({ store: adapter, namespace: options?.namespace, useKeyPrefix: false });
413
413
  return keyv;
414
414
  }
415
415
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.d.cts CHANGED
@@ -200,7 +200,7 @@ declare class KeyvRedis extends EventEmitter implements KeyvStoreAdapter {
200
200
  private initClient;
201
201
  }
202
202
  /**
203
- * Will create a Keyv instance with the Redis adapter.
203
+ * Will create a Keyv instance with the Redis adapter. This will also set the namespace and useKeyPrefix to false.
204
204
  * @param connect
205
205
  * @param options
206
206
  * @returns {Keyv} - Keyv instance with the Redis adapter
package/dist/index.d.ts CHANGED
@@ -200,7 +200,7 @@ declare class KeyvRedis extends EventEmitter implements KeyvStoreAdapter {
200
200
  private initClient;
201
201
  }
202
202
  /**
203
- * Will create a Keyv instance with the Redis adapter.
203
+ * Will create a Keyv instance with the Redis adapter. This will also set the namespace and useKeyPrefix to false.
204
204
  * @param connect
205
205
  * @param options
206
206
  * @returns {Keyv} - Keyv instance with the Redis adapter
package/dist/index.js CHANGED
@@ -376,7 +376,7 @@ var KeyvRedis = class extends EventEmitter {
376
376
  };
377
377
  function createKeyv(connect, options) {
378
378
  const adapter = new KeyvRedis(connect, options);
379
- const keyv = new Keyv({ store: adapter, namespace: options?.namespace });
379
+ const keyv = new Keyv({ store: adapter, namespace: options?.namespace, useKeyPrefix: false });
380
380
  return keyv;
381
381
  }
382
382
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keyv/redis",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Redis storage adapter for Keyv",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",