Skip to content

Commit 12d975c

Browse files
committed
expose #name on queue and have a #redis_name
1 parent 8b356f7 commit 12d975c

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

lib/resque/queue.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,23 @@ module Resque
99
class Queue
1010
include Mutex_m
1111

12+
attr_reader :name, :redis_name
13+
1214
###
1315
# Create a new Queue object with +name+ on +redis+ connection, and using
1416
# the +coder+ for encoding and decoding objects that are stored in redis.
1517
def initialize name, redis, coder = Marshal
1618
super()
17-
@name = "queue:#{name}"
18-
@redis = redis
19-
@coder = coder
19+
@name = name
20+
@redis_name = "queue:#{@name}"
21+
@redis = redis
22+
@coder = coder
2023
end
2124

2225
# Add +object+ to the queue
2326
def push object
2427
synchronize do
25-
@redis.rpush @name, encode(object)
28+
@redis.rpush @redis_name, encode(object)
2629
end
2730
end
2831

@@ -34,11 +37,11 @@ def push object
3437
def slice start, length
3538
if length == 1
3639
synchronize do
37-
decode @redis.lindex @name, start
40+
decode @redis.lindex @redis_name, start
3841
end
3942
else
4043
synchronize do
41-
Array(@redis.lrange(@name, start, start + length - 1)).map do |item|
44+
Array(@redis.lrange(@redis_name, start, start + length - 1)).map do |item|
4245
decode item
4346
end
4447
end
@@ -53,21 +56,21 @@ def slice start, length
5356
def pop non_block = false
5457
if non_block
5558
synchronize do
56-
value = @redis.lpop(@name)
59+
value = @redis.lpop(@redis_name)
5760
raise ThreadError unless value
5861
decode value
5962
end
6063
else
6164
synchronize do
62-
value = @redis.blpop(@name, 1) until value
65+
value = @redis.blpop(@redis_name, 1) until value
6366
decode value.last
6467
end
6568
end
6669
end
6770

6871
# Get the length of the queue
6972
def length
70-
@redis.llen @name
73+
@redis.llen @redis_name
7174
end
7275
alias :size :length
7376

@@ -79,7 +82,7 @@ def empty?
7982
# Deletes this Queue from redis. This method is *not* available on the
8083
# stdlib Queue.
8184
def destroy
82-
@redis.del @name
85+
@redis.del @redis_name
8386
end
8487

8588
private

test/redis_queue_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def == other
1616
end
1717
end
1818

19+
it "generates a redis_name" do
20+
assert_equal "queue:foo", q.redis_name
21+
end
22+
1923
it "acts sanely" do
2024
queue = q
2125
x = Thing.new

0 commit comments

Comments
 (0)