@@ -201,4 +201,167 @@ var _ = Describe("Cache test", func() {
201201 Expect (mGet4 .Err ()).NotTo (HaveOccurred ())
202202 Expect (mGet4 .Val ()).To (Equal ([]interface {}{nil , nil , nil , nil }))
203203 })
204+
205+ It ("should mget for multi key in cache and db" , func () {
206+ multiset1 := client .Set (ctx , "key1" , "a" , 3000 * time .Millisecond )
207+ Expect (multiset1 .Err ()).NotTo (HaveOccurred ())
208+ Expect (multiset1 .Val ()).To (Equal ("OK" ))
209+
210+ multiset2 := client .Set (ctx , "key2" , "b" , 3000 * time .Millisecond )
211+ Expect (multiset2 .Err ()).NotTo (HaveOccurred ())
212+ Expect (multiset2 .Val ()).To (Equal ("OK" ))
213+
214+ multiset3 := client .Set (ctx , "key3" , "c" , 3000 * time .Millisecond )
215+ Expect (multiset3 .Err ()).NotTo (HaveOccurred ())
216+ Expect (multiset3 .Val ()).To (Equal ("OK" ))
217+
218+ multiset4 := client .Set (ctx , "key4" , "d" , 3000 * time .Millisecond )
219+ Expect (multiset4 .Err ()).NotTo (HaveOccurred ())
220+ Expect (multiset4 .Val ()).To (Equal ("OK" ))
221+
222+ multikey1 := client .MGet (ctx , "key1" )
223+ Expect (multikey1 .Err ()).NotTo (HaveOccurred ())
224+ Expect (multikey1 .Val ()).To (Equal ([]interface {}{"a" }))
225+
226+ MultiKey2 := client .Get (ctx , "key1" )
227+ Expect (MultiKey2 .Err ()).NotTo (HaveOccurred ())
228+ Expect (MultiKey2 .Val ()).To (Equal ("a" ))
229+
230+ MultiMget := client .MGet (ctx , "key1" , "key2" , "key3" , "key4" )
231+ Expect (MultiMget .Err ()).NotTo (HaveOccurred ())
232+ Expect (MultiMget .Val ()).To (Equal ([]interface {}{"a" , "b" , "c" , "d" }))
233+ })
234+
235+ It ("should mget for multi key in cache" , func () {
236+ multiset1 := client .Set (ctx , "key1" , "a" , 3000 * time .Millisecond )
237+ Expect (multiset1 .Err ()).NotTo (HaveOccurred ())
238+ Expect (multiset1 .Val ()).To (Equal ("OK" ))
239+
240+ multiset2 := client .Set (ctx , "key2" , "b" , 3000 * time .Millisecond )
241+ Expect (multiset2 .Err ()).NotTo (HaveOccurred ())
242+ Expect (multiset2 .Val ()).To (Equal ("OK" ))
243+
244+ multiset3 := client .Set (ctx , "key3" , "c" , 3000 * time .Millisecond )
245+ Expect (multiset3 .Err ()).NotTo (HaveOccurred ())
246+ Expect (multiset3 .Val ()).To (Equal ("OK" ))
247+
248+ multiset4 := client .Set (ctx , "key4" , "d" , 3000 * time .Millisecond )
249+ Expect (multiset4 .Err ()).NotTo (HaveOccurred ())
250+ Expect (multiset4 .Val ()).To (Equal ("OK" ))
251+
252+ multikey1 := client .MGet (ctx , "key1" )
253+ Expect (multikey1 .Err ()).NotTo (HaveOccurred ())
254+ Expect (multikey1 .Val ()).To (Equal ([]interface {}{"a" }))
255+
256+ MultiKey2 := client .Get (ctx , "key1" )
257+ Expect (MultiKey2 .Err ()).NotTo (HaveOccurred ())
258+ Expect (MultiKey2 .Val ()).To (Equal ("a" ))
259+
260+ MultiMget := client .MGet (ctx , "key1" , "key2" , "key3" , "key4" )
261+ Expect (MultiMget .Err ()).NotTo (HaveOccurred ())
262+ Expect (MultiMget .Val ()).To (Equal ([]interface {}{"a" , "b" , "c" , "d" }))
263+ })
264+
265+ It ("should mget for multi key in db" , func () {
266+ multiset1 := client .Set (ctx , "key1" , "a" , 3000 * time .Millisecond )
267+ Expect (multiset1 .Err ()).NotTo (HaveOccurred ())
268+ Expect (multiset1 .Val ()).To (Equal ("OK" ))
269+
270+ multiset2 := client .Set (ctx , "key2" , "b" , 3000 * time .Millisecond )
271+ Expect (multiset2 .Err ()).NotTo (HaveOccurred ())
272+ Expect (multiset2 .Val ()).To (Equal ("OK" ))
273+
274+ multiset3 := client .Set (ctx , "key3" , "c" , 3000 * time .Millisecond )
275+ Expect (multiset3 .Err ()).NotTo (HaveOccurred ())
276+ Expect (multiset3 .Val ()).To (Equal ("OK" ))
277+
278+ multiset4 := client .Set (ctx , "key4" , "d" , 3000 * time .Millisecond )
279+ Expect (multiset4 .Err ()).NotTo (HaveOccurred ())
280+ Expect (multiset4 .Val ()).To (Equal ("OK" ))
281+
282+ multikey1 := client .MGet (ctx , "key1" )
283+ Expect (multikey1 .Err ()).NotTo (HaveOccurred ())
284+ Expect (multikey1 .Val ()).To (Equal ([]interface {}{"a" }))
285+
286+ MultiKey2 := client .Get (ctx , "key1" )
287+ Expect (MultiKey2 .Err ()).NotTo (HaveOccurred ())
288+ Expect (MultiKey2 .Val ()).To (Equal ("a" ))
289+
290+ multikey3 := client .MGet (ctx , "key2" )
291+ Expect (multikey3 .Err ()).NotTo (HaveOccurred ())
292+ Expect (multikey3 .Val ()).To (Equal ([]interface {}{"b" }))
293+
294+ multikey4 := client .MGet (ctx , "key3" )
295+ Expect (multikey4 .Err ()).NotTo (HaveOccurred ())
296+ Expect (multikey4 .Val ()).To (Equal ([]interface {}{"c" }))
297+
298+ multikey5 := client .MGet (ctx , "key4" )
299+ Expect (multikey5 .Err ()).NotTo (HaveOccurred ())
300+ Expect (multikey5 .Val ()).To (Equal ([]interface {}{"d" }))
301+
302+ MultiMget := client .MGet (ctx , "key1" , "key2" , "key3" , "key4" )
303+ Expect (MultiMget .Err ()).NotTo (HaveOccurred ())
304+ Expect (MultiMget .Val ()).To (Equal ([]interface {}{"a" , "b" , "c" , "d" }))
305+ })
306+
307+ It ("should mget for multi key in db" , func () {
308+ multiset1 := client .Set (ctx , "key1" , "a" , 3000 * time .Millisecond )
309+ Expect (multiset1 .Err ()).NotTo (HaveOccurred ())
310+ Expect (multiset1 .Val ()).To (Equal ("OK" ))
311+
312+ multiset2 := client .Set (ctx , "key2" , "b" , 3000 * time .Millisecond )
313+ Expect (multiset2 .Err ()).NotTo (HaveOccurred ())
314+ Expect (multiset2 .Val ()).To (Equal ("OK" ))
315+
316+ multiset3 := client .Set (ctx , "key3" , "c" , 3000 * time .Millisecond )
317+ Expect (multiset3 .Err ()).NotTo (HaveOccurred ())
318+ Expect (multiset3 .Val ()).To (Equal ("OK" ))
319+
320+ multiset4 := client .Set (ctx , "key4" , "d" , 3000 * time .Millisecond )
321+ Expect (multiset4 .Err ()).NotTo (HaveOccurred ())
322+ Expect (multiset4 .Val ()).To (Equal ("OK" ))
323+
324+ MultiMget := client .MGet (ctx , "key1" , "key2" , "key3" , "key4" )
325+ Expect (MultiMget .Err ()).NotTo (HaveOccurred ())
326+ Expect (MultiMget .Val ()).To (Equal ([]interface {}{"a" , "b" , "c" , "d" }))
327+ })
328+
329+ It ("MGET against non existing key" , func () {
330+ multiset1 := client .Set (ctx , "key1" , "a" , 3000 * time .Millisecond )
331+ Expect (multiset1 .Err ()).NotTo (HaveOccurred ())
332+ Expect (multiset1 .Val ()).To (Equal ("OK" ))
333+
334+ multiset3 := client .Set (ctx , "key3" , "c" , 3000 * time .Millisecond )
335+ Expect (multiset3 .Err ()).NotTo (HaveOccurred ())
336+ Expect (multiset3 .Val ()).To (Equal ("OK" ))
337+
338+ multiset4 := client .Set (ctx , "key4" , "d" , 3000 * time .Millisecond )
339+ Expect (multiset4 .Err ()).NotTo (HaveOccurred ())
340+ Expect (multiset4 .Val ()).To (Equal ("OK" ))
341+
342+ MultiMget := client .MGet (ctx , "key1" , "key2" , "key3" , "key4" )
343+ Expect (MultiMget .Err ()).NotTo (HaveOccurred ())
344+ Expect (MultiMget .Val ()).To (Equal ([]interface {}{"a" , nil , "c" , "d" }))
345+ })
346+ It ("MGET against non-string key" , func () {
347+ SetMultiKey := client .Set (ctx , "foo{t}" , "BAR" , 3000 * time .Millisecond )
348+ Expect (SetMultiKey .Err ()).NotTo (HaveOccurred ())
349+ Expect (SetMultiKey .Val ()).To (Equal ("OK" ))
350+
351+ SetMultiKey1 := client .Set (ctx , "bar{t}" , "FOO" , 3000 * time .Millisecond )
352+ Expect (SetMultiKey1 .Err ()).NotTo (HaveOccurred ())
353+ Expect (SetMultiKey1 .Val ()).To (Equal ("OK" ))
354+
355+ SaddMultiKey := client .SAdd (ctx , "myset{t}" , "ciao" )
356+ Expect (SaddMultiKey .Err ()).NotTo (HaveOccurred ())
357+ Expect (SaddMultiKey .Val ()).To (Equal (int64 (1 )))
358+
359+ SaddMultiKey1 := client .SAdd (ctx , "myset{t}" , "bau" )
360+ Expect (SaddMultiKey1 .Err ()).NotTo (HaveOccurred ())
361+ Expect (SaddMultiKey1 .Val ()).To (Equal (int64 (1 )))
362+
363+ MultiMget := client .MGet (ctx , "foo{t}" , "baazz{t}" , "bar{t}" , "myset{t}" )
364+ Expect (MultiMget .Err ()).NotTo (HaveOccurred ())
365+ Expect (MultiMget .Val ()).To (Equal ([]interface {}{"BAR" , nil , "FOO" , nil }))
366+ })
204367})
0 commit comments