PageRenderTime 40ms CodeModel.GetById 19ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/bundle/jruby/2.1/gems/redis-3.0.7/test/sorting_test.rb

https://github.com/delowong/logstash
Ruby | 59 lines | 41 code | 17 blank | 1 comment | 0 complexity | 2d86039f02de3a5ce92dfc4588dc7534 MD5 | raw file
 1# encoding: UTF-8
 2
 3require File.expand_path("helper", File.dirname(__FILE__))
 4
 5class TestSorting < Test::Unit::TestCase
 6
 7  include Helper::Client
 8
 9  def test_sort
10    r.set("foo:1", "s1")
11    r.set("foo:2", "s2")
12
13    r.rpush("bar", "1")
14    r.rpush("bar", "2")
15
16    assert_equal ["s1"], r.sort("bar", :get => "foo:*", :limit => [0, 1])
17    assert_equal ["s2"], r.sort("bar", :get => "foo:*", :limit => [0, 1], :order => "desc alpha")
18  end
19
20  def test_sort_with_an_array_of_gets
21    r.set("foo:1:a", "s1a")
22    r.set("foo:1:b", "s1b")
23
24    r.set("foo:2:a", "s2a")
25    r.set("foo:2:b", "s2b")
26
27    r.rpush("bar", "1")
28    r.rpush("bar", "2")
29
30    assert_equal [["s1a", "s1b"]], r.sort("bar", :get => ["foo:*:a", "foo:*:b"], :limit => [0, 1])
31    assert_equal [["s2a", "s2b"]], r.sort("bar", :get => ["foo:*:a", "foo:*:b"], :limit => [0, 1], :order => "desc alpha")
32    assert_equal [["s1a", "s1b"], ["s2a", "s2b"]], r.sort("bar", :get => ["foo:*:a", "foo:*:b"])
33  end
34
35  def test_sort_with_store
36    r.set("foo:1", "s1")
37    r.set("foo:2", "s2")
38
39    r.rpush("bar", "1")
40    r.rpush("bar", "2")
41
42    r.sort("bar", :get => "foo:*", :store => "baz")
43    assert_equal ["s1", "s2"], r.lrange("baz", 0, -1)
44  end
45
46  def test_sort_with_an_array_of_gets_and_with_store
47    r.set("foo:1:a", "s1a")
48    r.set("foo:1:b", "s1b")
49
50    r.set("foo:2:a", "s2a")
51    r.set("foo:2:b", "s2b")
52
53    r.rpush("bar", "1")
54    r.rpush("bar", "2")
55
56    r.sort("bar", :get => ["foo:*:a", "foo:*:b"], :store => 'baz')
57    assert_equal ["s1a", "s1b", "s2a", "s2b"], r.lrange("baz", 0, -1)
58  end
59end