]>
Commit | Line | Data |
---|---|---|
1 | start_server {tags {"dump"}} { | |
2 | test {DUMP / RESTORE are able to serialize / unserialize a simple key} { | |
3 | r set foo bar | |
4 | set encoded [r dump foo] | |
5 | r del foo | |
6 | list [r exists foo] [r restore foo 0 $encoded] [r ttl foo] [r get foo] | |
7 | } {0 OK -1 bar} | |
8 | ||
9 | test {RESTORE can set an arbitrary expire to the materialized key} { | |
10 | r set foo bar | |
11 | set encoded [r dump foo] | |
12 | r del foo | |
13 | r restore foo 5000 $encoded | |
14 | set ttl [r pttl foo] | |
15 | assert {$ttl >= 3000 && $ttl <= 5000} | |
16 | r get foo | |
17 | } {bar} | |
18 | ||
19 | test {RESTORE returns an error of the key already exists} { | |
20 | r set foo bar | |
21 | set e {} | |
22 | catch {r restore foo 0 "..."} e | |
23 | set e | |
24 | } {*is busy*} | |
25 | ||
26 | test {DUMP of non existing key returns nil} { | |
27 | r dump nonexisting_key | |
28 | } {} | |
29 | ||
30 | test {MIGRATE is able to migrate a key between two instances} { | |
31 | set first [srv 0 client] | |
32 | r set key "Some Value" | |
33 | start_server {tags {"repl"}} { | |
34 | set second [srv 0 client] | |
35 | set second_host [srv 0 host] | |
36 | set second_port [srv 0 port] | |
37 | ||
38 | assert {[$first exists key] == 1} | |
39 | assert {[$second exists key] == 0} | |
40 | set ret [r -1 migrate $second_host $second_port key 9 5000] | |
41 | assert {$ret eq {OK}} | |
42 | assert {[$first exists key] == 0} | |
43 | assert {[$second exists key] == 1} | |
44 | assert {[$second get key] eq {Some Value}} | |
45 | assert {[$second ttl key] == -1} | |
46 | } | |
47 | } | |
48 | ||
49 | test {MIGRATE propagates TTL correctly} { | |
50 | set first [srv 0 client] | |
51 | r set key "Some Value" | |
52 | start_server {tags {"repl"}} { | |
53 | set second [srv 0 client] | |
54 | set second_host [srv 0 host] | |
55 | set second_port [srv 0 port] | |
56 | ||
57 | assert {[$first exists key] == 1} | |
58 | assert {[$second exists key] == 0} | |
59 | $first expire key 10 | |
60 | set ret [r -1 migrate $second_host $second_port key 9 5000] | |
61 | assert {$ret eq {OK}} | |
62 | assert {[$first exists key] == 0} | |
63 | assert {[$second exists key] == 1} | |
64 | assert {[$second get key] eq {Some Value}} | |
65 | assert {[$second ttl key] >= 7 && [$second ttl key] <= 10} | |
66 | } | |
67 | } | |
68 | ||
69 | test {MIGRATE can correctly transfer large values} { | |
70 | set first [srv 0 client] | |
71 | r del key | |
72 | for {set j 0} {$j < 5000} {incr j} { | |
73 | r rpush key 1 2 3 4 5 6 7 8 9 10 | |
74 | r rpush key "item 1" "item 2" "item 3" "item 4" "item 5" \ | |
75 | "item 6" "item 7" "item 8" "item 9" "item 10" | |
76 | } | |
77 | assert {[string length [r dump key]] > (1024*64)} | |
78 | start_server {tags {"repl"}} { | |
79 | set second [srv 0 client] | |
80 | set second_host [srv 0 host] | |
81 | set second_port [srv 0 port] | |
82 | ||
83 | assert {[$first exists key] == 1} | |
84 | assert {[$second exists key] == 0} | |
85 | set ret [r -1 migrate $second_host $second_port key 9 10000] | |
86 | assert {$ret eq {OK}} | |
87 | assert {[$first exists key] == 0} | |
88 | assert {[$second exists key] == 1} | |
89 | assert {[$second ttl key] == -1} | |
90 | assert {[$second llen key] == 5000*20} | |
91 | } | |
92 | } | |
93 | ||
94 | test {MIGRATE can correctly transfer hashes} { | |
95 | set first [srv 0 client] | |
96 | r del key | |
97 | r hmset key field1 "item 1" field2 "item 2" field3 "item 3" \ | |
98 | field4 "item 4" field5 "item 5" field6 "item 6" | |
99 | start_server {tags {"repl"}} { | |
100 | set second [srv 0 client] | |
101 | set second_host [srv 0 host] | |
102 | set second_port [srv 0 port] | |
103 | ||
104 | assert {[$first exists key] == 1} | |
105 | assert {[$second exists key] == 0} | |
106 | set ret [r -1 migrate $second_host $second_port key 9 10000] | |
107 | assert {$ret eq {OK}} | |
108 | assert {[$first exists key] == 0} | |
109 | assert {[$second exists key] == 1} | |
110 | assert {[$second ttl key] == -1} | |
111 | } | |
112 | } | |
113 | ||
114 | test {MIGRATE timeout actually works} { | |
115 | set first [srv 0 client] | |
116 | r set key "Some Value" | |
117 | start_server {tags {"repl"}} { | |
118 | set second [srv 0 client] | |
119 | set second_host [srv 0 host] | |
120 | set second_port [srv 0 port] | |
121 | ||
122 | assert {[$first exists key] == 1} | |
123 | assert {[$second exists key] == 0} | |
124 | ||
125 | set rd [redis_deferring_client] | |
126 | $rd debug sleep 5.0 ; # Make second server unable to reply. | |
127 | set e {} | |
128 | catch {r -1 migrate $second_host $second_port key 9 1000} e | |
129 | assert_match {IOERR*} $e | |
130 | } | |
131 | } | |
132 | } |