simple_queues 1.0.0 → 1.0.1
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.
- data/lib/simple_queues/redis.rb +14 -4
- data/lib/simple_queues/version.rb +1 -1
- data/simple_queues.gemspec +1 -0
- data/spec/enqueueing_spec.rb +7 -4
- metadata +19 -6
data/lib/simple_queues/redis.rb
CHANGED
@@ -1,12 +1,23 @@
|
|
1
|
+
autoload :Redis, "redis"
|
2
|
+
require 'json'
|
3
|
+
|
1
4
|
module SimpleQueues
|
2
5
|
# The Redis version of SimpleQueues.
|
3
6
|
#
|
4
7
|
# Messages are enqueued to the right, dequeued from the left - thus the most recent messages are at the end of the list.
|
5
8
|
class Redis
|
6
|
-
def initialize(redis=Redis.new)
|
9
|
+
def initialize(redis = ::Redis.new)
|
7
10
|
@redis = redis
|
8
11
|
end
|
9
12
|
|
13
|
+
def serialize(message)
|
14
|
+
message.to_json
|
15
|
+
end
|
16
|
+
|
17
|
+
def unserialize(message)
|
18
|
+
JSON.parse(message) if message
|
19
|
+
end
|
20
|
+
|
10
21
|
# Enqueues a new message to the Redis backend.
|
11
22
|
#
|
12
23
|
# @param queue_name [String, Symbol] The queue name, which must not be nil or the empty String.
|
@@ -16,8 +27,7 @@ module SimpleQueues
|
|
16
27
|
def enqueue(queue_name, message)
|
17
28
|
raise ArgumentError, "Queue name argument was nil - must not be" if queue_name.nil? || queue_name.to_s.empty?
|
18
29
|
raise ArgumentError, "Message argument was nil - must not be" if message.nil?
|
19
|
-
|
20
|
-
@redis.rpush(queue_name.to_s, message.to_s)
|
30
|
+
@redis.rpush(queue_name.to_s, serialize(message))
|
21
31
|
end
|
22
32
|
|
23
33
|
# Dequeues a message, and waits forever for one to arrive.
|
@@ -38,7 +48,7 @@ module SimpleQueues
|
|
38
48
|
def dequeue_with_timeout(queue_name, timeout)
|
39
49
|
raise ArgumentError, "Queue name argument was nil - must not be" if queue_name.nil? || queue_name.to_s.empty?
|
40
50
|
|
41
|
-
@redis.blpop(queue_name.to_s, timeout)
|
51
|
+
unserialize(@redis.blpop(queue_name.to_s, timeout))
|
42
52
|
end
|
43
53
|
end
|
44
54
|
end
|
data/simple_queues.gemspec
CHANGED
data/spec/enqueueing_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe SimpleQueues::Redis, "enqueue" do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should enqueue to the end of the list" do
|
13
|
-
redis.should_receive(:rpush).with("q", "message")
|
13
|
+
redis.should_receive(:rpush).with("q", '"message"')
|
14
14
|
queue.enqueue("q", "message")
|
15
15
|
end
|
16
16
|
|
@@ -29,12 +29,15 @@ describe SimpleQueues::Redis, "enqueue" do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "accepts symbols as queue names, translating to a string" do
|
32
|
-
redis.should_receive(:rpush).with("pages_to_crawl", "http://blog.teksol.info/")
|
32
|
+
redis.should_receive(:rpush).with("pages_to_crawl", '"http://blog.teksol.info/"')
|
33
33
|
queue.enqueue :pages_to_crawl, "http://blog.teksol.info/"
|
34
34
|
end
|
35
35
|
|
36
|
-
it "translates the message
|
37
|
-
redis.should_receive(:rpush).with("ops", "shutdown_and_destroy")
|
36
|
+
it "translates the message using JSON before enqueueing" do
|
37
|
+
redis.should_receive(:rpush).with("ops", '"shutdown_and_destroy"')
|
38
38
|
queue.enqueue :ops, :shutdown_and_destroy
|
39
|
+
|
40
|
+
redis.should_receive(:rpush).with("ops", '[1,2,3]')
|
41
|
+
queue.enqueue :ops, [1, 2, 3]
|
39
42
|
end
|
40
43
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 1
|
9
|
+
version: 1.0.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Fran\xC3\xA7ois Beausoleil"
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
type: :runtime
|
32
32
|
version_requirements: *id001
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
34
|
+
name: json
|
35
35
|
prerelease: false
|
36
36
|
requirement: &id002 !ruby/object:Gem::Requirement
|
37
37
|
none: false
|
@@ -41,10 +41,10 @@ dependencies:
|
|
41
41
|
segments:
|
42
42
|
- 0
|
43
43
|
version: "0"
|
44
|
-
type: :
|
44
|
+
type: :runtime
|
45
45
|
version_requirements: *id002
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: rspec
|
48
48
|
prerelease: false
|
49
49
|
requirement: &id003 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
@@ -57,7 +57,7 @@ dependencies:
|
|
57
57
|
type: :development
|
58
58
|
version_requirements: *id003
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
60
|
+
name: yard
|
61
61
|
prerelease: false
|
62
62
|
requirement: &id004 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
@@ -69,6 +69,19 @@ dependencies:
|
|
69
69
|
version: "0"
|
70
70
|
type: :development
|
71
71
|
version_requirements: *id004
|
72
|
+
- !ruby/object:Gem::Dependency
|
73
|
+
name: RedCloth
|
74
|
+
prerelease: false
|
75
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
type: :development
|
84
|
+
version_requirements: *id005
|
72
85
|
description: Program to an interface, not an implementation - hides Redis (used as a queue) behind a simple interface
|
73
86
|
email:
|
74
87
|
- francois@teksol.info
|