PageRenderTime 45ms CodeModel.GetById 15ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 1ms

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