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 caching connections
} {
47 # Note, we run this as first test so that the connection cache
49 set first
[srv
0 client
]
50 r
set key
"Some Value"
51 start_server
{tags
{"repl"}} {
52 set second
[srv
0 client
]
53 set second_host
[srv
0 host
]
54 set second_port
[srv
0 port
]
56 assert_match
{*migrate_cached_sockets
:0*} [r
-1 info]
57 r
-1 migrate
$second_host $second_port key
9 1000
58 assert_match
{*migrate_cached_sockets
:1*} [r
-1 info]
62 test
{MIGRATE cached connections are released
after some
time} {
64 assert_match
{*migrate_cached_sockets
:0*} [r
info]
67 test
{MIGRATE is able to migrate a key between two instances
} {
68 set first
[srv
0 client
]
69 r
set key
"Some Value"
70 start_server
{tags
{"repl"}} {
71 set second
[srv
0 client
]
72 set second_host
[srv
0 host
]
73 set second_port
[srv
0 port
]
75 assert
{[$first exists key
] == 1}
76 assert
{[$second exists key
] == 0}
77 set ret
[r
-1 migrate
$second_host $second_port key
9 5000]
79 assert
{[$first exists key
] == 0}
80 assert
{[$second exists key
] == 1}
81 assert
{[$second get key
] eq
{Some Value
}}
82 assert
{[$second ttl key
] == -1}
86 test
{MIGRATE is able to copy a key between two instances
} {
87 set first
[srv
0 client
]
90 start_server
{tags
{"repl"}} {
91 set second
[srv
0 client
]
92 set second_host
[srv
0 host
]
93 set second_port
[srv
0 port
]
95 assert
{[$first exists
list] == 1}
96 assert
{[$second exists
list] == 0}
97 set ret
[r
-1 migrate
$second_host $second_port list 9 5000 copy
]
99 assert
{[$first exists
list] == 1}
100 assert
{[$second exists
list] == 1}
101 assert
{[$first lrange list 0 -1] eq
[$second lrange list 0 -1]}
105 test
{MIGRATE will not overwrite existing keys
, unless REPLACE is used
} {
106 set first
[srv
0 client
]
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
list] == 1}
115 assert
{[$second exists
list] == 0}
116 $second set list somevalue
117 catch {r
-1 migrate
$second_host $second_port list 9 5000 copy
} e
118 assert_match
{ERR
*} $e
119 set res
[r
-1 migrate
$second_host $second_port list 9 5000 copy replace
]
120 assert
{$ret eq
{OK
}}
121 assert
{[$first exists
list] == 1}
122 assert
{[$second exists
list] == 1}
123 assert
{[$first lrange list 0 -1] eq
[$second lrange list 0 -1]}
127 test
{MIGRATE propagates TTL correctly
} {
128 set first
[srv
0 client
]
129 r
set key
"Some Value"
130 start_server
{tags
{"repl"}} {
131 set second
[srv
0 client
]
132 set second_host
[srv
0 host
]
133 set second_port
[srv
0 port
]
135 assert
{[$first exists key
] == 1}
136 assert
{[$second exists key
] == 0}
138 set ret
[r
-1 migrate
$second_host $second_port key
9 5000]
139 assert
{$ret eq
{OK
}}
140 assert
{[$first exists key
] == 0}
141 assert
{[$second exists key
] == 1}
142 assert
{[$second get key
] eq
{Some Value
}}
143 assert
{[$second ttl key
] >= 7 && [$second ttl key
] <= 10}
147 test
{MIGRATE can correctly transfer large values
} {
148 set first
[srv
0 client
]
150 for {set j
0} {$j < 5000} {incr j
} {
151 r rpush key
1 2 3 4 5 6 7 8 9 10
152 r rpush key
"item 1" "item 2" "item 3" "item 4" "item 5" \
153 "item 6" "item 7" "item 8" "item 9" "item 10"
155 assert
{[string length
[r dump key
]] > (1024*64)}
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}
168 assert
{[$second llen key
] == 5000*20}
172 test
{MIGRATE can correctly transfer hashes
} {
173 set first
[srv
0 client
]
175 r hmset key field1
"item 1" field2
"item 2" field3
"item 3" \
176 field4
"item 4" field5
"item 5" field6
"item 6"
177 start_server
{tags
{"repl"}} {
178 set second
[srv
0 client
]
179 set second_host
[srv
0 host
]
180 set second_port
[srv
0 port
]
182 assert
{[$first exists key
] == 1}
183 assert
{[$second exists key
] == 0}
184 set ret
[r
-1 migrate
$second_host $second_port key
9 10000]
185 assert
{$ret eq
{OK
}}
186 assert
{[$first exists key
] == 0}
187 assert
{[$second exists key
] == 1}
188 assert
{[$second ttl key
] == -1}
192 test
{MIGRATE timeout actually works
} {
193 set first
[srv
0 client
]
194 r
set key
"Some Value"
195 start_server
{tags
{"repl"}} {
196 set second
[srv
0 client
]
197 set second_host
[srv
0 host
]
198 set second_port
[srv
0 port
]
200 assert
{[$first exists key
] == 1}
201 assert
{[$second exists key
] == 0}
203 set rd
[redis_deferring_client
]
204 $rd debug sleep
1.0 ; # Make second server unable to reply.
206 catch {r
-1 migrate
$second_host $second_port key
9 500} e
207 assert_match
{IOERR
*} $e