/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. require File.expand_path("helper", File.dirname(__FILE__))
  3. class TestSorting < Test::Unit::TestCase
  4. include Helper::Client
  5. def test_sort
  6. r.set("foo:1", "s1")
  7. r.set("foo:2", "s2")
  8. r.rpush("bar", "1")
  9. r.rpush("bar", "2")
  10. assert_equal ["s1"], r.sort("bar", :get => "foo:*", :limit => [0, 1])
  11. assert_equal ["s2"], r.sort("bar", :get => "foo:*", :limit => [0, 1], :order => "desc alpha")
  12. end
  13. def test_sort_with_an_array_of_gets
  14. r.set("foo:1:a", "s1a")
  15. r.set("foo:1:b", "s1b")
  16. r.set("foo:2:a", "s2a")
  17. r.set("foo:2:b", "s2b")
  18. r.rpush("bar", "1")
  19. r.rpush("bar", "2")
  20. assert_equal [["s1a", "s1b"]], r.sort("bar", :get => ["foo:*:a", "foo:*:b"], :limit => [0, 1])
  21. assert_equal [["s2a", "s2b"]], r.sort("bar", :get => ["foo:*:a", "foo:*:b"], :limit => [0, 1], :order => "desc alpha")
  22. assert_equal [["s1a", "s1b"], ["s2a", "s2b"]], r.sort("bar", :get => ["foo:*:a", "foo:*:b"])
  23. end
  24. def test_sort_with_store
  25. r.set("foo:1", "s1")
  26. r.set("foo:2", "s2")
  27. r.rpush("bar", "1")
  28. r.rpush("bar", "2")
  29. r.sort("bar", :get => "foo:*", :store => "baz")
  30. assert_equal ["s1", "s2"], r.lrange("baz", 0, -1)
  31. end
  32. def test_sort_with_an_array_of_gets_and_with_store
  33. r.set("foo:1:a", "s1a")
  34. r.set("foo:1:b", "s1b")
  35. r.set("foo:2:a", "s2a")
  36. r.set("foo:2:b", "s2b")
  37. r.rpush("bar", "1")
  38. r.rpush("bar", "2")
  39. r.sort("bar", :get => ["foo:*:a", "foo:*:b"], :store => 'baz')
  40. assert_equal ["s1a", "s1b", "s2a", "s2b"], r.lrange("baz", 0, -1)
  41. end
  42. end