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

https://github.com/delowong/logstash · Ruby · 101 lines · 77 code · 23 blank · 1 comment · 0 complexity · 24f46faa9959d569278373a1cc344c3c MD5 · raw file

  1. # encoding: UTF-8
  2. require File.expand_path("helper", File.dirname(__FILE__))
  3. require "lint/strings"
  4. class TestCommandsOnStrings < Test::Unit::TestCase
  5. include Helper::Client
  6. include Lint::Strings
  7. def test_mget
  8. r.set("foo", "s1")
  9. r.set("bar", "s2")
  10. assert_equal ["s1", "s2"] , r.mget("foo", "bar")
  11. assert_equal ["s1", "s2", nil], r.mget("foo", "bar", "baz")
  12. end
  13. def test_mget_mapped
  14. r.set("foo", "s1")
  15. r.set("bar", "s2")
  16. response = r.mapped_mget("foo", "bar")
  17. assert_equal "s1", response["foo"]
  18. assert_equal "s2", response["bar"]
  19. response = r.mapped_mget("foo", "bar", "baz")
  20. assert_equal "s1", response["foo"]
  21. assert_equal "s2", response["bar"]
  22. assert_equal nil , response["baz"]
  23. end
  24. def test_mapped_mget_in_a_pipeline_returns_hash
  25. r.set("foo", "s1")
  26. r.set("bar", "s2")
  27. result = r.pipelined do
  28. r.mapped_mget("foo", "bar")
  29. end
  30. assert_equal result[0], { "foo" => "s1", "bar" => "s2" }
  31. end
  32. def test_mset
  33. r.mset(:foo, "s1", :bar, "s2")
  34. assert_equal "s1", r.get("foo")
  35. assert_equal "s2", r.get("bar")
  36. end
  37. def test_mset_mapped
  38. r.mapped_mset(:foo => "s1", :bar => "s2")
  39. assert_equal "s1", r.get("foo")
  40. assert_equal "s2", r.get("bar")
  41. end
  42. def test_msetnx
  43. r.set("foo", "s1")
  44. assert_equal false, r.msetnx(:foo, "s2", :bar, "s3")
  45. assert_equal "s1", r.get("foo")
  46. assert_equal nil, r.get("bar")
  47. r.del("foo")
  48. assert_equal true, r.msetnx(:foo, "s2", :bar, "s3")
  49. assert_equal "s2", r.get("foo")
  50. assert_equal "s3", r.get("bar")
  51. end
  52. def test_msetnx_mapped
  53. r.set("foo", "s1")
  54. assert_equal false, r.mapped_msetnx(:foo => "s2", :bar => "s3")
  55. assert_equal "s1", r.get("foo")
  56. assert_equal nil, r.get("bar")
  57. r.del("foo")
  58. assert_equal true, r.mapped_msetnx(:foo => "s2", :bar => "s3")
  59. assert_equal "s2", r.get("foo")
  60. assert_equal "s3", r.get("bar")
  61. end
  62. def test_bitop
  63. try_encoding("UTF-8") do
  64. target_version "2.5.10" do
  65. r.set("foo", "a")
  66. r.set("bar", "b")
  67. r.bitop(:and, "foo&bar", "foo", "bar")
  68. assert_equal "\x60", r.get("foo&bar")
  69. r.bitop(:or, "foo|bar", "foo", "bar")
  70. assert_equal "\x63", r.get("foo|bar")
  71. r.bitop(:xor, "foo^bar", "foo", "bar")
  72. assert_equal "\x03", r.get("foo^bar")
  73. r.bitop(:not, "~foo", "foo")
  74. assert_equal "\x9E", r.get("~foo")
  75. end
  76. end
  77. end
  78. end