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

https://github.com/delowong/logstash · Ruby · 122 lines · 93 code · 29 blank · 0 comment · 1 complexity · debc823997057eec1c0467d8b6da2396 MD5 · raw file

  1. module Lint
  2. module ValueTypes
  3. def test_exists
  4. assert_equal false, r.exists("foo")
  5. r.set("foo", "s1")
  6. assert_equal true, r.exists("foo")
  7. end
  8. def test_type
  9. assert_equal "none", r.type("foo")
  10. r.set("foo", "s1")
  11. assert_equal "string", r.type("foo")
  12. end
  13. def test_keys
  14. r.set("f", "s1")
  15. r.set("fo", "s2")
  16. r.set("foo", "s3")
  17. assert_equal ["f","fo", "foo"], r.keys("f*").sort
  18. end
  19. def test_expire
  20. r.set("foo", "s1")
  21. assert r.expire("foo", 2)
  22. assert_in_range 0..2, r.ttl("foo")
  23. end
  24. def test_pexpire
  25. target_version "2.5.4" do
  26. r.set("foo", "s1")
  27. assert r.pexpire("foo", 2000)
  28. assert_in_range 0..2, r.ttl("foo")
  29. end
  30. end
  31. def test_expireat
  32. r.set("foo", "s1")
  33. assert r.expireat("foo", (Time.now + 2).to_i)
  34. assert_in_range 0..2, r.ttl("foo")
  35. end
  36. def test_pexpireat
  37. target_version "2.5.4" do
  38. r.set("foo", "s1")
  39. assert r.pexpireat("foo", (Time.now + 2).to_i * 1_000)
  40. assert_in_range 0..2, r.ttl("foo")
  41. end
  42. end
  43. def test_persist
  44. r.set("foo", "s1")
  45. r.expire("foo", 1)
  46. r.persist("foo")
  47. assert(-1 == r.ttl("foo"))
  48. end
  49. def test_ttl
  50. r.set("foo", "s1")
  51. r.expire("foo", 2)
  52. assert_in_range 0..2, r.ttl("foo")
  53. end
  54. def test_pttl
  55. target_version "2.5.4" do
  56. r.set("foo", "s1")
  57. r.expire("foo", 2)
  58. assert_in_range 1..2000, r.pttl("foo")
  59. end
  60. end
  61. def test_dump_and_restore
  62. target_version "2.5.7" do
  63. r.set("foo", "a")
  64. v = r.dump("foo")
  65. r.del("foo")
  66. assert r.restore("foo", 1000, v)
  67. assert_equal "a", r.get("foo")
  68. assert [0, 1].include? r.ttl("foo")
  69. r.rpush("bar", ["b", "c", "d"])
  70. w = r.dump("bar")
  71. r.del("bar")
  72. assert r.restore("bar", 1000, w)
  73. assert_equal ["b", "c", "d"], r.lrange("bar", 0, -1)
  74. assert [0, 1].include? r.ttl("bar")
  75. end
  76. end
  77. def test_move
  78. r.select 14
  79. r.flushdb
  80. r.set "bar", "s3"
  81. r.select 15
  82. r.set "foo", "s1"
  83. r.set "bar", "s2"
  84. assert r.move("foo", 14)
  85. assert_equal nil, r.get("foo")
  86. assert !r.move("bar", 14)
  87. assert_equal "s2", r.get("bar")
  88. r.select 14
  89. assert_equal "s1", r.get("foo")
  90. assert_equal "s3", r.get("bar")
  91. end
  92. end
  93. end