Sha256: 7722bc145dbb01763d353ed8113879dae542ebe81dd1a942e351d7baa2ae7ac2

Contents?: true

Size: 1.54 KB

Versions: 23

Compression:

Stored size: 1.54 KB

Contents

# encoding: UTF-8

require File.expand_path("helper", File.dirname(__FILE__))

class TestSorting < Test::Unit::TestCase

  include Helper::Client

  def test_sort
    r.set("foo:1", "s1")
    r.set("foo:2", "s2")

    r.rpush("bar", "1")
    r.rpush("bar", "2")

    assert_equal ["s1"], r.sort("bar", :get => "foo:*", :limit => [0, 1])
    assert_equal ["s2"], r.sort("bar", :get => "foo:*", :limit => [0, 1], :order => "desc alpha")
  end

  def test_sort_with_an_array_of_gets
    r.set("foo:1:a", "s1a")
    r.set("foo:1:b", "s1b")

    r.set("foo:2:a", "s2a")
    r.set("foo:2:b", "s2b")

    r.rpush("bar", "1")
    r.rpush("bar", "2")

    assert_equal [["s1a", "s1b"]], r.sort("bar", :get => ["foo:*:a", "foo:*:b"], :limit => [0, 1])
    assert_equal [["s2a", "s2b"]], r.sort("bar", :get => ["foo:*:a", "foo:*:b"], :limit => [0, 1], :order => "desc alpha")
    assert_equal [["s1a", "s1b"], ["s2a", "s2b"]], r.sort("bar", :get => ["foo:*:a", "foo:*:b"])
  end

  def test_sort_with_store
    r.set("foo:1", "s1")
    r.set("foo:2", "s2")

    r.rpush("bar", "1")
    r.rpush("bar", "2")

    r.sort("bar", :get => "foo:*", :store => "baz")
    assert_equal ["s1", "s2"], r.lrange("baz", 0, -1)
  end

  def test_sort_with_an_array_of_gets_and_with_store
    r.set("foo:1:a", "s1a")
    r.set("foo:1:b", "s1b")

    r.set("foo:2:a", "s2a")
    r.set("foo:2:b", "s2b")

    r.rpush("bar", "1")
    r.rpush("bar", "2")

    r.sort("bar", :get => ["foo:*:a", "foo:*:b"], :store => 'baz')
    assert_equal ["s1a", "s1b", "s2a", "s2b"], r.lrange("baz", 0, -1)
  end
end

Version data entries

23 entries across 22 versions & 8 rubygems

Version Path
finsync_redis-3.3.5 test/sorting_test.rb
redis-3.3.5 test/sorting_test.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/redis-3.3.3/test/sorting_test.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/test/sorting_test.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/test/sorting_test.rb
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/redis-3.3.3/test/sorting_test.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/redis-3.3.3/test/sorting_test.rb
redis-3.3.3 test/sorting_test.rb
abaci-0.3.0 vendor/bundle/gems/redis-3.3.1/test/sorting_test.rb
abaci-0.3.0 vendor/bundle/gems/redis-3.3.2/test/sorting_test.rb
redis-3.3.2 test/sorting_test.rb
redis-3.3.1 test/sorting_test.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/test/sorting_test.rb
redis-3.3.0 test/sorting_test.rb
discourse-redis-3.2.2 test/sorting_test.rb
redis-3.2.2 test/sorting_test.rb
redis-3.2.1 test/sorting_test.rb
redis-3.2.0 test/sorting_test.rb
redis2-namespaced-3.0.7.1 test/sorting_test.rb
redis2-namespaced-3.0.7 test/sorting_test.rb