redis 6.0.0 → 6.1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +114 -0
- data/README.md +172 -5
- data/lib/redis/client.rb +5 -1
- data/lib/redis/commands/arrays.rb +358 -0
- data/lib/redis/commands/bitmaps.rb +24 -0
- data/lib/redis/commands/bless.rb +115 -0
- data/lib/redis/commands/cluster.rb +9 -2
- data/lib/redis/commands/hashes.rb +250 -7
- data/lib/redis/commands/keys.rb +48 -11
- data/lib/redis/commands/modules/json.rb +27 -2
- data/lib/redis/commands/modules/search/aggregation.rb +2 -1
- data/lib/redis/commands/modules/search/field.rb +11 -2
- data/lib/redis/commands/modules/search/hybrid.rb +3 -0
- data/lib/redis/commands/modules/search/index.rb +2 -1
- data/lib/redis/commands/modules/search/miscellaneous.rb +2 -1
- data/lib/redis/commands/modules/search/query.rb +2 -2
- data/lib/redis/commands/modules/search/schema.rb +4 -0
- data/lib/redis/commands/scripting.rb +109 -0
- data/lib/redis/commands/server.rb +158 -7
- data/lib/redis/commands/sets.rb +270 -0
- data/lib/redis/commands/sorted_sets.rb +131 -6
- data/lib/redis/commands/streams.rb +284 -33
- data/lib/redis/commands/strings.rb +232 -6
- data/lib/redis/commands/transactions.rb +6 -1
- data/lib/redis/commands/vector_sets.rb +407 -0
- data/lib/redis/commands.rb +169 -6
- data/lib/redis/distributed.rb +539 -22
- data/lib/redis/hash_ring.rb +2 -1
- data/lib/redis/keyspace_notifications/channels.rb +121 -0
- data/lib/redis/keyspace_notifications/manager.rb +1121 -0
- data/lib/redis/keyspace_notifications/notification.rb +95 -0
- data/lib/redis/keyspace_notifications/parser.rb +170 -0
- data/lib/redis/keyspace_notifications.rb +59 -0
- data/lib/redis/pipeline.rb +17 -5
- data/lib/redis/ractorize.rb +6 -0
- data/lib/redis/subscribe.rb +80 -2
- data/lib/redis/version.rb +1 -1
- data/lib/redis/xxh3.rb +354 -0
- data/lib/redis.rb +29 -8
- metadata +16 -6
|
@@ -35,6 +35,9 @@ class Redis
|
|
|
35
35
|
# redis.xadd('mystream', f1: 'v1', f2: 'v2')
|
|
36
36
|
# @example With options
|
|
37
37
|
# redis.xadd('mystream', { f1: 'v1', f2: 'v2' }, id: '0-0', maxlen: 1000, approximate: true, nomkstream: true)
|
|
38
|
+
# @example Idempotent production (Redis 8.6)
|
|
39
|
+
# redis.xadd('mystream', { f1: 'v1' }, idmp: ['producer-1', 'msg-42'])
|
|
40
|
+
# redis.xadd('mystream', { f1: 'v1' }, idmpauto: 'producer-1')
|
|
38
41
|
#
|
|
39
42
|
# @param key [String] the stream key
|
|
40
43
|
# @param entry [Hash] one or multiple field-value pairs
|
|
@@ -46,11 +49,32 @@ class Redis
|
|
|
46
49
|
# @option opts [Boolean] :approximate whether to add `~` modifier of maxlen/minid or not
|
|
47
50
|
# @option opts [Integer] :limit maximum count of entries to be evicted, requires approximate trimming
|
|
48
51
|
# @option opts [Boolean] :nomkstream whether to add NOMKSTREAM, default is not to add
|
|
52
|
+
# @option opts [Symbol, String] :policy (Redis 8.2) how trimming (`:maxlen`/`:minid`)
|
|
53
|
+
# handles consumer group PEL references to the evicted entries: `:keepref` (the
|
|
54
|
+
# server's default) keeps them, `:delref` also removes them, `:acked` only evicts
|
|
55
|
+
# entries already acknowledged by every consumer group. No effect without trimming.
|
|
56
|
+
# @option opts [Array(String, String)] :idmp (Redis 8.6) `[producer_id, idempotent_id]` for
|
|
57
|
+
# idempotent production: resending the same pair returns the original entry's id instead
|
|
58
|
+
# of appending a duplicate. Retention is configured per stream with {#xcfgset}.
|
|
59
|
+
# @option opts [String] :idmpauto (Redis 8.6) producer id; the server derives the idempotent
|
|
60
|
+
# id from the entry's field-value pairs. Mutually exclusive with `:idmp`.
|
|
49
61
|
#
|
|
50
62
|
# @return [String] the entry id
|
|
51
|
-
def xadd(key, entry, approximate: nil, maxlen: nil, minid: nil, limit: nil, nomkstream: nil, id: '*'
|
|
63
|
+
def xadd(key, entry, approximate: nil, maxlen: nil, minid: nil, limit: nil, nomkstream: nil, id: '*', policy: nil,
|
|
64
|
+
idmp: nil, idmpauto: nil)
|
|
52
65
|
args = [:xadd, key]
|
|
53
66
|
args << 'NOMKSTREAM' if nomkstream
|
|
67
|
+
args << xstream_ref_policy_token(policy) if policy
|
|
68
|
+
if idmp
|
|
69
|
+
raise ArgumentError, "can't supply both idmp and idmpauto" if idmpauto
|
|
70
|
+
|
|
71
|
+
pid, iid = idmp
|
|
72
|
+
raise ArgumentError, "idmp must be [producer_id, idempotent_id]" if pid.nil? || iid.nil?
|
|
73
|
+
|
|
74
|
+
args << 'IDMP' << pid << iid
|
|
75
|
+
elsif idmpauto
|
|
76
|
+
args << 'IDMPAUTO' << idmpauto
|
|
77
|
+
end
|
|
54
78
|
if maxlen
|
|
55
79
|
raise ArgumentError, "can't supply both maxlen and minid" if minid
|
|
56
80
|
|
|
@@ -89,15 +113,20 @@ class Redis
|
|
|
89
113
|
# @param strategy [String] the limit strategy, must be MINID
|
|
90
114
|
# @param approximate [Boolean] whether to add `~` modifier of minid or not
|
|
91
115
|
# @param limit [Integer] maximum count of entries to be evicted
|
|
116
|
+
# @param policy [Symbol, String] (Redis 8.2) how trimming handles consumer group
|
|
117
|
+
# PEL references to the evicted entries: `:keepref` (the server's default) keeps
|
|
118
|
+
# them, `:delref` also removes them, `:acked` only evicts entries already
|
|
119
|
+
# acknowledged by every consumer group
|
|
92
120
|
#
|
|
93
121
|
# @return [Integer] the number of entries actually deleted
|
|
94
|
-
def xtrim(key, len_or_id, strategy: 'MAXLEN', approximate: false, limit: nil)
|
|
122
|
+
def xtrim(key, len_or_id, strategy: 'MAXLEN', approximate: false, limit: nil, policy: nil)
|
|
95
123
|
strategy = strategy.to_s.upcase
|
|
96
124
|
|
|
97
125
|
args = [:xtrim, key, strategy]
|
|
98
126
|
args << '~' if approximate
|
|
99
127
|
args << len_or_id
|
|
100
128
|
args.concat(['LIMIT', limit]) if limit
|
|
129
|
+
args << xstream_ref_policy_token(policy) if policy
|
|
101
130
|
send_command(args)
|
|
102
131
|
end
|
|
103
132
|
|
|
@@ -117,6 +146,45 @@ class Redis
|
|
|
117
146
|
send_command(args)
|
|
118
147
|
end
|
|
119
148
|
|
|
149
|
+
# Delete entries by entry ids, with control over consumer group PEL references. XDELEX
|
|
150
|
+
# is an extension of XDEL.
|
|
151
|
+
#
|
|
152
|
+
# @example With splatted entry ids, keeping consumer group references (the default)
|
|
153
|
+
# redis.xdelex('mystream', '0-1', '0-2')
|
|
154
|
+
# @example With arrayed entry ids
|
|
155
|
+
# redis.xdelex('mystream', ['0-1', '0-2'])
|
|
156
|
+
# @example Also drop dangling consumer group references
|
|
157
|
+
# redis.xdelex('mystream', '0-1', delref: true)
|
|
158
|
+
# @example Only delete entries acknowledged by every consumer group
|
|
159
|
+
# redis.xdelex('mystream', '0-1', acked: true)
|
|
160
|
+
#
|
|
161
|
+
# @param key [String] the stream key
|
|
162
|
+
# @param ids [Array<String>] one or multiple entry ids
|
|
163
|
+
# @param keepref [Boolean] delete the entries but keep existing consumer group PEL
|
|
164
|
+
# references (the server's default). Mutually exclusive with `:delref` and `:acked`.
|
|
165
|
+
# @param delref [Boolean] delete the entries and remove all consumer group PEL references
|
|
166
|
+
# to them, including dangling ones. Mutually exclusive with `:keepref` and `:acked`.
|
|
167
|
+
# @param acked [Boolean] only delete entries already acknowledged by every consumer group.
|
|
168
|
+
# Mutually exclusive with `:keepref` and `:delref`.
|
|
169
|
+
#
|
|
170
|
+
# @return [Array<Integer>] one entry per requested id, in order: `-1` if the key or that
|
|
171
|
+
# id does not exist, `1` if the entry was deleted, `2` if it was not deleted because
|
|
172
|
+
# references still exist (`:acked`) or the stream has no consumer groups
|
|
173
|
+
def xdelex(key, *ids, keepref: nil, delref: nil, acked: nil)
|
|
174
|
+
if [keepref, delref, acked].count { |option| option } > 1
|
|
175
|
+
raise ArgumentError, "keepref, delref, and acked are mutually exclusive"
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
ids = ids.flatten
|
|
179
|
+
args = [:xdelex, key]
|
|
180
|
+
args << "KEEPREF" if keepref
|
|
181
|
+
args << "DELREF" if delref
|
|
182
|
+
args << "ACKED" if acked
|
|
183
|
+
args.concat(["IDS", ids.size, *ids])
|
|
184
|
+
|
|
185
|
+
send_command(args)
|
|
186
|
+
end
|
|
187
|
+
|
|
120
188
|
# Fetches entries of the stream in ascending order.
|
|
121
189
|
#
|
|
122
190
|
# @example Without options
|
|
@@ -219,19 +287,66 @@ class Redis
|
|
|
219
287
|
# redis.xgroup(:destroy, 'mystream', 'mygroup')
|
|
220
288
|
# @example With `delconsumer` subcommand
|
|
221
289
|
# redis.xgroup(:delconsumer, 'mystream', 'mygroup', 'consumer1')
|
|
290
|
+
# @example With `create` subcommand and the group's entries-read counter (Redis 7.0)
|
|
291
|
+
# redis.xgroup(:create, 'mystream', 'mygroup', '$', mkstream: true, entriesread: 10)
|
|
222
292
|
#
|
|
223
|
-
# @param subcommand [String] `create` `setid` `destroy` `delconsumer`
|
|
293
|
+
# @param subcommand [String] `create` `setid` `destroy` `delconsumer` `createconsumer`
|
|
224
294
|
# @param key [String] the stream key
|
|
225
295
|
# @param group [String] the consumer group name
|
|
226
296
|
# @param id_or_consumer [String]
|
|
227
297
|
# * the entry id or `$`, required if subcommand is `create` or `setid`
|
|
228
|
-
# * the consumer name, required if subcommand is `delconsumer`
|
|
229
|
-
# @param mkstream
|
|
298
|
+
# * the consumer name, required if subcommand is `delconsumer` or `createconsumer`
|
|
299
|
+
# @param mkstream [Boolean] (`create`) create an empty stream automatically if it does not exist
|
|
300
|
+
# @param entriesread [Integer] (`create`, `setid`) the number of entries the group has read, used by
|
|
301
|
+
# the server to compute the group's lag (Redis 7.0)
|
|
230
302
|
#
|
|
231
303
|
# @return [String] `OK` if subcommand is `create` or `setid`
|
|
232
|
-
# @return [Integer] effected count if subcommand is `destroy` or `
|
|
233
|
-
def xgroup(subcommand, key, group, id_or_consumer = nil, mkstream: false)
|
|
234
|
-
args = [:xgroup, subcommand, key, group, id_or_consumer
|
|
304
|
+
# @return [Integer] effected count if subcommand is `destroy`, `delconsumer` or `createconsumer`
|
|
305
|
+
def xgroup(subcommand, key, group, id_or_consumer = nil, mkstream: false, entriesread: nil)
|
|
306
|
+
args = [:xgroup, subcommand, key, group, id_or_consumer].compact
|
|
307
|
+
args << 'MKSTREAM' if mkstream
|
|
308
|
+
args << 'ENTRIESREAD' << Integer(entriesread) if entriesread
|
|
309
|
+
send_command(args)
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
# Set the last entry id of the stream, and optionally its entries-added counter and
|
|
313
|
+
# maximal deleted entry id.
|
|
314
|
+
#
|
|
315
|
+
# @example Set the last id
|
|
316
|
+
# redis.xsetid('mystream', '1526919030474-55')
|
|
317
|
+
# @example Also set the counters used for lag tracking (Redis 7.0)
|
|
318
|
+
# redis.xsetid('mystream', '1526919030474-55', entriesadded: 100, maxdeletedid: '1526919030474-10')
|
|
319
|
+
#
|
|
320
|
+
# @param key [String] the stream key
|
|
321
|
+
# @param id [String] the new last entry id, must not be smaller than the current one
|
|
322
|
+
# @param entriesadded [Integer] the number of entries added to the stream over its lifetime (Redis 7.0)
|
|
323
|
+
# @param maxdeletedid [String] the maximal entry id that was deleted from the stream (Redis 7.0)
|
|
324
|
+
#
|
|
325
|
+
# @return [String] `OK`
|
|
326
|
+
def xsetid(key, id, entriesadded: nil, maxdeletedid: nil)
|
|
327
|
+
args = [:xsetid, key, id]
|
|
328
|
+
args << 'ENTRIESADDED' << Integer(entriesadded) if entriesadded
|
|
329
|
+
args << 'MAXDELETEDID' << maxdeletedid if maxdeletedid
|
|
330
|
+
send_command(args)
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
# Configures idempotent-producer (IDMP) tracking for an existing stream (Redis 8.6).
|
|
334
|
+
# Changing either value clears the stream's tracked producer/idempotent-id pairs.
|
|
335
|
+
#
|
|
336
|
+
# @example
|
|
337
|
+
# redis.xcfgset('mystream', duration: 300, maxsize: 1000)
|
|
338
|
+
#
|
|
339
|
+
# @param key [String] the stream key, must exist
|
|
340
|
+
# @param duration [Integer] seconds an idempotent id is retained (1..86400, server default 100)
|
|
341
|
+
# @param maxsize [Integer] most recent idempotent ids kept per producer (1..10000, server default 100)
|
|
342
|
+
#
|
|
343
|
+
# @return [String] `OK`
|
|
344
|
+
def xcfgset(key, duration: nil, maxsize: nil)
|
|
345
|
+
raise ArgumentError, "supply duration and/or maxsize" if duration.nil? && maxsize.nil?
|
|
346
|
+
|
|
347
|
+
args = [:xcfgset, key]
|
|
348
|
+
args << 'IDMP-DURATION' << Integer(duration) if duration
|
|
349
|
+
args << 'IDMP-MAXSIZE' << Integer(maxsize) if maxsize
|
|
235
350
|
send_command(args)
|
|
236
351
|
end
|
|
237
352
|
|
|
@@ -248,6 +363,9 @@ class Redis
|
|
|
248
363
|
# redis.xreadgroup('mygroup', 'consumer1', 'mystream', '>', block: 1000)
|
|
249
364
|
# @example With noack option
|
|
250
365
|
# redis.xreadgroup('mygroup', 'consumer1', 'mystream', '>', noack: true)
|
|
366
|
+
# @example Also claim entries pending for over a minute on other consumers (Redis 8.4+)
|
|
367
|
+
# redis.xreadgroup('mygroup', 'consumer1', 'mystream', '>', claim: 60_000)
|
|
368
|
+
# # => { 'mystream' => [['0-1', { 'f' => 'v' }, 75_000, 2], ['0-2', { 'f' => 'v' }, 0, 0]] }
|
|
251
369
|
#
|
|
252
370
|
# @param group [String] the consumer group name
|
|
253
371
|
# @param consumer [String] the consumer name
|
|
@@ -263,15 +381,23 @@ class Redis
|
|
|
263
381
|
# streams combined, measured on the serialized server reply including protocol overhead;
|
|
264
382
|
# a single oversized first entry can still be returned (Redis 8.10+). Defaults to unlimited.
|
|
265
383
|
# @option opts [Integer] :block the number of milliseconds as blocking timeout
|
|
384
|
+
# @option opts [Integer] :claim before reading new entries, also claim entries pending for at
|
|
385
|
+
# least this many milliseconds on any consumer of the group (Redis 8.4+). Only applies to
|
|
386
|
+
# `>` ids. Claimed entries come first, and every entry carries two extra elements, the
|
|
387
|
+
# idle time in milliseconds and the prior delivery count (both `0` for new entries), so
|
|
388
|
+
# each entry is `[id, fields, idle, deliveries]` instead of `[id, fields]`. `NOACK` does
|
|
389
|
+
# not apply to claimed entries.
|
|
266
390
|
# @option opts [Boolean] :noack whether message loss is acceptable or not
|
|
267
391
|
#
|
|
268
|
-
# @return [Hash{String =>
|
|
269
|
-
def xreadgroup(group, consumer, keys, ids, count: nil, max_count: nil, max_size: nil, block: nil,
|
|
392
|
+
# @return [Hash{String => Array<Array>}] the entries per stream, each `[id, fields]`
|
|
393
|
+
def xreadgroup(group, consumer, keys, ids, count: nil, max_count: nil, max_size: nil, block: nil, claim: nil,
|
|
394
|
+
noack: nil)
|
|
270
395
|
args = [:xreadgroup, 'GROUP', group, consumer]
|
|
271
396
|
args << 'COUNT' << count if count
|
|
272
397
|
args << 'MAXCOUNT' << Integer(max_count) if max_count
|
|
273
398
|
args << 'MAXSIZE' << Integer(max_size) if max_size
|
|
274
399
|
args << 'BLOCK' << block.to_i if block
|
|
400
|
+
args << 'CLAIM' << Integer(claim) if claim
|
|
275
401
|
args << 'NOACK' if noack
|
|
276
402
|
_xread(args, keys, ids, block)
|
|
277
403
|
end
|
|
@@ -295,38 +421,150 @@ class Redis
|
|
|
295
421
|
send_command(args)
|
|
296
422
|
end
|
|
297
423
|
|
|
298
|
-
#
|
|
424
|
+
# Acknowledges and conditionally deletes one or more entries for a stream consumer
|
|
425
|
+
# group, in a single atomic operation. XACKDEL combines XACK and XDELEX.
|
|
426
|
+
#
|
|
427
|
+
# @example With splatted entry ids, keeping consumer group references (the default)
|
|
428
|
+
# redis.xackdel('mystream', 'mygroup', '0-1', '0-2')
|
|
429
|
+
# @example With arrayed entry ids
|
|
430
|
+
# redis.xackdel('mystream', 'mygroup', ['0-1', '0-2'])
|
|
431
|
+
# @example Also drop dangling consumer group references
|
|
432
|
+
# redis.xackdel('mystream', 'mygroup', '0-1', delref: true)
|
|
433
|
+
# @example Only delete entries acknowledged by every consumer group
|
|
434
|
+
# redis.xackdel('mystream', 'mygroup', '0-1', acked: true)
|
|
435
|
+
#
|
|
436
|
+
# @param key [String] the stream key
|
|
437
|
+
# @param group [String] the consumer group name
|
|
438
|
+
# @param ids [Array<String>] one or multiple entry ids
|
|
439
|
+
# @param keepref [Boolean] acknowledge and delete the entries but keep existing consumer
|
|
440
|
+
# group PEL references (the server's default). Mutually exclusive with `:delref` and
|
|
441
|
+
# `:acked`.
|
|
442
|
+
# @param delref [Boolean] acknowledge and delete the entries and remove all consumer
|
|
443
|
+
# group PEL references to them, including dangling ones. Mutually exclusive with
|
|
444
|
+
# `:keepref` and `:acked`.
|
|
445
|
+
# @param acked [Boolean] acknowledge the entries but only delete those already
|
|
446
|
+
# acknowledged by every consumer group. Mutually exclusive with `:keepref` and
|
|
447
|
+
# `:delref`.
|
|
448
|
+
#
|
|
449
|
+
# @return [Array<Integer>] one entry per requested id, in order: `-1` if the key or that
|
|
450
|
+
# id does not exist, `1` if the entry was acknowledged and deleted, `2` if it was
|
|
451
|
+
# acknowledged but not deleted because references still exist (`:acked`)
|
|
452
|
+
def xackdel(key, group, *ids, keepref: nil, delref: nil, acked: nil)
|
|
453
|
+
if [keepref, delref, acked].count { |option| option } > 1
|
|
454
|
+
raise ArgumentError, "keepref, delref, and acked are mutually exclusive"
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
ids = ids.flatten
|
|
458
|
+
args = [:xackdel, key, group]
|
|
459
|
+
args << "KEEPREF" if keepref
|
|
460
|
+
args << "DELREF" if delref
|
|
461
|
+
args << "ACKED" if acked
|
|
462
|
+
args.concat(["IDS", ids.size, *ids])
|
|
463
|
+
|
|
464
|
+
send_command(args)
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
# Releases pending entries back to the consumer group's Pending Entries
|
|
468
|
+
# List without acknowledging them. Released entries become unowned, are
|
|
469
|
+
# placed at the head of the PEL and are immediately available for
|
|
470
|
+
# re-delivery via `xreadgroup` CLAIM, `xclaim` or `xautoclaim`,
|
|
471
|
+
# bypassing the usual idle-timeout delay.
|
|
472
|
+
#
|
|
473
|
+
# @example Let another consumer retry two entries
|
|
474
|
+
# redis.xnack('mystream', 'mygroup', 'FAIL', '0-1', '0-2')
|
|
475
|
+
# @example Graceful shutdown with arrayed entry ids
|
|
476
|
+
# redis.xnack('mystream', 'mygroup', :silent, %w[0-1 0-2])
|
|
477
|
+
# @example Mark a poison message as permanently failed
|
|
478
|
+
# redis.xnack('mystream', 'mygroup', 'FATAL', '0-1')
|
|
479
|
+
#
|
|
480
|
+
# @param key [String] the stream key
|
|
481
|
+
# @param group [String] the consumer group name
|
|
482
|
+
# @param mode [String, Symbol] how the entry's delivery counter is
|
|
483
|
+
# adjusted: `SILENT` decrements it by one (the delivery "didn't
|
|
484
|
+
# count"), `FAIL` keeps it unchanged, `FATAL` sets it to the maximum,
|
|
485
|
+
# marking the entry permanently failed
|
|
486
|
+
# @param ids [Array<String>] one or multiple entry ids
|
|
487
|
+
# @param retrycount [Integer] set the delivery counter to an explicit
|
|
488
|
+
# value, overriding the mode adjustment (internal, rarely needed)
|
|
489
|
+
# @param force [Boolean] create unowned PEL entries for ids that
|
|
490
|
+
# are not currently pending; each must exist in the stream (internal,
|
|
491
|
+
# rarely needed)
|
|
492
|
+
#
|
|
493
|
+
# @return [Integer] the number of entries released back to the group
|
|
494
|
+
# PEL; ids that are not pending are ignored and not counted
|
|
495
|
+
def xnack(key, group, mode, *ids, retrycount: nil, force: nil)
|
|
496
|
+
mode = mode.to_s.upcase
|
|
497
|
+
raise ArgumentError, "mode must be SILENT, FAIL or FATAL" unless %w[SILENT FAIL FATAL].include?(mode)
|
|
498
|
+
|
|
499
|
+
ids = ids.flatten
|
|
500
|
+
args = [:xnack, key, group, mode, "IDS", ids.size].concat(ids)
|
|
501
|
+
args << "RETRYCOUNT" << Integer(retrycount) if retrycount
|
|
502
|
+
args << "FORCE" if force
|
|
503
|
+
send_command(args)
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
# Changes the ownership of pending stream entries, as if they had just been delivered to `consumer`.
|
|
507
|
+
#
|
|
508
|
+
# A claim rewrites the entries' Pending Entries List (PEL) attributes instead of filtering on them:
|
|
509
|
+
# the idle time is reset to 0 and the delivery counter is incremented. Only `min_idle_time` filters.
|
|
510
|
+
# That reset is what makes a positive `min_idle_time` behave like a lock: a claimed entry is idle
|
|
511
|
+
# for 0ms, so a rival claiming with the same positive threshold gets nothing back. It is not a lock
|
|
512
|
+
# when `min_idle_time` is 0, because then the check is skipped and every caller succeeds.
|
|
513
|
+
#
|
|
514
|
+
# Entries that are not pending in the group are skipped silently, and so are entries that were
|
|
515
|
+
# deleted from the stream (those are also dropped from the PEL on Redis 7.0+). The reply can
|
|
516
|
+
# therefore be shorter than `ids`, or empty.
|
|
299
517
|
#
|
|
300
518
|
# @example With splatted entry ids
|
|
301
519
|
# redis.xclaim('mystream', 'mygroup', 'consumer1', 3600000, '0-1', '0-2')
|
|
302
520
|
# @example With arrayed entry ids
|
|
303
521
|
# redis.xclaim('mystream', 'mygroup', 'consumer1', 3600000, %w[0-1 0-2])
|
|
304
|
-
# @example
|
|
305
|
-
# redis.xclaim('mystream', 'mygroup', 'consumer1',
|
|
306
|
-
# @example
|
|
522
|
+
# @example Claim every pending entry, however recently it was delivered
|
|
523
|
+
# redis.xclaim('mystream', 'mygroup', 'consumer1', 0, %w[0-1 0-2])
|
|
524
|
+
# @example Keep an hour of idle time on the claimed entries instead of resetting it
|
|
525
|
+
# redis.xclaim('mystream', 'mygroup', 'consumer1', 3600000, %w[0-1 0-2], idle: 3600000)
|
|
526
|
+
# @example Record an absolute Unix time as the last delivery
|
|
307
527
|
# redis.xclaim('mystream', 'mygroup', 'consumer1', 3600000, %w[0-1 0-2], time: 1542866959000)
|
|
308
|
-
# @example
|
|
528
|
+
# @example Pin the delivery counter instead of incrementing it
|
|
309
529
|
# redis.xclaim('mystream', 'mygroup', 'consumer1', 3600000, %w[0-1 0-2], retrycount: 10)
|
|
310
|
-
# @example
|
|
530
|
+
# @example Claim entries that no consumer has read yet
|
|
311
531
|
# redis.xclaim('mystream', 'mygroup', 'consumer1', 3600000, %w[0-1 0-2], force: true)
|
|
312
|
-
# @example
|
|
532
|
+
# @example Get the claimed ids back without incrementing the delivery counter
|
|
313
533
|
# redis.xclaim('mystream', 'mygroup', 'consumer1', 3600000, %w[0-1 0-2], justid: true)
|
|
314
534
|
#
|
|
315
535
|
# @param key [String] the stream key
|
|
316
536
|
# @param group [String] the consumer group name
|
|
317
|
-
# @param consumer [String] the consumer
|
|
318
|
-
# @param min_idle_time [Integer] the
|
|
537
|
+
# @param consumer [String] the consumer that takes ownership
|
|
538
|
+
# @param min_idle_time [Integer] the only filter: claim an entry only if it has been idle for
|
|
539
|
+
# at least this many milliseconds. `0` disables the check and claims every entry in `ids` that is
|
|
540
|
+
# still pending; a negative value is treated as `0`
|
|
319
541
|
# @param ids [Array<String>] one or multiple entry ids
|
|
320
|
-
# @param opts [Hash] several options for `XCLAIM` command
|
|
321
|
-
#
|
|
322
|
-
#
|
|
323
|
-
#
|
|
324
|
-
#
|
|
325
|
-
# @option opts [
|
|
326
|
-
#
|
|
327
|
-
#
|
|
328
|
-
#
|
|
542
|
+
# @param opts [Hash] several options for the `XCLAIM` command. Apart from `:justid`
|
|
543
|
+
# they overwrite the claimed entries' PEL attributes rather than select which entries are claimed,
|
|
544
|
+
# and exist mainly so the AOF file and replicas can replay a claim exactly; application code
|
|
545
|
+
# usually needs nothing beyond `min_idle_time` and `:justid`
|
|
546
|
+
#
|
|
547
|
+
# @option opts [Integer] :idle the idle time in milliseconds to record on the claimed entries,
|
|
548
|
+
# that is the write side of `min_idle_time` rather than a second filter: `min_idle_time` decides
|
|
549
|
+
# which entries are claimed, `:idle` decides what their idle time is afterwards. Omitting it
|
|
550
|
+
# records 0, as does an out-of-range value (one that would place the last delivery before the
|
|
551
|
+
# Unix epoch or in the future)
|
|
552
|
+
# @option opts [Integer] :time same as `:idle`, including the out-of-range handling, but as an
|
|
553
|
+
# absolute Unix time in milliseconds. Given both, `:time` wins because the client always sends
|
|
554
|
+
# `IDLE` before `TIME`
|
|
555
|
+
# @option opts [Integer] :retrycount the delivery counter to record on the claimed entries, instead of
|
|
556
|
+
# incrementing it. `0` resets the counter
|
|
557
|
+
# @option opts [Boolean] :force also claim ids that are not in the group PEL yet, creating their
|
|
558
|
+
# pending entries from scratch. The id must still exist in the stream, and `min_idle_time` is
|
|
559
|
+
# ignored for entries created this way
|
|
560
|
+
# @option opts [Boolean] :justid return only the claimed ids and skip the delivery counter's
|
|
561
|
+
# automatic increment. An explicit `:retrycount` still overwrites the counter, and the entries are
|
|
562
|
+
# still claimed - their idle time is still reset unless `:idle` or `:time` says otherwise
|
|
563
|
+
#
|
|
564
|
+
# @return [Hash{String => Hash}] the entries successfully claimed, keyed by entry id
|
|
329
565
|
# @return [Array<String>] the entry ids successfully claimed if justid option is `true`
|
|
566
|
+
#
|
|
567
|
+
# See the [Redis Server XCLAIM documentation](https://redis.io/docs/latest/commands/xclaim/) for details.
|
|
330
568
|
def xclaim(key, group, consumer, min_idle_time, *ids, **opts)
|
|
331
569
|
args = [:xclaim, key, group, consumer, min_idle_time].concat(ids.flatten)
|
|
332
570
|
args.concat(['IDLE', opts[:idle].to_i]) if opts[:idle]
|
|
@@ -343,9 +581,9 @@ class Redis
|
|
|
343
581
|
# @example Claim next pending message stuck > 5 minutes and mark as retry
|
|
344
582
|
# redis.xautoclaim('mystream', 'mygroup', 'consumer1', 3600000, '0-0')
|
|
345
583
|
# @example Claim 50 next pending messages stuck > 5 minutes and mark as retry
|
|
346
|
-
# redis.
|
|
584
|
+
# redis.xautoclaim('mystream', 'mygroup', 'consumer1', 3600000, '0-0', count: 50)
|
|
347
585
|
# @example Claim next pending message stuck > 5 minutes and don't mark as retry
|
|
348
|
-
# redis.
|
|
586
|
+
# redis.xautoclaim('mystream', 'mygroup', 'consumer1', 3600000, '0-0', justid: true)
|
|
349
587
|
# @example Claim next pending message after this id stuck > 5 minutes and mark as retry
|
|
350
588
|
# redis.xautoclaim('mystream', 'mygroup', 'consumer1', 3600000, '1641321233-0')
|
|
351
589
|
#
|
|
@@ -354,12 +592,16 @@ class Redis
|
|
|
354
592
|
# @param consumer [String] the consumer name
|
|
355
593
|
# @param min_idle_time [Integer] the number of milliseconds
|
|
356
594
|
# @param start [String] entry id to start scanning from or 0-0 for everything
|
|
357
|
-
# @param count [Integer] number of messages to claim (default
|
|
595
|
+
# @param count [Integer] number of messages to claim (default 100)
|
|
358
596
|
# @param justid [Boolean] whether to fetch just an array of entry ids or not.
|
|
359
597
|
# Does not increment retry count when true
|
|
360
598
|
#
|
|
361
|
-
# @return [Hash
|
|
362
|
-
#
|
|
599
|
+
# @return [Hash] with the keys
|
|
600
|
+
# * `'next'` [String] the entry id to pass as `start` on the next call, `0-0` when done
|
|
601
|
+
# * `'entries'` [Array<[String, Hash]>] the claimed entries as `[id, fields]` pairs, or just
|
|
602
|
+
# the ids when `justid` is `true`
|
|
603
|
+
# * `'deleted'` [Array<String>] ids that were deleted from the stream and dropped from the
|
|
604
|
+
# PEL (Redis 7.0); always `[]` on Redis 6.2
|
|
363
605
|
def xautoclaim(key, group, consumer, min_idle_time, start, count: nil, justid: false)
|
|
364
606
|
args = [:xautoclaim, key, group, consumer, min_idle_time, start]
|
|
365
607
|
if count
|
|
@@ -409,6 +651,15 @@ class Redis
|
|
|
409
651
|
|
|
410
652
|
private
|
|
411
653
|
|
|
654
|
+
def xstream_ref_policy_token(policy)
|
|
655
|
+
token = policy.to_s.upcase
|
|
656
|
+
unless %w[KEEPREF DELREF ACKED].include?(token)
|
|
657
|
+
raise ArgumentError, "policy must be :keepref, :delref, or :acked"
|
|
658
|
+
end
|
|
659
|
+
|
|
660
|
+
token
|
|
661
|
+
end
|
|
662
|
+
|
|
412
663
|
def _xread(args, keys, ids, blocking_timeout_msec)
|
|
413
664
|
keys = keys.is_a?(Array) ? keys : [keys]
|
|
414
665
|
ids = ids.is_a?(Array) ? ids : [ids]
|