redis_queue 0.5.1 → 0.6.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/lib/redis_connection.rb +6 -6
- data/lib/redis_queue.rb +30 -28
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2611aeb7b25137f26b161137e3169da32c8f3880
|
4
|
+
data.tar.gz: 8815a25e09045bb8ec6583569f6eb777cfe7ab78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53d783bcb3f12facae37336c9c7fad0a963680bf5d41a41b7de9b76fb1757c392af7ac32c6e220a98d08322be0f5fd19f6a6c24b07f6cbe9940f2d9ceeb2150c
|
7
|
+
data.tar.gz: 42f7bbaec3b42537cb18fa5f665a09a8b7184ac9ee88a90540f1758b13cff5b8a4fa382854a535e9b730cd3f3988fb10e8d3098a3daf7ee2f888d60ecb4c3f5b
|
data/lib/redis_connection.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'redis'
|
2
2
|
|
3
|
-
class RedisConnection
|
4
|
-
def initialize
|
3
|
+
class RedisQueue::RedisConnection
|
4
|
+
def initialize(args)
|
5
5
|
@args = args
|
6
6
|
end
|
7
7
|
|
@@ -12,14 +12,14 @@ class RedisConnection
|
|
12
12
|
yield(@redis)
|
13
13
|
rescue Redis::CannotConnectError, Redis::TimeoutError => e
|
14
14
|
puts e.backtrace
|
15
|
-
puts
|
16
|
-
sleep
|
15
|
+
puts 'Redis crashed, retrying'
|
16
|
+
sleep 2
|
17
17
|
@redis = new_redis
|
18
18
|
retry
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def new_redis
|
23
|
-
::Redis.
|
23
|
+
::Redis.new(@args)
|
24
24
|
end
|
25
|
-
end
|
25
|
+
end
|
data/lib/redis_queue.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
require_relative 'redis_connection'
|
2
|
-
|
3
1
|
class RedisQueue
|
4
|
-
PUSH_CODE = "
|
2
|
+
PUSH_CODE = ''"
|
5
3
|
if ARGV[3] == 'true' then
|
6
4
|
local insert = redis.call('linsert', ARGV[1], 'before', '', ARGV[2])
|
7
5
|
if insert == -1 or insert == 0 then
|
@@ -10,70 +8,72 @@ class RedisQueue
|
|
10
8
|
end
|
11
9
|
else
|
12
10
|
redis.call('rpush', ARGV[1], ARGV[2])
|
13
|
-
end"
|
11
|
+
end"''.freeze
|
14
12
|
|
15
13
|
SCRIPTS = {
|
16
14
|
push: PUSH_CODE,
|
17
|
-
repush: "
|
15
|
+
repush: ''"
|
18
16
|
#{PUSH_CODE}
|
19
17
|
redis.call('srem', ARGV[1]..'_in_use', ARGV[2])
|
20
|
-
"
|
21
|
-
fail: "
|
18
|
+
"'',
|
19
|
+
fail: ''"
|
22
20
|
redis.call('sadd', ARGV[1]..'_failed', ARGV[2])
|
23
21
|
redis.call('srem', ARGV[1]..'_in_use', ARGV[2])
|
24
|
-
"
|
25
|
-
done: "
|
22
|
+
"'',
|
23
|
+
done: ''"
|
26
24
|
redis.call('sadd', ARGV[1]..'_done', ARGV[2])
|
27
25
|
redis.call('srem', ARGV[1]..'_in_use', ARGV[2])
|
28
|
-
"
|
29
|
-
unpop: "
|
26
|
+
"'',
|
27
|
+
unpop: ''"
|
30
28
|
redis.call('lpush', ARGV[1], ARGV[2])
|
31
29
|
redis.call('srem', ARGV[1]..'_in_use', ARGV[2])
|
32
|
-
"
|
33
|
-
init_from: "
|
30
|
+
"'',
|
31
|
+
init_from: ''"
|
34
32
|
local vals = redis.call('smembers', ARGV[2])
|
35
33
|
for i = 1, table.getn(vals) do
|
36
34
|
redis.call('lpush', ARGV[1], vals[i])
|
37
|
-
end"
|
38
|
-
}
|
35
|
+
end"''
|
36
|
+
}.freeze
|
39
37
|
|
40
|
-
def initialize
|
41
|
-
args = {id: :messages, url: 'redis://localhost:6379/0'}.merge(args)
|
38
|
+
def initialize(args = {})
|
39
|
+
args = { id: :messages, url: 'redis://localhost:6379/0' }.merge(args)
|
42
40
|
@id = args.delete(:id)
|
43
41
|
@redis = RedisConnection.new(args)
|
44
42
|
@redis_blocking = RedisConnection.new(args)
|
45
43
|
load_scripts
|
46
44
|
end
|
47
45
|
|
48
|
-
def pop
|
46
|
+
def pop(block: true)
|
47
|
+
command = block ? :blpop : :lpop
|
49
48
|
begin
|
50
|
-
message = @redis_blocking.run { |redis| redis.
|
49
|
+
message = @redis_blocking.run { |redis| redis.send(command, @id) }
|
50
|
+
message = message.last if command == :blpop
|
51
51
|
end while message == ''
|
52
|
-
@redis.run { |redis| redis.sadd "#{@id}_in_use", message }
|
52
|
+
@redis.run { |redis| redis.sadd "#{@id}_in_use", message } if message
|
53
53
|
message
|
54
54
|
end
|
55
55
|
|
56
|
-
def push
|
56
|
+
def push(message, priority = false)
|
57
57
|
script :push, @id, message, priority
|
58
58
|
end
|
59
59
|
|
60
|
-
def fail
|
60
|
+
def fail(message)
|
61
61
|
script :fail, @id, message
|
62
62
|
end
|
63
63
|
|
64
|
-
def done
|
64
|
+
def done(message)
|
65
65
|
script :done, @id, message
|
66
66
|
end
|
67
67
|
|
68
|
-
def unpop
|
68
|
+
def unpop(message)
|
69
69
|
script :unpop, @id, message
|
70
70
|
end
|
71
71
|
|
72
|
-
def repush
|
72
|
+
def repush(message, priority = false)
|
73
73
|
script :repush, @id, message, priority
|
74
74
|
end
|
75
75
|
|
76
|
-
def forget
|
76
|
+
def forget(message)
|
77
77
|
@redis.run { |redis| redis.srem "#{@id}_in_use", message }
|
78
78
|
end
|
79
79
|
|
@@ -87,7 +87,7 @@ class RedisQueue
|
|
87
87
|
@redis.run { |redis| redis.del "#{@id}_done" }
|
88
88
|
end
|
89
89
|
|
90
|
-
def init_from
|
90
|
+
def init_from(set)
|
91
91
|
script(:init_from, @id, set)
|
92
92
|
end
|
93
93
|
|
@@ -157,7 +157,9 @@ class RedisQueue
|
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
160
|
-
def script
|
160
|
+
def script(name, *args)
|
161
161
|
@redis.run { |redis| redis.evalsha @scripts[name], argv: args }
|
162
162
|
end
|
163
163
|
end
|
164
|
+
|
165
|
+
require_relative 'redis_connection'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jose Ignacio Fernandez
|
@@ -14,16 +14,22 @@ dependencies:
|
|
14
14
|
name: redis
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
17
20
|
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
22
|
+
version: 4.0.1
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4.0'
|
24
30
|
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
32
|
+
version: 4.0.1
|
27
33
|
description: A redis-based queue
|
28
34
|
email: joseignacio.fernandez@gmail.com
|
29
35
|
executables: []
|
@@ -52,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
58
|
version: '0'
|
53
59
|
requirements: []
|
54
60
|
rubyforge_project:
|
55
|
-
rubygems_version: 2.
|
61
|
+
rubygems_version: 2.6.11
|
56
62
|
signing_key:
|
57
63
|
specification_version: 4
|
58
64
|
summary: Redis Queue
|