Skip to content

Commit

Permalink
Merge branch 'master' of github.com:defunkt/resque
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Aug 24, 2010
2 parents c70d454 + f15aedb commit ff5fc9b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/resque.rb
Expand Up @@ -26,19 +26,23 @@ 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
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
namespace ||= :resque

@redis = Redis::Namespace.new(:resque, :redis => redis)
@redis = Redis::Namespace.new(namespace, :redis => redis)
elsif server.respond_to? :namespace=
@redis = server
else
Expand Down
2 changes: 1 addition & 1 deletion resque.gemspec
Expand Up @@ -24,7 +24,7 @@ Gem::Specification.new do |s|
s.add_dependency "redis-namespace", "~> 0.8.0"
s.add_dependency "vegas", "~> 0.1.2"
s.add_dependency "sinatra", ">= 0.9.2"
s.add_dependency "json_pure", "~> 1.4.0"
s.add_dependency "json", "~> 1.4.6"

s.description = <<description
Resque is a Redis-backed Ruby library for creating background jobs,
Expand Down
9 changes: 8 additions & 1 deletion test/resque_test.rb
Expand Up @@ -8,6 +8,13 @@
Resque.push(:people, { 'name' => 'bob' })
Resque.push(:people, { 'name' => 'mark' })
end

test "can set a namespace through a url-like string" do
assert Resque.redis
assert_equal :resque, Resque.redis.namespace
Resque.redis = 'localhost:9736/namespace'
assert_equal 'namespace', Resque.redis.namespace
end

test "can put jobs on a queue" do
assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
Expand Down Expand Up @@ -222,4 +229,4 @@
test "decode bad json" do
assert_nil Resque.decode("{\"error\":\"Module not found \\u002\"}")
end
end
end

0 comments on commit ff5fc9b

Please sign in to comment.