You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
awaitstore.set('foo', 'bar', 5000); // expires in 5 seconds
222
225
```
223
226
227
+
### .setMany(entries)
228
+
229
+
Sets multiple key-value pairs in a single batch operation. Each entry can have an optional TTL in milliseconds. Entries with `undefined` values are skipped.
230
+
231
+
```js
232
+
awaitstore.setMany([
233
+
{ key:'foo', value:'bar' },
234
+
{ key:'baz', value:'qux', ttl:5000 },
235
+
]);
236
+
```
237
+
224
238
### .delete(key)
225
239
226
240
Deletes a key-value pair from the store. Returns `true` if the key existed and was deleted, `false` otherwise.
Clears all entries from the store. If a namespace is set, only entries within that namespace are cleared.
274
+
275
+
```js
276
+
awaitstore.clear();
254
277
```
255
278
256
279
### .iterator(namespace?)
@@ -271,6 +294,31 @@ Disconnects from the Valkey server.
271
294
awaitstore.disconnect();
272
295
```
273
296
297
+
## Clustering
298
+
299
+
The adapter supports Valkey and Redis clusters via iovalkey's `Cluster` class. Pass a `Redis.Cluster` instance directly to the constructor:
300
+
301
+
```js
302
+
importKeyvValkeyfrom'@keyv/valkey';
303
+
importRedisfrom'iovalkey';
304
+
305
+
constcluster=newRedis.Cluster([
306
+
{ host:'127.0.0.1', port:7001 },
307
+
{ host:'127.0.0.1', port:7002 },
308
+
{ host:'127.0.0.1', port:7003 },
309
+
]);
310
+
conststore=newKeyvValkey(cluster);
311
+
```
312
+
313
+
Batch methods (`getMany`, `setMany`, `deleteMany`, `hasMany`) automatically group keys by hash slot and run separate transactions per slot group. This avoids `CROSSSLOT` errors without any extra configuration.
314
+
315
+
Single-key methods (`get`, `set`, `delete`, `has`) work automatically in cluster mode — iovalkey routes each command to the correct node.
316
+
317
+
### Cluster gotchas
318
+
319
+
-**`clear()` with `useSets: false` (the default)** uses the `KEYS` command, which only scans the node that receives the command. In cluster mode this may miss keys on other nodes. Set `useSets: true` if you need reliable `clear()` across all cluster nodes.
320
+
-**`iterator()` in cluster mode** uses `SCAN`, which only iterates keys on the node the command is routed to. It may not return all keys across the cluster.
0 commit comments