Skip to content
Permalink
Browse files
Added ability to use multi and pipelined commands along with corr…
…esponding specs
  • Loading branch information
carlzulauf committed Aug 24, 2012
1 parent 3232dd8 commit 7ef30e91878689d0411d4b962d6835778335b0bf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
@@ -210,6 +210,14 @@ def keys(query = nil)
query.nil? ? super("*") : super
end

def multi(&block)
namespaced_block(:multi, &block)
end

def pipelined(&block)
namespaced_block(:pipelined, &block)
end

def method_missing(command, *args, &block)
handling = COMMANDS[command.to_s] ||
COMMANDS[ALIASES[command.to_s]]
@@ -268,6 +276,16 @@ def method_missing(command, *args, &block)
end

private

def namespaced_block(command, &block)
original = @redis
redis.send(command) do |r|
@redis = r
yield self
end
@redis = original
end

def add_namespace(key)
return key unless key && @namespace

@@ -228,6 +228,24 @@
@namespaced.keys.sort.should == %w( bar baz foo )
end

it "should add namepsace to multi blocks" do
@namespaced.mapped_hmset "a_hash", {"foo" => "bar"}
@namespaced.multi do |r|
r.del "a_hash"
r.mapped_hmset "a_hash", {"yin" => "yang"}
end
@namespaced.hgetall("a_hash").should == {"yin" => "yang"}
end

it "should add namespace to pipelined blocks" do
@namespaced.mapped_hmset "a_hash", {"foo" => "bar"}
@namespaced.pipelined do |r|
r.del "a_hash"
r.mapped_hmset "a_hash", {"yin" => "yang"}
end
@namespaced.hgetall("a_hash").should == {"yin" => "yang"}
end

it "can change its namespace" do
@namespaced['foo'].should == nil
@namespaced['foo'] = 'chris'

7 comments on commit 7ef30e9

@steveklabnik
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what yet, but this commit broke Resque's tests :(

@carlzulauf
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is not threadsafe? I will try to look at this a little closer and pull down resque's test suite.

@carlzulauf
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled down the latest master branch of resque.

I tried running the tests against the redis-namespace version specified in resque's gemspec, tests passed. I tried running the tests against the master HEAD of redis-namespace (which includes this commit), tests passed. I then did git co -b test-fix 7ef30e91 and ran the reque tests against that commit specifically, and the tests still passed for me.

I'd be happy to look at this closer if you could let me know what test is failing for you.

@steveklabnik
Copy link
Member

@steveklabnik steveklabnik commented on 7ef30e9 May 4, 2013 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steveklabnik
Copy link
Member

@steveklabnik steveklabnik commented on 7ef30e9 May 4, 2013 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ecoffey
Copy link
Member

@ecoffey ecoffey commented on 7ef30e9 May 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A git checkout 7ef30e91878689d0411d4b962d6835778335b0bf and rake yields a clean test run for me

@ecoffey
Copy link
Member

@ecoffey ecoffey commented on 7ef30e9 May 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which legacy test in resque led you down this way? I can take a look there too :-)

Please sign in to comment.