Skip to content

Commit 1840616

Browse files
quirkeydefunkt
authored andcommitted
Allow the Redis namespace to be set via "host:port/namespace"
1 parent 28e3f03 commit 1840616

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/resque.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,24 @@ module Resque
2626
# Accepts:
2727
# 1. A 'hostname:port' string
2828
# 2. A 'hostname:port:db' string (to select the Redis db)
29-
# 3. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`,
29+
# 3. A 'hostname:port/namespace' string (to set the Redis namespace)
30+
# 4. A redis URL string 'redis://host:port'
31+
# 5. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`,
3032
# or `Redis::Namespace`.
3133
def redis=(server)
3234
if server.respond_to? :split
35+
namespace = :resque
36+
3337
if server =~ /redis\:\/\//
3438
redis = Redis.connect(:url => server)
3539
else
40+
server, namespace = server.split('/', 2)
3641
host, port, db = server.split(':')
3742
redis = Redis.new(:host => host, :port => port,
3843
:thread_safe => true, :db => db)
3944
end
4045

41-
@redis = Redis::Namespace.new(:resque, :redis => redis)
46+
@redis = Redis::Namespace.new(namespace, :redis => redis)
4247
elsif server.respond_to? :namespace=
4348
@redis = server
4449
else

0 commit comments

Comments
 (0)