Skip to content

Commit

Permalink
Allow the Redis namespace to be set via "host:port/namespace"
Browse files Browse the repository at this point in the history
  • Loading branch information
quirkey authored and defunkt committed Aug 24, 2010
1 parent 28e3f03 commit 1840616
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/resque.rb
Expand Up @@ -26,19 +26,24 @@ module Resque
# Accepts:
# 1. A 'hostname:port' string
# 2. A 'hostname:port:db' string (to select the Redis db)
# 3. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`,
# 3. A 'hostname:port/namespace' string (to set the Redis namespace)
# 4. A redis URL string 'redis://host:port'
# 5. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`,
# or `Redis::Namespace`.
def redis=(server)
if server.respond_to? :split
namespace = :resque

if server =~ /redis\:\/\//
redis = Redis.connect(:url => server)
else
server, namespace = server.split('/', 2)
host, port, db = server.split(':')
redis = Redis.new(:host => host, :port => port,
:thread_safe => true, :db => db)
end

@redis = Redis::Namespace.new(:resque, :redis => redis)
@redis = Redis::Namespace.new(namespace, :redis => redis)
elsif server.respond_to? :namespace=
@redis = server
else
Expand Down

0 comments on commit 1840616

Please sign in to comment.