Skip to content

Commit 04f0cb2

Browse files
committed
Replace deprecated Redis commands, bump to 1.0.0
rpoplpush/brpoplpush were deprecated in Redis 6.2 in favour of lmove/blmove. Also add frozen_string_literal, remove unused size attr_reader, and use lrem count 1 instead of 0 since each item appears exactly once in the working queue.
1 parent 6fffdda commit 04f0cb2

4 files changed

Lines changed: 15 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
All notable changes to this project will be documented in this file. This
44
project adheres to [Semantic Versioning](http://semver.org/).
55

6-
## UNRELEASED - 2024-10-18
6+
## [1.0.0] - 2026-03-27
77

88
### Changed
99

10+
- Replace deprecated `rpoplpush`/`brpoplpush` with `lmove`/`blmove` (requires Redis 6.2+)
1011
- Modernise dev dependencies
1112
- Replace Travis CI with GitHub Actions
1213
- Add house_style and apply the corrections

lib/reliable_queue_rb/chunked_reliable_queue.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# frozen_string_literal: true
2+
13
class ChunkedReliableQueue
24
DEFAULT_SIZE = 100
35

4-
attr_reader :name, :queue, :size, :working_queue, :redis
6+
attr_reader :name, :queue, :working_queue, :redis
57

68
def initialize(name, queue, redis)
79
@name = name
@@ -16,20 +18,20 @@ def each_slice(size = DEFAULT_SIZE)
1618
return enum_for(:each_slice, size) unless block_given?
1719

1820
loop do
19-
blocking_reply = redis.brpoplpush(queue, working_queue, timeout: 30)
21+
blocking_reply = redis.blmove(queue, working_queue, 'RIGHT', 'LEFT', timeout: 30)
2022
next unless blocking_reply
2123

2224
replies = [blocking_reply]
2325
replies += redis.multi { |multi|
2426
(size - 1).times do
25-
multi.rpoplpush(queue, working_queue)
27+
multi.lmove(queue, working_queue, 'RIGHT', 'LEFT')
2628
end
2729
}.compact
2830

2931
yield replies
3032
redis.multi do |multi|
3133
replies.each do |reply|
32-
multi.lrem(working_queue, 0, reply)
34+
multi.lrem(working_queue, 1, reply)
3335
end
3436
end
3537
end
@@ -38,6 +40,6 @@ def each_slice(size = DEFAULT_SIZE)
3840
private
3941

4042
def requeue_unfinished_work
41-
loop while redis.rpoplpush(working_queue, queue)
43+
loop while redis.lmove(working_queue, queue, 'RIGHT', 'LEFT')
4244
end
4345
end

lib/reliable_queue_rb/reliable_queue.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class ReliableQueue
24
include Enumerable
35

@@ -15,17 +17,17 @@ def each
1517
return enum_for(:each) unless block_given?
1618

1719
loop do
18-
reply = redis.brpoplpush(queue, working_queue, timeout: 30)
20+
reply = redis.blmove(queue, working_queue, 'RIGHT', 'LEFT', timeout: 30)
1921
next unless reply
2022

2123
yield reply
22-
redis.lrem(working_queue, 0, reply)
24+
redis.lrem(working_queue, 1, reply)
2325
end
2426
end
2527

2628
private
2729

2830
def requeue_unfinished_work
29-
loop while redis.rpoplpush(working_queue, queue)
31+
loop while redis.lmove(working_queue, queue, 'RIGHT', 'LEFT')
3032
end
3133
end

reliable_queue.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Gem::Specification.new do |s|
22
s.required_ruby_version = '>= 2.7.0'
33
s.name = 'reliable-queue-rb'
4-
s.version = '0.4.0'
4+
s.version = '1.0.0'
55
s.authors = ['Anna Klimas', 'Jonathan Hernandez']
66
s.email = ['support@altmetric.com']
77

0 commit comments

Comments
 (0)