1 start_server
{tags
{"dump"}} {
2 test
{DUMP
/ RESTORE are able to serialize
/ unserialize a simple key
} {
4 set encoded
[r dump foo
]
6 list [r exists foo
] [r restore foo
0 $encoded] [r ttl foo
] [r get foo
]
9 test
{RESTORE can
set an arbitrary expire to the materialized key
} {
11 set encoded
[r dump foo
]
13 r restore foo
5000 $encoded
15 assert
{$ttl >= 3000 && $ttl <= 5000}
19 test
{RESTORE returns an
error of the key already exists
} {
22 catch {r restore foo
0 "..."} e
26 test
{RESTORE can overwrite an existing key with REPLACE
} {
28 set encoded1
[r dump foo
]
30 set encoded2
[r dump foo
]
32 r restore foo
0 $encoded1
33 r restore foo
0 $encoded2 replace
37 test
{RESTORE can detect a syntax
error for unrecongized
options} {
38 catch {r restore foo
0 "..." invalid-option
} e
42 test
{DUMP of non existing key returns nil
} {
43 r dump nonexisting_key
46 test
{MIGRATE is able to migrate a key between two instances
} {
47 set first
[srv
0 client
]
48 r
set key
"Some Value"
49 start_server
{tags
{"repl"}} {
50 set second
[srv
0 client
]
51 set second_host
[srv
0 host
]
52 set second_port
[srv
0 port
]
54 assert
{[$first exists key
] == 1}
55 assert
{[$second exists key
] == 0}
56 set ret
[r
-1 migrate
$second_host $second_port key
9 5000]
58 assert
{[$first exists key
] == 0}
59 assert
{[$second exists key
] == 1}
60 assert
{[$second get key
] eq
{Some Value
}}
61 assert
{[$second ttl key
] == -1}
65 test
{MIGRATE is able to copy a key between two instances
} {
66 set first
[srv
0 client
]
69 start_server
{tags
{"repl"}} {
70 set second
[srv
0 client
]
71 set second_host
[srv
0 host
]
72 set second_port
[srv
0 port
]
74 assert
{[$first exists
list] == 1}
75 assert
{[$second exists
list] == 0}
76 set ret
[r
-1 migrate
$second_host $second_port list 9 5000 copy
]
78 assert
{[$first exists
list] == 1}
79 assert
{[$second exists
list] == 1}
80 assert
{[$first lrange list 0 -1] eq
[$second lrange list 0 -1]}
84 test
{MIGRATE will not overwrite existing keys
, unless REPLACE is used
} {
85 set first
[srv
0 client
]
88 start_server
{tags
{"repl"}} {
89 set second
[srv
0 client
]
90 set second_host
[srv
0 host
]
91 set second_port
[srv
0 port
]
93 assert
{[$first exists
list] == 1}
94 assert
{[$second exists
list] == 0}
95 $second set list somevalue
96 catch {r
-1 migrate
$second_host $second_port list 9 5000 copy
} e
97 assert_match
{ERR
*} $e
98 set res
[r
-1 migrate
$second_host $second_port list 9 5000 copy replace
]
100 assert
{[$first exists
list] == 1}
101 assert
{[$second exists
list] == 1}
102 assert
{[$first lrange list 0 -1] eq
[$second lrange list 0 -1]}
106 test
{MIGRATE propagates TTL correctly
} {
107 set first
[srv
0 client
]
108 r
set key
"Some Value"
109 start_server
{tags
{"repl"}} {
110 set second
[srv
0 client
]
111 set second_host
[srv
0 host
]
112 set second_port
[srv
0 port
]
114 assert
{[$first exists key
] == 1}
115 assert
{[$second exists key
] == 0}
117 set ret
[r
-1 migrate
$second_host $second_port key
9 5000]
118 assert
{$ret eq
{OK
}}
119 assert
{[$first exists key
] == 0}
120 assert
{[$second exists key
] == 1}
121 assert
{[$second get key
] eq
{Some Value
}}
122 assert
{[$second ttl key
] >= 7 && [$second ttl key
] <= 10}
126 test
{MIGRATE can correctly transfer large values
} {
127 set first
[srv
0 client
]
129 for {set j
0} {$j < 5000} {incr j
} {
130 r rpush key
1 2 3 4 5 6 7 8 9 10
131 r rpush key
"item 1" "item 2" "item 3" "item 4" "item 5" \
132 "item 6" "item 7" "item 8" "item 9" "item 10"
134 assert
{[string length
[r dump key
]] > (1024*64)}
135 start_server
{tags
{"repl"}} {
136 set second
[srv
0 client
]
137 set second_host
[srv
0 host
]
138 set second_port
[srv
0 port
]
140 assert
{[$first exists key
] == 1}
141 assert
{[$second exists key
] == 0}
142 set ret
[r
-1 migrate
$second_host $second_port key
9 10000]
143 assert
{$ret eq
{OK
}}
144 assert
{[$first exists key
] == 0}
145 assert
{[$second exists key
] == 1}
146 assert
{[$second ttl key
] == -1}
147 assert
{[$second llen key
] == 5000*20}
151 test
{MIGRATE can correctly transfer hashes
} {
152 set first
[srv
0 client
]
154 r hmset key field1
"item 1" field2
"item 2" field3
"item 3" \
155 field4
"item 4" field5
"item 5" field6
"item 6"
156 start_server
{tags
{"repl"}} {
157 set second
[srv
0 client
]
158 set second_host
[srv
0 host
]
159 set second_port
[srv
0 port
]
161 assert
{[$first exists key
] == 1}
162 assert
{[$second exists key
] == 0}
163 set ret
[r
-1 migrate
$second_host $second_port key
9 10000]
164 assert
{$ret eq
{OK
}}
165 assert
{[$first exists key
] == 0}
166 assert
{[$second exists key
] == 1}
167 assert
{[$second ttl key
] == -1}
171 test
{MIGRATE timeout actually works
} {
172 set first
[srv
0 client
]
173 r
set key
"Some Value"
174 start_server
{tags
{"repl"}} {
175 set second
[srv
0 client
]
176 set second_host
[srv
0 host
]
177 set second_port
[srv
0 port
]
179 assert
{[$first exists key
] == 1}
180 assert
{[$second exists key
] == 0}
182 set rd
[redis_deferring_client
]
183 $rd debug sleep
5.0 ; # Make second server unable to reply.
185 catch {r
-1 migrate
$second_host $second_port key
9 1000} e
186 assert_match
{IOERR
*} $e
190 test
{MIGRATE is caching connections
} {
191 set first
[srv
0 client
]
192 r
set key
"Some Value"
193 start_server
{tags
{"repl"}} {
194 set second
[srv
0 client
]
195 set second_host
[srv
0 host
]
196 set second_port
[srv
0 port
]
198 assert
{[$first exists key
] == 1}
199 assert
{[$second exists key
] == 0}
201 set rd
[redis_deferring_client
]
202 $rd debug sleep
5.0 ; # Make second server unable to reply.
204 catch {r
-1 migrate
$second_host $second_port key
9 1000} e
205 assert_match
{IOERR
*} $e