gorsuch-redis 3.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +10 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +113 -0
- data/LICENSE +20 -0
- data/README.md +214 -0
- data/Rakefile +260 -0
- data/TODO.md +4 -0
- data/benchmarking/logging.rb +62 -0
- data/benchmarking/pipeline.rb +51 -0
- data/benchmarking/speed.rb +21 -0
- data/benchmarking/suite.rb +24 -0
- data/benchmarking/thread_safety.rb +38 -0
- data/benchmarking/worker.rb +71 -0
- data/examples/basic.rb +15 -0
- data/examples/dist_redis.rb +43 -0
- data/examples/incr-decr.rb +17 -0
- data/examples/list.rb +26 -0
- data/examples/pubsub.rb +31 -0
- data/examples/sets.rb +36 -0
- data/examples/unicorn/config.ru +3 -0
- data/examples/unicorn/unicorn.rb +20 -0
- data/lib/redis/client.rb +303 -0
- data/lib/redis/connection/command_helper.rb +44 -0
- data/lib/redis/connection/hiredis.rb +52 -0
- data/lib/redis/connection/registry.rb +12 -0
- data/lib/redis/connection/ruby.rb +136 -0
- data/lib/redis/connection/synchrony.rb +131 -0
- data/lib/redis/connection.rb +9 -0
- data/lib/redis/distributed.rb +696 -0
- data/lib/redis/errors.rb +38 -0
- data/lib/redis/hash_ring.rb +131 -0
- data/lib/redis/pipeline.rb +106 -0
- data/lib/redis/subscribe.rb +79 -0
- data/lib/redis/version.rb +3 -0
- data/lib/redis.rb +1724 -0
- data/redis.gemspec +43 -0
- data/test/command_map_test.rb +29 -0
- data/test/commands_on_hashes_test.rb +20 -0
- data/test/commands_on_lists_test.rb +60 -0
- data/test/commands_on_sets_test.rb +76 -0
- data/test/commands_on_sorted_sets_test.rb +108 -0
- data/test/commands_on_strings_test.rb +80 -0
- data/test/commands_on_value_types_test.rb +87 -0
- data/test/connection_handling_test.rb +204 -0
- data/test/db/.gitignore +1 -0
- data/test/distributed_blocking_commands_test.rb +53 -0
- data/test/distributed_commands_on_hashes_test.rb +11 -0
- data/test/distributed_commands_on_lists_test.rb +23 -0
- data/test/distributed_commands_on_sets_test.rb +84 -0
- data/test/distributed_commands_on_sorted_sets_test.rb +19 -0
- data/test/distributed_commands_on_strings_test.rb +49 -0
- data/test/distributed_commands_on_value_types_test.rb +72 -0
- data/test/distributed_commands_requiring_clustering_test.rb +148 -0
- data/test/distributed_connection_handling_test.rb +24 -0
- data/test/distributed_internals_test.rb +27 -0
- data/test/distributed_key_tags_test.rb +52 -0
- data/test/distributed_persistence_control_commands_test.rb +23 -0
- data/test/distributed_publish_subscribe_test.rb +100 -0
- data/test/distributed_remote_server_control_commands_test.rb +42 -0
- data/test/distributed_sorting_test.rb +21 -0
- data/test/distributed_test.rb +59 -0
- data/test/distributed_transactions_test.rb +33 -0
- data/test/encoding_test.rb +15 -0
- data/test/error_replies_test.rb +53 -0
- data/test/helper.rb +155 -0
- data/test/helper_test.rb +8 -0
- data/test/internals_test.rb +152 -0
- data/test/lint/hashes.rb +140 -0
- data/test/lint/internals.rb +36 -0
- data/test/lint/lists.rb +107 -0
- data/test/lint/sets.rb +90 -0
- data/test/lint/sorted_sets.rb +196 -0
- data/test/lint/strings.rb +133 -0
- data/test/lint/value_types.rb +81 -0
- data/test/persistence_control_commands_test.rb +21 -0
- data/test/pipelining_commands_test.rb +186 -0
- data/test/publish_subscribe_test.rb +158 -0
- data/test/redis_mock.rb +89 -0
- data/test/remote_server_control_commands_test.rb +88 -0
- data/test/sorting_test.rb +43 -0
- data/test/synchrony_driver.rb +57 -0
- data/test/test.conf +9 -0
- data/test/thread_safety_test.rb +30 -0
- data/test/transactions_test.rb +173 -0
- data/test/unknown_commands_test.rb +13 -0
- data/test/url_param_test.rb +59 -0
- metadata +236 -0
data/redis.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
4
|
+
|
5
|
+
require "redis/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "gorsuch-redis"
|
9
|
+
|
10
|
+
s.version = Redis::VERSION
|
11
|
+
|
12
|
+
s.homepage = "https://github.com/ezmobius/redis-rb"
|
13
|
+
|
14
|
+
s.summary = "A Ruby client library for the Redis key-value store."
|
15
|
+
|
16
|
+
s.description = <<-EOS
|
17
|
+
A simple Ruby client trying to match Redis' API one-to-one while still providing a Rubystic interface.
|
18
|
+
It features thread safety, client-side sharding, and an obsession for performance.
|
19
|
+
EOS
|
20
|
+
|
21
|
+
s.authors = [
|
22
|
+
"Ezra Zygmuntowicz",
|
23
|
+
"Taylor Weibley",
|
24
|
+
"Matthew Clark",
|
25
|
+
"Brian McKinney",
|
26
|
+
"Salvatore Sanfilippo",
|
27
|
+
"Luca Guidi",
|
28
|
+
"Michel Martens",
|
29
|
+
"Damian Janowski",
|
30
|
+
"Pieter Noordhuis"
|
31
|
+
]
|
32
|
+
|
33
|
+
s.email = ["redis-db@googlegroups.com"]
|
34
|
+
|
35
|
+
s.files = `git ls-files`.split("\n")
|
36
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
37
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
38
|
+
|
39
|
+
s.add_development_dependency("rake")
|
40
|
+
s.add_development_dependency("cutest")
|
41
|
+
s.add_development_dependency("hiredis")
|
42
|
+
s.add_development_dependency("em-synchrony")
|
43
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path("./helper", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
setup do
|
6
|
+
init Redis.new(OPTIONS)
|
7
|
+
end
|
8
|
+
|
9
|
+
test "Override existing commands" do |r|
|
10
|
+
r.set("counter", 1)
|
11
|
+
|
12
|
+
assert 2 == r.incr("counter")
|
13
|
+
|
14
|
+
r.client.command_map[:incr] = :decr
|
15
|
+
|
16
|
+
assert 1 == r.incr("counter")
|
17
|
+
end
|
18
|
+
|
19
|
+
test "Override non-existing commands" do |r|
|
20
|
+
r.set("key", "value")
|
21
|
+
|
22
|
+
assert_raise Redis::CommandError do
|
23
|
+
r.idontexist("key")
|
24
|
+
end
|
25
|
+
|
26
|
+
r.client.command_map[:idontexist] = :get
|
27
|
+
|
28
|
+
assert "value" == r.idontexist("key")
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path("./helper", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
setup do
|
6
|
+
init Redis.new(OPTIONS)
|
7
|
+
end
|
8
|
+
|
9
|
+
load './test/lint/hashes.rb'
|
10
|
+
|
11
|
+
test "Mapped HMGET in a pipeline returns hash" do |r|
|
12
|
+
r.hset("foo", "f1", "s1")
|
13
|
+
r.hset("foo", "f2", "s2")
|
14
|
+
|
15
|
+
result = r.pipelined do
|
16
|
+
r.mapped_hmget("foo", "f1", "f2")
|
17
|
+
end
|
18
|
+
|
19
|
+
assert result[0] == { "f1" => "s1", "f2" => "s2" }
|
20
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path("./helper", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
setup do
|
6
|
+
init Redis.new(OPTIONS)
|
7
|
+
end
|
8
|
+
|
9
|
+
load './test/lint/lists.rb'
|
10
|
+
|
11
|
+
test "RPUSHX" do |r|
|
12
|
+
r.rpushx "foo", "s1"
|
13
|
+
r.rpush "foo", "s2"
|
14
|
+
r.rpushx "foo", "s3"
|
15
|
+
|
16
|
+
assert 2 == r.llen("foo")
|
17
|
+
assert ["s2", "s3"] == r.lrange("foo", 0, -1)
|
18
|
+
end
|
19
|
+
|
20
|
+
test "LPUSHX" do |r|
|
21
|
+
r.lpushx "foo", "s1"
|
22
|
+
r.lpush "foo", "s2"
|
23
|
+
r.lpushx "foo", "s3"
|
24
|
+
|
25
|
+
assert 2 == r.llen("foo")
|
26
|
+
assert ["s3", "s2"] == r.lrange("foo", 0, -1)
|
27
|
+
end
|
28
|
+
|
29
|
+
test "LINSERT" do |r|
|
30
|
+
r.rpush "foo", "s1"
|
31
|
+
r.rpush "foo", "s3"
|
32
|
+
r.linsert "foo", :before, "s3", "s2"
|
33
|
+
|
34
|
+
assert ["s1", "s2", "s3"] == r.lrange("foo", 0, -1)
|
35
|
+
|
36
|
+
assert_raise(Redis::CommandError) do
|
37
|
+
r.linsert "foo", :anywhere, "s3", "s2"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
test "RPOPLPUSH" do |r|
|
42
|
+
r.rpush "foo", "s1"
|
43
|
+
r.rpush "foo", "s2"
|
44
|
+
|
45
|
+
assert "s2" == r.rpoplpush("foo", "bar")
|
46
|
+
assert ["s2"] == r.lrange("bar", 0, -1)
|
47
|
+
assert "s1" == r.rpoplpush("foo", "bar")
|
48
|
+
assert ["s1", "s2"] == r.lrange("bar", 0, -1)
|
49
|
+
end
|
50
|
+
|
51
|
+
test "BRPOPLPUSH" do |r|
|
52
|
+
r.rpush "foo", "s1"
|
53
|
+
r.rpush "foo", "s2"
|
54
|
+
|
55
|
+
assert_equal "s2", r.brpoplpush("foo", "bar", 1)
|
56
|
+
|
57
|
+
assert_equal nil, r.brpoplpush("baz", "qux", 1)
|
58
|
+
|
59
|
+
assert_equal ["s2"], r.lrange("bar", 0, -1)
|
60
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path("./helper", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
setup do
|
6
|
+
init Redis.new(OPTIONS)
|
7
|
+
end
|
8
|
+
|
9
|
+
load './test/lint/sets.rb'
|
10
|
+
|
11
|
+
test "SMOVE" do |r|
|
12
|
+
r.sadd "foo", "s1"
|
13
|
+
r.sadd "bar", "s2"
|
14
|
+
|
15
|
+
assert r.smove("foo", "bar", "s1")
|
16
|
+
assert r.sismember("bar", "s1")
|
17
|
+
end
|
18
|
+
|
19
|
+
test "SINTER" do |r|
|
20
|
+
r.sadd "foo", "s1"
|
21
|
+
r.sadd "foo", "s2"
|
22
|
+
r.sadd "bar", "s2"
|
23
|
+
|
24
|
+
assert ["s2"] == r.sinter("foo", "bar")
|
25
|
+
end
|
26
|
+
|
27
|
+
test "SINTERSTORE" do |r|
|
28
|
+
r.sadd "foo", "s1"
|
29
|
+
r.sadd "foo", "s2"
|
30
|
+
r.sadd "bar", "s2"
|
31
|
+
|
32
|
+
r.sinterstore("baz", "foo", "bar")
|
33
|
+
|
34
|
+
assert ["s2"] == r.smembers("baz")
|
35
|
+
end
|
36
|
+
|
37
|
+
test "SUNION" do |r|
|
38
|
+
r.sadd "foo", "s1"
|
39
|
+
r.sadd "foo", "s2"
|
40
|
+
r.sadd "bar", "s2"
|
41
|
+
r.sadd "bar", "s3"
|
42
|
+
|
43
|
+
assert ["s1", "s2", "s3"] == r.sunion("foo", "bar").sort
|
44
|
+
end
|
45
|
+
|
46
|
+
test "SUNIONSTORE" do |r|
|
47
|
+
r.sadd "foo", "s1"
|
48
|
+
r.sadd "foo", "s2"
|
49
|
+
r.sadd "bar", "s2"
|
50
|
+
r.sadd "bar", "s3"
|
51
|
+
|
52
|
+
r.sunionstore("baz", "foo", "bar")
|
53
|
+
|
54
|
+
assert ["s1", "s2", "s3"] == r.smembers("baz").sort
|
55
|
+
end
|
56
|
+
|
57
|
+
test "SDIFF" do |r|
|
58
|
+
r.sadd "foo", "s1"
|
59
|
+
r.sadd "foo", "s2"
|
60
|
+
r.sadd "bar", "s2"
|
61
|
+
r.sadd "bar", "s3"
|
62
|
+
|
63
|
+
assert ["s1"] == r.sdiff("foo", "bar")
|
64
|
+
assert ["s3"] == r.sdiff("bar", "foo")
|
65
|
+
end
|
66
|
+
|
67
|
+
test "SDIFFSTORE" do |r|
|
68
|
+
r.sadd "foo", "s1"
|
69
|
+
r.sadd "foo", "s2"
|
70
|
+
r.sadd "bar", "s2"
|
71
|
+
r.sadd "bar", "s3"
|
72
|
+
|
73
|
+
r.sdiffstore("baz", "foo", "bar")
|
74
|
+
|
75
|
+
assert ["s1"] == r.smembers("baz")
|
76
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path("./helper", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
setup do
|
6
|
+
init Redis.new(OPTIONS)
|
7
|
+
end
|
8
|
+
|
9
|
+
load './test/lint/sorted_sets.rb'
|
10
|
+
|
11
|
+
test "ZCOUNT" do |r|
|
12
|
+
r.zadd "foo", 1, "s1"
|
13
|
+
r.zadd "foo", 2, "s2"
|
14
|
+
r.zadd "foo", 3, "s3"
|
15
|
+
|
16
|
+
assert 2 == r.zcount("foo", 2, 3)
|
17
|
+
end
|
18
|
+
|
19
|
+
test "ZUNIONSTORE" do |r|
|
20
|
+
r.zadd "foo", 1, "s1"
|
21
|
+
r.zadd "bar", 2, "s2"
|
22
|
+
r.zadd "foo", 3, "s3"
|
23
|
+
r.zadd "bar", 4, "s4"
|
24
|
+
|
25
|
+
assert 4 == r.zunionstore("foobar", ["foo", "bar"])
|
26
|
+
assert ["s1", "s2", "s3", "s4"] == r.zrange("foobar", 0, -1)
|
27
|
+
end
|
28
|
+
|
29
|
+
test "ZUNIONSTORE with WEIGHTS" do |r|
|
30
|
+
r.zadd "foo", 1, "s1"
|
31
|
+
r.zadd "foo", 3, "s3"
|
32
|
+
r.zadd "bar", 20, "s2"
|
33
|
+
r.zadd "bar", 40, "s4"
|
34
|
+
|
35
|
+
assert 4 == r.zunionstore("foobar", ["foo", "bar"])
|
36
|
+
assert ["s1", "s3", "s2", "s4"] == r.zrange("foobar", 0, -1)
|
37
|
+
|
38
|
+
assert 4 == r.zunionstore("foobar", ["foo", "bar"], :weights => [10, 1])
|
39
|
+
assert ["s1", "s2", "s3", "s4"] == r.zrange("foobar", 0, -1)
|
40
|
+
end
|
41
|
+
|
42
|
+
test "ZUNIONSTORE with AGGREGATE" do |r|
|
43
|
+
r.zadd "foo", 1, "s1"
|
44
|
+
r.zadd "foo", 2, "s2"
|
45
|
+
r.zadd "bar", 4, "s2"
|
46
|
+
r.zadd "bar", 3, "s3"
|
47
|
+
|
48
|
+
assert 3 == r.zunionstore("foobar", ["foo", "bar"])
|
49
|
+
assert ["s1", "s3", "s2"] == r.zrange("foobar", 0, -1)
|
50
|
+
|
51
|
+
assert 3 == r.zunionstore("foobar", ["foo", "bar"], :aggregate => :min)
|
52
|
+
assert ["s1", "s2", "s3"] == r.zrange("foobar", 0, -1)
|
53
|
+
|
54
|
+
assert 3 == r.zunionstore("foobar", ["foo", "bar"], :aggregate => :max)
|
55
|
+
assert ["s1", "s3", "s2"] == r.zrange("foobar", 0, -1)
|
56
|
+
end
|
57
|
+
|
58
|
+
test "ZINTERSTORE" do |r|
|
59
|
+
r.zadd "foo", 1, "s1"
|
60
|
+
r.zadd "bar", 2, "s1"
|
61
|
+
r.zadd "foo", 3, "s3"
|
62
|
+
r.zadd "bar", 4, "s4"
|
63
|
+
|
64
|
+
assert 1 == r.zinterstore("foobar", ["foo", "bar"])
|
65
|
+
assert ["s1"] == r.zrange("foobar", 0, -1)
|
66
|
+
end
|
67
|
+
|
68
|
+
test "ZINTERSTORE with WEIGHTS" do |r|
|
69
|
+
r.zadd "foo", 1, "s1"
|
70
|
+
r.zadd "foo", 2, "s2"
|
71
|
+
r.zadd "foo", 3, "s3"
|
72
|
+
r.zadd "bar", 20, "s2"
|
73
|
+
r.zadd "bar", 30, "s3"
|
74
|
+
r.zadd "bar", 40, "s4"
|
75
|
+
|
76
|
+
assert 2 == r.zinterstore("foobar", ["foo", "bar"])
|
77
|
+
assert ["s2", "s3"] == r.zrange("foobar", 0, -1)
|
78
|
+
|
79
|
+
assert 2 == r.zinterstore("foobar", ["foo", "bar"], :weights => [10, 1])
|
80
|
+
assert ["s2", "s3"] == r.zrange("foobar", 0, -1)
|
81
|
+
|
82
|
+
assert 40.0 == r.zscore("foobar", "s2")
|
83
|
+
assert 60.0 == r.zscore("foobar", "s3")
|
84
|
+
end
|
85
|
+
|
86
|
+
test "ZINTERSTORE with AGGREGATE" do |r|
|
87
|
+
r.zadd "foo", 1, "s1"
|
88
|
+
r.zadd "foo", 2, "s2"
|
89
|
+
r.zadd "foo", 3, "s3"
|
90
|
+
r.zadd "bar", 20, "s2"
|
91
|
+
r.zadd "bar", 30, "s3"
|
92
|
+
r.zadd "bar", 40, "s4"
|
93
|
+
|
94
|
+
assert 2 == r.zinterstore("foobar", ["foo", "bar"])
|
95
|
+
assert ["s2", "s3"] == r.zrange("foobar", 0, -1)
|
96
|
+
assert 22.0 == r.zscore("foobar", "s2")
|
97
|
+
assert 33.0 == r.zscore("foobar", "s3")
|
98
|
+
|
99
|
+
assert 2 == r.zinterstore("foobar", ["foo", "bar"], :aggregate => :min)
|
100
|
+
assert ["s2", "s3"] == r.zrange("foobar", 0, -1)
|
101
|
+
assert 2.0 == r.zscore("foobar", "s2")
|
102
|
+
assert 3.0 == r.zscore("foobar", "s3")
|
103
|
+
|
104
|
+
assert 2 == r.zinterstore("foobar", ["foo", "bar"], :aggregate => :max)
|
105
|
+
assert ["s2", "s3"] == r.zrange("foobar", 0, -1)
|
106
|
+
assert 20.0 == r.zscore("foobar", "s2")
|
107
|
+
assert 30.0 == r.zscore("foobar", "s3")
|
108
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path("./helper", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
setup do
|
6
|
+
init Redis.new(OPTIONS)
|
7
|
+
end
|
8
|
+
|
9
|
+
load './test/lint/strings.rb'
|
10
|
+
|
11
|
+
test "MGET" do |r|
|
12
|
+
r.set("foo", "s1")
|
13
|
+
r.set("bar", "s2")
|
14
|
+
|
15
|
+
assert ["s1", "s2"] == r.mget("foo", "bar")
|
16
|
+
assert ["s1", "s2", nil] == r.mget("foo", "bar", "baz")
|
17
|
+
end
|
18
|
+
|
19
|
+
test "MGET mapped" do |r|
|
20
|
+
r.set("foo", "s1")
|
21
|
+
r.set("bar", "s2")
|
22
|
+
|
23
|
+
response = r.mapped_mget("foo", "bar")
|
24
|
+
|
25
|
+
assert "s1" == response["foo"]
|
26
|
+
assert "s2" == response["bar"]
|
27
|
+
|
28
|
+
response = r.mapped_mget("foo", "bar", "baz")
|
29
|
+
|
30
|
+
assert "s1" == response["foo"]
|
31
|
+
assert "s2" == response["bar"]
|
32
|
+
assert nil == response["baz"]
|
33
|
+
end
|
34
|
+
|
35
|
+
test "Mapped MGET in a pipeline returns hash" do |r|
|
36
|
+
r.set("foo", "s1")
|
37
|
+
r.set("bar", "s2")
|
38
|
+
|
39
|
+
result = r.pipelined do
|
40
|
+
r.mapped_mget("foo", "bar")
|
41
|
+
end
|
42
|
+
|
43
|
+
assert result[0] == { "foo" => "s1", "bar" => "s2" }
|
44
|
+
end
|
45
|
+
|
46
|
+
test "MSET" do |r|
|
47
|
+
r.mset(:foo, "s1", :bar, "s2")
|
48
|
+
|
49
|
+
assert "s1" == r.get("foo")
|
50
|
+
assert "s2" == r.get("bar")
|
51
|
+
end
|
52
|
+
|
53
|
+
test "MSET mapped" do |r|
|
54
|
+
r.mapped_mset(:foo => "s1", :bar => "s2")
|
55
|
+
|
56
|
+
assert "s1" == r.get("foo")
|
57
|
+
assert "s2" == r.get("bar")
|
58
|
+
end
|
59
|
+
|
60
|
+
test "MSETNX" do |r|
|
61
|
+
r.set("foo", "s1")
|
62
|
+
r.msetnx(:foo, "s2", :bar, "s3")
|
63
|
+
|
64
|
+
assert "s1" == r.get("foo")
|
65
|
+
assert nil == r.get("bar")
|
66
|
+
end
|
67
|
+
|
68
|
+
test "MSETNX mapped" do |r|
|
69
|
+
r.set("foo", "s1")
|
70
|
+
r.mapped_msetnx(:foo => "s2", :bar => "s3")
|
71
|
+
|
72
|
+
assert "s1" == r.get("foo")
|
73
|
+
assert nil == r.get("bar")
|
74
|
+
end
|
75
|
+
|
76
|
+
test "STRLEN" do |r|
|
77
|
+
r.set "foo", "lorem"
|
78
|
+
|
79
|
+
assert 5 == r.strlen("foo")
|
80
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require File.expand_path("./helper", File.dirname(__FILE__))
|
4
|
+
require File.expand_path("./redis_mock", File.dirname(__FILE__))
|
5
|
+
|
6
|
+
include RedisMock::Helper
|
7
|
+
|
8
|
+
setup do
|
9
|
+
init Redis.new(OPTIONS)
|
10
|
+
end
|
11
|
+
|
12
|
+
load "./test/lint/value_types.rb"
|
13
|
+
|
14
|
+
test "DEL" do |r|
|
15
|
+
r.set "foo", "s1"
|
16
|
+
r.set "bar", "s2"
|
17
|
+
r.set "baz", "s3"
|
18
|
+
|
19
|
+
assert ["bar", "baz", "foo"] == r.keys("*").sort
|
20
|
+
|
21
|
+
assert 1 == r.del("foo")
|
22
|
+
|
23
|
+
assert ["bar", "baz"] == r.keys("*").sort
|
24
|
+
|
25
|
+
assert 2 == r.del("bar", "baz")
|
26
|
+
|
27
|
+
assert [] == r.keys("*").sort
|
28
|
+
end
|
29
|
+
|
30
|
+
test "RANDOMKEY" do |r|
|
31
|
+
assert r.randomkey.to_s.empty?
|
32
|
+
|
33
|
+
r.set("foo", "s1")
|
34
|
+
|
35
|
+
assert "foo" == r.randomkey
|
36
|
+
|
37
|
+
r.set("bar", "s2")
|
38
|
+
|
39
|
+
4.times do
|
40
|
+
assert ["foo", "bar"].include?(r.randomkey)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
test "RENAME" do |r|
|
45
|
+
r.set("foo", "s1")
|
46
|
+
r.rename "foo", "bar"
|
47
|
+
|
48
|
+
assert "s1" == r.get("bar")
|
49
|
+
assert nil == r.get("foo")
|
50
|
+
end
|
51
|
+
|
52
|
+
test "RENAMENX" do |r|
|
53
|
+
r.set("foo", "s1")
|
54
|
+
r.set("bar", "s2")
|
55
|
+
|
56
|
+
assert false == r.renamenx("foo", "bar")
|
57
|
+
|
58
|
+
assert "s1" == r.get("foo")
|
59
|
+
assert "s2" == r.get("bar")
|
60
|
+
end
|
61
|
+
|
62
|
+
test "DBSIZE" do |r|
|
63
|
+
assert 0 == r.dbsize
|
64
|
+
|
65
|
+
r.set("foo", "s1")
|
66
|
+
|
67
|
+
assert 1 == r.dbsize
|
68
|
+
end
|
69
|
+
|
70
|
+
test "FLUSHDB" do |r|
|
71
|
+
r.set("foo", "s1")
|
72
|
+
r.set("bar", "s2")
|
73
|
+
|
74
|
+
assert 2 == r.dbsize
|
75
|
+
|
76
|
+
r.flushdb
|
77
|
+
|
78
|
+
assert 0 == r.dbsize
|
79
|
+
end
|
80
|
+
|
81
|
+
test "FLUSHALL" do
|
82
|
+
redis_mock(:flushall => lambda { "+FLUSHALL" }) do
|
83
|
+
redis = Redis.new(OPTIONS.merge(:port => 6380))
|
84
|
+
|
85
|
+
assert "FLUSHALL" == redis.flushall
|
86
|
+
end
|
87
|
+
end
|