Sha256: d54743562a629e4e108dce28d798216f42d30d883ebf720de0fb2f961059d165

Contents?: true

Size: 1.49 KB

Versions: 4

Compression:

Stored size: 1.49 KB

Contents

# encoding: UTF-8

require "helper"

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

4 entries across 4 versions & 2 rubygems

Version Path
redis-3.0.5 test/sorting_test.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/redis-3.0.4/test/sorting_test.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/redis-3.0.4/test/sorting_test.rb
redis-3.0.4 test/sorting_test.rb