Skip to content

Commit

Permalink
test SORT properly
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed Apr 20, 2011
1 parent 4d96f72 commit b260cb2
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 54 deletions.
3 changes: 1 addition & 2 deletions spec/live_redis_protocol_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,8 @@ def set(&blk)
end

it "collates a sorted set of data" do
pending("not supported yet")
set do |redis|
redis.sort("foo", "BY *_sort", "GET *_data") do |r|
redis.sort("foo", "BY", "*_sort", "GET", "*_data") do |r|
r.should == ["bar", "foo"]
done
end
Expand Down
126 changes: 74 additions & 52 deletions spec/redis_commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -478,45 +478,6 @@
end
end

it "sorts" do
pending("can't figure out sort yet")
connect do |redis|
# The 'Dogs' is capitialized on purpose
redis['dog_1'] = 'louie'
redis.rpush 'Dogs', 1
redis['dog_2'] = 'lucy'
redis.rpush 'Dogs', 2
redis['dog_3'] = 'max'
redis.rpush 'Dogs', 3
redis['dog_4'] = 'taj'
redis.rpush 'Dogs', 4
redis.sort('Dogs', :get => 'dog_*', :limit => [0,1]) { |r| r.should == ['louie'] }
redis.sort('Dogs', :get => 'dog_*', :limit => [0,1], :order => 'desc alpha') { |r| r.should == ['taj'] }
redis.ping { done }
end
end

it "handles array of :get using SORT" do
pending("can't figure out sort yet")
connect do |redis|
redis['dog:1:name'] = 'louie'
redis['dog:1:breed'] = 'mutt'
redis.rpush 'dogs', 1
redis['dog:2:name'] = 'lucy'
redis['dog:2:breed'] = 'poodle'
redis.rpush 'dogs', 2
redis['dog:3:name'] = 'max'
redis['dog:3:breed'] = 'hound'
redis.rpush 'dogs', 3
redis['dog:4:name'] = 'taj'
redis['dog:4:breed'] = 'terrier'
redis.rpush 'dogs', 4
redis.sort('dogs', :get => ['dog:*:name', 'dog:*:breed'], :limit => [0,1]) { |r| r.should == ['louie', 'mutt'] }
redis.sort('dogs', :get => ['dog:*:name', 'dog:*:breed'], :limit => [0,1], :order => 'desc alpha') { |r| r.should == ['taj', 'terrier'] }
redis.ping { done }
end
end

it "counts the members of a zset" do
connect do |redis|
redis.sadd "set", 'key1'
Expand Down Expand Up @@ -760,19 +721,6 @@
end
end

# Tests are disabled due uncatchable exceptions. We should use on_error callback,
# intead of raising exceptions in random places.
#
# it "should raise error when invoke MONITOR" do
# # lambda { redis.monitor }.should.raise
# done
# end
#
# it "should raise error when invoke SYNC" do
# # lambda { redis.sync }.should.raise
# done
# end

it "runs MULTI without a block" do
connect do |redis|
redis.multi
Expand Down Expand Up @@ -903,3 +851,77 @@ def set(&blk)
end
end
end

describe EventMachine::Hiredis, "sorting" do
context "with some simple sorting data" do
def set(&blk)
connect do |redis|
redis.set('dog_1', 'louie')
redis.rpush 'Dogs', 1
redis.set('dog_2', 'lucy')
redis.rpush 'Dogs', 2
redis.set('dog_3', 'max')
redis.rpush 'Dogs', 3
redis.set('dog_4', 'taj')
redis.rpush 'Dogs', 4
blk.call(redis)
end
end

it "sorts with a limit" do
set do |redis|
redis.sort('Dogs', "GET", 'dog_*', "LIMIT", "0", "1") do |r|
r.should == ['louie']
done
end
end
end

it "sorts with a limit and order" do
set do |redis|
redis.sort('Dogs', "GET", 'dog_*', "LIMIT", "0", "1", "desc", "alpha") do |r|
r.should == ['taj']
done
end
end
end
end

context "with more complex sorting data" do
def set(&blk)
connect do |redis|
redis.set('dog:1:name', 'louie')
redis.set('dog:1:breed', 'mutt')
redis.rpush 'dogs', 1
redis.set('dog:2:name', 'lucy')
redis.set('dog:2:breed', 'poodle')
redis.rpush 'dogs', 2
redis.set('dog:3:name', 'max')
redis.set('dog:3:breed', 'hound')
redis.rpush 'dogs', 3
redis.set('dog:4:name', 'taj')
redis.set('dog:4:breed', 'terrier')
redis.rpush 'dogs', 4
blk.call(redis)
end
end

it "handles multiple GETs" do
set do |redis|
redis.sort('dogs', 'GET', 'dog:*:name', 'GET', 'dog:*:breed', 'LIMIT', '0', '1') do |r|
r.should == ['louie', 'mutt']
done
end
end
end

it "handles multiple GETs with an order" do
set do |redis|
redis.sort('dogs', 'GET', 'dog:*:name', 'GET', 'dog:*:breed', 'LIMIT', '0', '1', 'desc', 'alpha') do |r|
r.should == ['taj', 'terrier']
done
end
end
end
end
end

0 comments on commit b260cb2

Please sign in to comment.