redis 3.0.0 → 4.5.0
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +315 -0
- data/README.md +301 -58
- data/lib/redis/client.rb +383 -88
- data/lib/redis/cluster/command.rb +81 -0
- data/lib/redis/cluster/command_loader.rb +33 -0
- data/lib/redis/cluster/key_slot_converter.rb +72 -0
- data/lib/redis/cluster/node.rb +108 -0
- data/lib/redis/cluster/node_key.rb +31 -0
- data/lib/redis/cluster/node_loader.rb +37 -0
- data/lib/redis/cluster/option.rb +93 -0
- data/lib/redis/cluster/slot.rb +86 -0
- data/lib/redis/cluster/slot_loader.rb +49 -0
- data/lib/redis/cluster.rb +291 -0
- data/lib/redis/connection/command_helper.rb +7 -10
- data/lib/redis/connection/hiredis.rb +12 -8
- data/lib/redis/connection/registry.rb +2 -1
- data/lib/redis/connection/ruby.rb +266 -74
- data/lib/redis/connection/synchrony.rb +41 -14
- data/lib/redis/connection.rb +4 -2
- data/lib/redis/distributed.rb +258 -76
- data/lib/redis/errors.rb +48 -0
- data/lib/redis/hash_ring.rb +31 -73
- data/lib/redis/pipeline.rb +74 -18
- data/lib/redis/subscribe.rb +24 -13
- data/lib/redis/version.rb +3 -1
- data/lib/redis.rb +2068 -464
- metadata +63 -160
- data/.gitignore +0 -10
- data/.order +0 -169
- data/.travis/Gemfile +0 -11
- data/.travis.yml +0 -50
- data/.yardopts +0 -3
- data/Rakefile +0 -392
- data/benchmarking/logging.rb +0 -62
- data/benchmarking/pipeline.rb +0 -51
- data/benchmarking/speed.rb +0 -21
- data/benchmarking/suite.rb +0 -24
- data/benchmarking/worker.rb +0 -71
- data/examples/basic.rb +0 -15
- data/examples/dist_redis.rb +0 -43
- data/examples/incr-decr.rb +0 -17
- data/examples/list.rb +0 -26
- data/examples/pubsub.rb +0 -31
- data/examples/sets.rb +0 -36
- data/examples/unicorn/config.ru +0 -3
- data/examples/unicorn/unicorn.rb +0 -20
- data/redis.gemspec +0 -41
- data/test/blocking_commands_test.rb +0 -42
- data/test/command_map_test.rb +0 -30
- data/test/commands_on_hashes_test.rb +0 -21
- data/test/commands_on_lists_test.rb +0 -20
- data/test/commands_on_sets_test.rb +0 -77
- data/test/commands_on_sorted_sets_test.rb +0 -109
- data/test/commands_on_strings_test.rb +0 -83
- data/test/commands_on_value_types_test.rb +0 -99
- data/test/connection_handling_test.rb +0 -189
- data/test/db/.gitignore +0 -1
- data/test/distributed_blocking_commands_test.rb +0 -46
- data/test/distributed_commands_on_hashes_test.rb +0 -10
- data/test/distributed_commands_on_lists_test.rb +0 -22
- data/test/distributed_commands_on_sets_test.rb +0 -83
- data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
- data/test/distributed_commands_on_strings_test.rb +0 -48
- data/test/distributed_commands_on_value_types_test.rb +0 -87
- data/test/distributed_commands_requiring_clustering_test.rb +0 -148
- data/test/distributed_connection_handling_test.rb +0 -23
- data/test/distributed_internals_test.rb +0 -15
- data/test/distributed_key_tags_test.rb +0 -52
- data/test/distributed_persistence_control_commands_test.rb +0 -26
- data/test/distributed_publish_subscribe_test.rb +0 -92
- data/test/distributed_remote_server_control_commands_test.rb +0 -53
- data/test/distributed_scripting_test.rb +0 -102
- data/test/distributed_sorting_test.rb +0 -20
- data/test/distributed_test.rb +0 -58
- data/test/distributed_transactions_test.rb +0 -32
- data/test/encoding_test.rb +0 -18
- data/test/error_replies_test.rb +0 -59
- data/test/helper.rb +0 -188
- data/test/helper_test.rb +0 -22
- data/test/internals_test.rb +0 -214
- data/test/lint/blocking_commands.rb +0 -124
- data/test/lint/hashes.rb +0 -162
- data/test/lint/lists.rb +0 -143
- data/test/lint/sets.rb +0 -96
- data/test/lint/sorted_sets.rb +0 -201
- data/test/lint/strings.rb +0 -157
- data/test/lint/value_types.rb +0 -106
- data/test/persistence_control_commands_test.rb +0 -26
- data/test/pipelining_commands_test.rb +0 -195
- data/test/publish_subscribe_test.rb +0 -153
- data/test/remote_server_control_commands_test.rb +0 -104
- data/test/scripting_test.rb +0 -78
- data/test/sorting_test.rb +0 -45
- data/test/support/connection/hiredis.rb +0 -1
- data/test/support/connection/ruby.rb +0 -1
- data/test/support/connection/synchrony.rb +0 -17
- data/test/support/redis_mock.rb +0 -92
- data/test/support/wire/synchrony.rb +0 -24
- data/test/support/wire/thread.rb +0 -5
- data/test/synchrony_driver.rb +0 -57
- data/test/test.conf +0 -9
- data/test/thread_safety_test.rb +0 -32
- data/test/transactions_test.rb +0 -244
- data/test/unknown_commands_test.rb +0 -14
- data/test/url_param_test.rb +0 -64
data/examples/list.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'redis'
|
3
|
-
|
4
|
-
r = Redis.new
|
5
|
-
|
6
|
-
r.del 'logs'
|
7
|
-
|
8
|
-
puts
|
9
|
-
|
10
|
-
p "pushing log messages into a LIST"
|
11
|
-
r.rpush 'logs', 'some log message'
|
12
|
-
r.rpush 'logs', 'another log message'
|
13
|
-
r.rpush 'logs', 'yet another log message'
|
14
|
-
r.rpush 'logs', 'also another log message'
|
15
|
-
|
16
|
-
puts
|
17
|
-
p 'contents of logs LIST'
|
18
|
-
|
19
|
-
p r.lrange('logs', 0, -1)
|
20
|
-
|
21
|
-
puts
|
22
|
-
p 'Trim logs LIST to last 2 elements(easy circular buffer)'
|
23
|
-
|
24
|
-
r.ltrim('logs', -2, -1)
|
25
|
-
|
26
|
-
p r.lrange('logs', 0, -1)
|
data/examples/pubsub.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require "redis"
|
2
|
-
|
3
|
-
puts <<-EOS
|
4
|
-
To play with this example use redis-cli from another terminal, like this:
|
5
|
-
|
6
|
-
$ redis-cli publish one hello
|
7
|
-
|
8
|
-
Finally force the example to exit sending the 'exit' message with:
|
9
|
-
|
10
|
-
$ redis-cli publish two exit
|
11
|
-
|
12
|
-
EOS
|
13
|
-
|
14
|
-
redis = Redis.new
|
15
|
-
|
16
|
-
trap(:INT) { puts; exit }
|
17
|
-
|
18
|
-
redis.subscribe(:one, :two) do |on|
|
19
|
-
on.subscribe do |channel, subscriptions|
|
20
|
-
puts "Subscribed to ##{channel} (#{subscriptions} subscriptions)"
|
21
|
-
end
|
22
|
-
|
23
|
-
on.message do |channel, message|
|
24
|
-
puts "##{channel}: #{message}"
|
25
|
-
redis.unsubscribe if message == "exit"
|
26
|
-
end
|
27
|
-
|
28
|
-
on.unsubscribe do |channel, subscriptions|
|
29
|
-
puts "Unsubscribed from ##{channel} (#{subscriptions} subscriptions)"
|
30
|
-
end
|
31
|
-
end
|
data/examples/sets.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'redis'
|
3
|
-
|
4
|
-
r = Redis.new
|
5
|
-
|
6
|
-
r.del 'foo-tags'
|
7
|
-
r.del 'bar-tags'
|
8
|
-
|
9
|
-
puts
|
10
|
-
p "create a set of tags on foo-tags"
|
11
|
-
|
12
|
-
r.sadd 'foo-tags', 'one'
|
13
|
-
r.sadd 'foo-tags', 'two'
|
14
|
-
r.sadd 'foo-tags', 'three'
|
15
|
-
|
16
|
-
puts
|
17
|
-
p "create a set of tags on bar-tags"
|
18
|
-
|
19
|
-
r.sadd 'bar-tags', 'three'
|
20
|
-
r.sadd 'bar-tags', 'four'
|
21
|
-
r.sadd 'bar-tags', 'five'
|
22
|
-
|
23
|
-
puts
|
24
|
-
p 'foo-tags'
|
25
|
-
|
26
|
-
p r.smembers('foo-tags')
|
27
|
-
|
28
|
-
puts
|
29
|
-
p 'bar-tags'
|
30
|
-
|
31
|
-
p r.smembers('bar-tags')
|
32
|
-
|
33
|
-
puts
|
34
|
-
p 'intersection of foo-tags and bar-tags'
|
35
|
-
|
36
|
-
p r.sinter('foo-tags', 'bar-tags')
|
data/examples/unicorn/config.ru
DELETED
data/examples/unicorn/unicorn.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require "redis"
|
2
|
-
|
3
|
-
worker_processes 3
|
4
|
-
|
5
|
-
# If you set the connection to Redis *before* forking,
|
6
|
-
# you will cause forks to share a file descriptor.
|
7
|
-
#
|
8
|
-
# This causes a concurrency problem by which one fork
|
9
|
-
# can read or write to the socket while others are
|
10
|
-
# performing other operations.
|
11
|
-
#
|
12
|
-
# Most likely you'll be getting ProtocolError exceptions
|
13
|
-
# mentioning a wrong initial byte in the reply.
|
14
|
-
#
|
15
|
-
# Thus we need to connect to Redis after forking the
|
16
|
-
# worker processes.
|
17
|
-
|
18
|
-
after_fork do |server, worker|
|
19
|
-
Redis.current.quit
|
20
|
-
end
|
data/redis.gemspec
DELETED
@@ -1,41 +0,0 @@
|
|
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 = "redis"
|
9
|
-
|
10
|
-
s.version = Redis::VERSION
|
11
|
-
|
12
|
-
s.homepage = "https://github.com/redis/redis-rb"
|
13
|
-
|
14
|
-
s.summary = "A Ruby client library for Redis"
|
15
|
-
|
16
|
-
s.description = <<-EOS
|
17
|
-
A Ruby client that tries to match Redis' API one-to-one, while still
|
18
|
-
providing an idiomatic interface. It features thread-safety,
|
19
|
-
client-side sharding, pipelining, and an obsession for performance.
|
20
|
-
EOS
|
21
|
-
|
22
|
-
s.authors = [
|
23
|
-
"Ezra Zygmuntowicz",
|
24
|
-
"Taylor Weibley",
|
25
|
-
"Matthew Clark",
|
26
|
-
"Brian McKinney",
|
27
|
-
"Salvatore Sanfilippo",
|
28
|
-
"Luca Guidi",
|
29
|
-
"Michel Martens",
|
30
|
-
"Damian Janowski",
|
31
|
-
"Pieter Noordhuis"
|
32
|
-
]
|
33
|
-
|
34
|
-
s.email = ["redis-db@googlegroups.com"]
|
35
|
-
|
36
|
-
s.files = `git ls-files`.split("\n")
|
37
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
38
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
39
|
-
|
40
|
-
s.add_development_dependency("rake")
|
41
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require "helper"
|
4
|
-
require "lint/blocking_commands"
|
5
|
-
|
6
|
-
class TestBlockingCommands < Test::Unit::TestCase
|
7
|
-
|
8
|
-
include Helper::Client
|
9
|
-
include Lint::BlockingCommands
|
10
|
-
|
11
|
-
def assert_takes_longer_than_client_timeout
|
12
|
-
timeout = OPTIONS[:timeout]
|
13
|
-
delay = timeout * 2
|
14
|
-
|
15
|
-
mock(:delay => delay) do |r|
|
16
|
-
t1 = Time.now
|
17
|
-
yield(r)
|
18
|
-
t2 = Time.now
|
19
|
-
|
20
|
-
assert timeout == r.client.timeout
|
21
|
-
assert delay <= (t2 - t1)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_blpop_disable_client_timeout
|
26
|
-
assert_takes_longer_than_client_timeout do |r|
|
27
|
-
assert_equal ["foo", "0"], r.blpop("foo")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_brpop_disable_client_timeout
|
32
|
-
assert_takes_longer_than_client_timeout do |r|
|
33
|
-
assert_equal ["foo", "0"], r.brpop("foo")
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_brpoplpush_disable_client_timeout
|
38
|
-
assert_takes_longer_than_client_timeout do |r|
|
39
|
-
assert_equal "0", r.brpoplpush("foo", "bar")
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
data/test/command_map_test.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require "helper"
|
4
|
-
|
5
|
-
class TestCommandMap < Test::Unit::TestCase
|
6
|
-
|
7
|
-
include Helper::Client
|
8
|
-
|
9
|
-
def test_override_existing_commands
|
10
|
-
r.set("counter", 1)
|
11
|
-
|
12
|
-
assert_equal 2, r.incr("counter")
|
13
|
-
|
14
|
-
r.client.command_map[:incr] = :decr
|
15
|
-
|
16
|
-
assert_equal 1, r.incr("counter")
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_override_non_existing_commands
|
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_equal "value", r.idontexist("key")
|
29
|
-
end
|
30
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require "helper"
|
4
|
-
require "lint/hashes"
|
5
|
-
|
6
|
-
class TestCommandsOnHashes < Test::Unit::TestCase
|
7
|
-
|
8
|
-
include Helper::Client
|
9
|
-
include Lint::Hashes
|
10
|
-
|
11
|
-
def test_mapped_hmget_in_a_pipeline_returns_hash
|
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_equal result[0], { "f1" => "s1", "f2" => "s2" }
|
20
|
-
end
|
21
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require "helper"
|
4
|
-
require "lint/lists"
|
5
|
-
|
6
|
-
class TestCommandsOnLists < Test::Unit::TestCase
|
7
|
-
|
8
|
-
include Helper::Client
|
9
|
-
include Lint::Lists
|
10
|
-
|
11
|
-
def test_rpoplpush
|
12
|
-
r.rpush "foo", "s1"
|
13
|
-
r.rpush "foo", "s2"
|
14
|
-
|
15
|
-
assert_equal "s2", r.rpoplpush("foo", "bar")
|
16
|
-
assert_equal ["s2"], r.lrange("bar", 0, -1)
|
17
|
-
assert_equal "s1", r.rpoplpush("foo", "bar")
|
18
|
-
assert_equal ["s1", "s2"], r.lrange("bar", 0, -1)
|
19
|
-
end
|
20
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require "helper"
|
4
|
-
require "lint/sets"
|
5
|
-
|
6
|
-
class TestCommandsOnSets < Test::Unit::TestCase
|
7
|
-
|
8
|
-
include Helper::Client
|
9
|
-
include Lint::Sets
|
10
|
-
|
11
|
-
def test_smove
|
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
|
-
def test_sinter
|
20
|
-
r.sadd "foo", "s1"
|
21
|
-
r.sadd "foo", "s2"
|
22
|
-
r.sadd "bar", "s2"
|
23
|
-
|
24
|
-
assert_equal ["s2"], r.sinter("foo", "bar")
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_sinterstore
|
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_equal ["s2"], r.smembers("baz")
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_sunion
|
38
|
-
r.sadd "foo", "s1"
|
39
|
-
r.sadd "foo", "s2"
|
40
|
-
r.sadd "bar", "s2"
|
41
|
-
r.sadd "bar", "s3"
|
42
|
-
|
43
|
-
assert_equal ["s1", "s2", "s3"], r.sunion("foo", "bar").sort
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_sunionstore
|
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_equal ["s1", "s2", "s3"], r.smembers("baz").sort
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_sdiff
|
58
|
-
r.sadd "foo", "s1"
|
59
|
-
r.sadd "foo", "s2"
|
60
|
-
r.sadd "bar", "s2"
|
61
|
-
r.sadd "bar", "s3"
|
62
|
-
|
63
|
-
assert_equal ["s1"], r.sdiff("foo", "bar")
|
64
|
-
assert_equal ["s3"], r.sdiff("bar", "foo")
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_sdiffstore
|
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_equal ["s1"], r.smembers("baz")
|
76
|
-
end
|
77
|
-
end
|
@@ -1,109 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require "helper"
|
4
|
-
require "lint/sorted_sets"
|
5
|
-
|
6
|
-
class TestCommandsOnSortedSets < Test::Unit::TestCase
|
7
|
-
|
8
|
-
include Helper::Client
|
9
|
-
include Lint::SortedSets
|
10
|
-
|
11
|
-
def test_zcount
|
12
|
-
r.zadd "foo", 1, "s1"
|
13
|
-
r.zadd "foo", 2, "s2"
|
14
|
-
r.zadd "foo", 3, "s3"
|
15
|
-
|
16
|
-
assert_equal 2, r.zcount("foo", 2, 3)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_zunionstore
|
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_equal 4, r.zunionstore("foobar", ["foo", "bar"])
|
26
|
-
assert_equal ["s1", "s2", "s3", "s4"], r.zrange("foobar", 0, -1)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_zunionstore_with_weights
|
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_equal 4, r.zunionstore("foobar", ["foo", "bar"])
|
36
|
-
assert_equal ["s1", "s3", "s2", "s4"], r.zrange("foobar", 0, -1)
|
37
|
-
|
38
|
-
assert_equal 4, r.zunionstore("foobar", ["foo", "bar"], :weights => [10, 1])
|
39
|
-
assert_equal ["s1", "s2", "s3", "s4"], r.zrange("foobar", 0, -1)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_zunionstore_with_aggregate
|
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_equal 3, r.zunionstore("foobar", ["foo", "bar"])
|
49
|
-
assert_equal ["s1", "s3", "s2"], r.zrange("foobar", 0, -1)
|
50
|
-
|
51
|
-
assert_equal 3, r.zunionstore("foobar", ["foo", "bar"], :aggregate => :min)
|
52
|
-
assert_equal ["s1", "s2", "s3"], r.zrange("foobar", 0, -1)
|
53
|
-
|
54
|
-
assert_equal 3, r.zunionstore("foobar", ["foo", "bar"], :aggregate => :max)
|
55
|
-
assert_equal ["s1", "s3", "s2"], r.zrange("foobar", 0, -1)
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_zinterstore
|
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_equal 1, r.zinterstore("foobar", ["foo", "bar"])
|
65
|
-
assert_equal ["s1"], r.zrange("foobar", 0, -1)
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_zinterstore_with_weights
|
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_equal 2, r.zinterstore("foobar", ["foo", "bar"])
|
77
|
-
assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
|
78
|
-
|
79
|
-
assert_equal 2, r.zinterstore("foobar", ["foo", "bar"], :weights => [10, 1])
|
80
|
-
assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
|
81
|
-
|
82
|
-
assert_equal 40.0, r.zscore("foobar", "s2")
|
83
|
-
assert_equal 60.0, r.zscore("foobar", "s3")
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_zinterstore_with_aggregate
|
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_equal 2, r.zinterstore("foobar", ["foo", "bar"])
|
95
|
-
assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
|
96
|
-
assert_equal 22.0, r.zscore("foobar", "s2")
|
97
|
-
assert_equal 33.0, r.zscore("foobar", "s3")
|
98
|
-
|
99
|
-
assert_equal 2, r.zinterstore("foobar", ["foo", "bar"], :aggregate => :min)
|
100
|
-
assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
|
101
|
-
assert_equal 2.0, r.zscore("foobar", "s2")
|
102
|
-
assert_equal 3.0, r.zscore("foobar", "s3")
|
103
|
-
|
104
|
-
assert_equal 2, r.zinterstore("foobar", ["foo", "bar"], :aggregate => :max)
|
105
|
-
assert_equal ["s2", "s3"], r.zrange("foobar", 0, -1)
|
106
|
-
assert_equal 20.0, r.zscore("foobar", "s2")
|
107
|
-
assert_equal 30.0, r.zscore("foobar", "s3")
|
108
|
-
end
|
109
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require "helper"
|
4
|
-
require "lint/strings"
|
5
|
-
|
6
|
-
class TestCommandsOnStrings < Test::Unit::TestCase
|
7
|
-
|
8
|
-
include Helper::Client
|
9
|
-
include Lint::Strings
|
10
|
-
|
11
|
-
def test_mget
|
12
|
-
r.set("foo", "s1")
|
13
|
-
r.set("bar", "s2")
|
14
|
-
|
15
|
-
assert_equal ["s1", "s2"] , r.mget("foo", "bar")
|
16
|
-
assert_equal ["s1", "s2", nil], r.mget("foo", "bar", "baz")
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_mget_mapped
|
20
|
-
r.set("foo", "s1")
|
21
|
-
r.set("bar", "s2")
|
22
|
-
|
23
|
-
response = r.mapped_mget("foo", "bar")
|
24
|
-
|
25
|
-
assert_equal "s1", response["foo"]
|
26
|
-
assert_equal "s2", response["bar"]
|
27
|
-
|
28
|
-
response = r.mapped_mget("foo", "bar", "baz")
|
29
|
-
|
30
|
-
assert_equal "s1", response["foo"]
|
31
|
-
assert_equal "s2", response["bar"]
|
32
|
-
assert_equal nil , response["baz"]
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_mapped_mget_in_a_pipeline_returns_hash
|
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_equal result[0], { "foo" => "s1", "bar" => "s2" }
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_mset
|
47
|
-
r.mset(:foo, "s1", :bar, "s2")
|
48
|
-
|
49
|
-
assert_equal "s1", r.get("foo")
|
50
|
-
assert_equal "s2", r.get("bar")
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_mset_mapped
|
54
|
-
r.mapped_mset(:foo => "s1", :bar => "s2")
|
55
|
-
|
56
|
-
assert_equal "s1", r.get("foo")
|
57
|
-
assert_equal "s2", r.get("bar")
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_msetnx
|
61
|
-
r.set("foo", "s1")
|
62
|
-
assert_equal false, r.msetnx(:foo, "s2", :bar, "s3")
|
63
|
-
assert_equal "s1", r.get("foo")
|
64
|
-
assert_equal nil, r.get("bar")
|
65
|
-
|
66
|
-
r.del("foo")
|
67
|
-
assert_equal true, r.msetnx(:foo, "s2", :bar, "s3")
|
68
|
-
assert_equal "s2", r.get("foo")
|
69
|
-
assert_equal "s3", r.get("bar")
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_msetnx_mapped
|
73
|
-
r.set("foo", "s1")
|
74
|
-
assert_equal false, r.mapped_msetnx(:foo => "s2", :bar => "s3")
|
75
|
-
assert_equal "s1", r.get("foo")
|
76
|
-
assert_equal nil, r.get("bar")
|
77
|
-
|
78
|
-
r.del("foo")
|
79
|
-
assert_equal true, r.mapped_msetnx(:foo => "s2", :bar => "s3")
|
80
|
-
assert_equal "s2", r.get("foo")
|
81
|
-
assert_equal "s3", r.get("bar")
|
82
|
-
end
|
83
|
-
end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require "helper"
|
4
|
-
require "lint/value_types"
|
5
|
-
|
6
|
-
class TestCommandsOnValueTypes < Test::Unit::TestCase
|
7
|
-
|
8
|
-
include Helper::Client
|
9
|
-
include Lint::ValueTypes
|
10
|
-
|
11
|
-
def test_del
|
12
|
-
r.set "foo", "s1"
|
13
|
-
r.set "bar", "s2"
|
14
|
-
r.set "baz", "s3"
|
15
|
-
|
16
|
-
assert_equal ["bar", "baz", "foo"], r.keys("*").sort
|
17
|
-
|
18
|
-
assert_equal 1, r.del("foo")
|
19
|
-
|
20
|
-
assert_equal ["bar", "baz"], r.keys("*").sort
|
21
|
-
|
22
|
-
assert_equal 2, r.del("bar", "baz")
|
23
|
-
|
24
|
-
assert_equal [], r.keys("*").sort
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_del_with_array_argument
|
28
|
-
r.set "foo", "s1"
|
29
|
-
r.set "bar", "s2"
|
30
|
-
r.set "baz", "s3"
|
31
|
-
|
32
|
-
assert_equal ["bar", "baz", "foo"], r.keys("*").sort
|
33
|
-
|
34
|
-
assert_equal 1, r.del(["foo"])
|
35
|
-
|
36
|
-
assert_equal ["bar", "baz"], r.keys("*").sort
|
37
|
-
|
38
|
-
assert_equal 2, r.del(["bar", "baz"])
|
39
|
-
|
40
|
-
assert_equal [], r.keys("*").sort
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_randomkey
|
44
|
-
assert r.randomkey.to_s.empty?
|
45
|
-
|
46
|
-
r.set("foo", "s1")
|
47
|
-
|
48
|
-
assert_equal "foo", r.randomkey
|
49
|
-
|
50
|
-
r.set("bar", "s2")
|
51
|
-
|
52
|
-
4.times do
|
53
|
-
assert ["foo", "bar"].include?(r.randomkey)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_rename
|
58
|
-
r.set("foo", "s1")
|
59
|
-
r.rename "foo", "bar"
|
60
|
-
|
61
|
-
assert_equal "s1", r.get("bar")
|
62
|
-
assert_equal nil, r.get("foo")
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_renamenx
|
66
|
-
r.set("foo", "s1")
|
67
|
-
r.set("bar", "s2")
|
68
|
-
|
69
|
-
assert_equal false, r.renamenx("foo", "bar")
|
70
|
-
|
71
|
-
assert_equal "s1", r.get("foo")
|
72
|
-
assert_equal "s2", r.get("bar")
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_dbsize
|
76
|
-
assert_equal 0, r.dbsize
|
77
|
-
|
78
|
-
r.set("foo", "s1")
|
79
|
-
|
80
|
-
assert_equal 1, r.dbsize
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_flushdb
|
84
|
-
r.set("foo", "s1")
|
85
|
-
r.set("bar", "s2")
|
86
|
-
|
87
|
-
assert_equal 2, r.dbsize
|
88
|
-
|
89
|
-
r.flushdb
|
90
|
-
|
91
|
-
assert_equal 0, r.dbsize
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_flushall
|
95
|
-
redis_mock(:flushall => lambda { "+FLUSHALL" }) do |redis|
|
96
|
-
assert_equal "FLUSHALL", redis.flushall
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|