redis_queue 0.4 → 0.5
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_queue.rb +35 -25
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83d7bc9d87624d6c6e049a3fe88daa963895d85f
|
4
|
+
data.tar.gz: 696a10c9b9f5c0d822b85e0521ead406a56c49e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66beafeceb0ee5f8436cf9c9e2a6f978bdbde4387ad2e381db6773b1fb1dccbedd1ccbaaefa9607385025d40ce00b5ddd5f3a132677aec7ae2f687a9a055e9c1
|
7
|
+
data.tar.gz: c31e7772d52044493d111fbfdea9d1a234c52b12b1930d4487f3b953fa72e1aac59161e98aa7ee33d54ba1d70e3131aebd5baa321d1b461bc80c276c2df04c2f
|
data/lib/redis_queue.rb
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
require_relative 'redis_connection'
|
2
2
|
|
3
3
|
class RedisQueue
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
redis.call('lpush', ARGV[1], ARGV[2])
|
11
|
-
end
|
12
|
-
else
|
13
|
-
redis.call('rpush', ARGV[1], ARGV[2])
|
4
|
+
PUSH_CODE = """
|
5
|
+
if ARGV[3] == 'true' then
|
6
|
+
local insert = redis.call('linsert', ARGV[1], 'before', '', ARGV[2])
|
7
|
+
if insert == -1 or insert == 0 then
|
8
|
+
redis.call('lpush', ARGV[1], '')
|
9
|
+
redis.call('lpush', ARGV[1], ARGV[2])
|
14
10
|
end
|
11
|
+
else
|
12
|
+
redis.call('rpush', ARGV[1], ARGV[2])
|
13
|
+
end"""
|
14
|
+
|
15
|
+
SCRIPTS = {
|
16
|
+
push: PUSH_CODE,
|
17
|
+
repush: """
|
18
|
+
#{PUSH_CODE}
|
19
|
+
redis.call('srem', ARGV[1]..'_in_use', ARGV[2])
|
15
20
|
""",
|
16
21
|
fail: """
|
17
22
|
redis.call('sadd', ARGV[1]..'_failed', ARGV[2])
|
@@ -32,7 +37,8 @@ class RedisQueue
|
|
32
37
|
end"""
|
33
38
|
}
|
34
39
|
|
35
|
-
def initialize args={
|
40
|
+
def initialize args={}
|
41
|
+
args = {id: :messages, url: 'redis://localhost:6379/0'}.merge(args)
|
36
42
|
@id = args.delete(:id)
|
37
43
|
@redis = RedisConnection.new(args)
|
38
44
|
@redis_blocking = RedisConnection.new(args)
|
@@ -41,30 +47,34 @@ class RedisQueue
|
|
41
47
|
|
42
48
|
def pop
|
43
49
|
begin
|
44
|
-
|
45
|
-
end while
|
46
|
-
@redis.run { |redis| redis.sadd "#{@id}_in_use",
|
47
|
-
|
50
|
+
message = @redis_blocking.run { |redis| redis.blpop(@id) }.last
|
51
|
+
end while message == ''
|
52
|
+
@redis.run { |redis| redis.sadd "#{@id}_in_use", message }
|
53
|
+
message
|
54
|
+
end
|
55
|
+
|
56
|
+
def push message, priority=false
|
57
|
+
script :push, @id, message, priority
|
48
58
|
end
|
49
59
|
|
50
|
-
def
|
51
|
-
script :
|
60
|
+
def fail message
|
61
|
+
script :fail, @id, message
|
52
62
|
end
|
53
63
|
|
54
|
-
def
|
55
|
-
script :
|
64
|
+
def done message
|
65
|
+
script :done, @id, message
|
56
66
|
end
|
57
67
|
|
58
|
-
def
|
59
|
-
script :
|
68
|
+
def unpop message
|
69
|
+
script :unpop, @id, message
|
60
70
|
end
|
61
71
|
|
62
|
-
def
|
63
|
-
script :
|
72
|
+
def repush message, priority=false
|
73
|
+
script :repush, @id, message, priority
|
64
74
|
end
|
65
75
|
|
66
|
-
def forget
|
67
|
-
@redis.run { |redis| redis.srem "#{@id}_in_use",
|
76
|
+
def forget message
|
77
|
+
@redis.run { |redis| redis.srem "#{@id}_in_use", message }
|
68
78
|
end
|
69
79
|
|
70
80
|
def reset
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jose Ignacio Fernandez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|