Skip to content

Commit 912ee53

Browse files
ashleym1972defunkt
authored andcommitted
Allow Resque to use DistRedis
1 parent ae19109 commit 912ee53

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/resque.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module Resque
2626
# 1. A 'hostname:port' string
2727
# 2. A 'hostname:port:db' string (to select the Redis db)
2828
# 3. An instance of `Redis`
29+
# 4. An instance of `DistRedis`
2930
def redis=(server)
3031
case server
3132
when String
@@ -34,6 +35,7 @@ def redis=(server)
3435
:thread_safe => true, :db => db)
3536
@redis = Redis::Namespace.new(:resque, :redis => redis)
3637
when Redis
38+
when DistRedis
3739
@redis = Redis::Namespace.new(:resque, :redis => server)
3840
else
3941
raise "I don't know what to do with #{server.inspect}"
@@ -229,7 +231,8 @@ def info
229231
# Returns an array of all known Resque keys in Redis. Redis' KEYS operation
230232
# is O(N) for the keyspace, so be careful - this can be slow for big databases.
231233
def keys
232-
redis.keys("*").map do |key|
234+
redis_keys = redis.keys("*").flatten
235+
redis_keys.map do |key|
233236
key.sub('resque:', '')
234237
end
235238
end

test/resque_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require File.dirname(__FILE__) + '/test_helper'
2+
# require 'dist_redis'
23

34
context "Resque" do
45
setup do
@@ -9,6 +10,10 @@
910
Resque.push(:people, { 'name' => 'mark' })
1011
end
1112

13+
# test "can use DistRedis" do
14+
# assert Resque.redis = DistRedis.new({:hosts => ['localhost:9736', 'localhost:9736']})
15+
# end
16+
1217
test "can put jobs on a queue" do
1318
assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
1419
assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')

0 commit comments

Comments
 (0)