forked from redis/redis-rb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistributed_scripting_test.rb
102 lines (82 loc) · 2.93 KB
/
distributed_scripting_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# encoding: UTF-8
require File.expand_path("helper", File.dirname(__FILE__))
class TestDistributedScripting < Test::Unit::TestCase
include Helper::Distributed
def to_sha(script)
r.script(:load, script).first
end
def test_script_exists
target_version "2.5.9" do # 2.6-rc1
a = to_sha("return 1")
b = a.succ
assert_equal [true], r.script(:exists, a)
assert_equal [false], r.script(:exists, b)
assert_equal [[true]], r.script(:exists, [a])
assert_equal [[false]], r.script(:exists, [b])
assert_equal [[true, false]], r.script(:exists, [a, b])
end
end
def test_script_flush
target_version "2.5.9" do # 2.6-rc1
sha = to_sha("return 1")
assert r.script(:exists, sha).first
assert_equal ["OK"], r.script(:flush)
assert !r.script(:exists, sha).first
end
end
def test_script_kill
target_version "2.5.9" do # 2.6-rc1
redis_mock(:script => lambda { |arg| "+#{arg.upcase}" }) do |redis|
assert_equal ["KILL"], redis.script(:kill)
end
end
end
def test_eval
target_version "2.5.9" do # 2.6-rc1
assert_raises(Redis::Distributed::CannotDistribute) do
r.eval("return #KEYS")
end
assert_raises(Redis::Distributed::CannotDistribute) do
r.eval("return KEYS", ["k1", "k2"])
end
assert_equal ["k1"], r.eval("return KEYS", ["k1"])
assert_equal ["a1", "a2"], r.eval("return ARGV", ["k1"], ["a1", "a2"])
end
end
def test_eval_with_options_hash
target_version "2.5.9" do # 2.6-rc1
assert_raises(Redis::Distributed::CannotDistribute) do
r.eval("return #KEYS", {})
end
assert_raises(Redis::Distributed::CannotDistribute) do
r.eval("return KEYS", { :keys => ["k1", "k2"] })
end
assert_equal ["k1"], r.eval("return KEYS", { :keys => ["k1"] })
assert_equal ["a1", "a2"], r.eval("return ARGV", { :keys => ["k1"], :argv => ["a1", "a2"] })
end
end
def test_evalsha
target_version "2.5.9" do # 2.6-rc1
assert_raises(Redis::Distributed::CannotDistribute) do
r.evalsha(to_sha("return #KEYS"))
end
assert_raises(Redis::Distributed::CannotDistribute) do
r.evalsha(to_sha("return KEYS"), ["k1", "k2"])
end
assert_equal ["k1"], r.evalsha(to_sha("return KEYS"), ["k1"])
assert_equal ["a1", "a2"], r.evalsha(to_sha("return ARGV"), ["k1"], ["a1", "a2"])
end
end
def test_evalsha_with_options_hash
target_version "2.5.9" do # 2.6-rc1
assert_raises(Redis::Distributed::CannotDistribute) do
r.evalsha(to_sha("return #KEYS"), {})
end
assert_raises(Redis::Distributed::CannotDistribute) do
r.evalsha(to_sha("return KEYS"), { :keys => ["k1", "k2"] })
end
assert_equal ["k1"], r.evalsha(to_sha("return KEYS"), { :keys => ["k1"] })
assert_equal ["a1", "a2"], r.evalsha(to_sha("return ARGV"), { :keys => ["k1"], :argv => ["a1", "a2"] })
end
end
end