@@ -1316,25 +1316,45 @@ func TestClientSideCachingExecAbort(t *testing.T) {
1316
1316
go func () {
1317
1317
mock .Expect ("CLIENT" , "CACHING" , "YES" ).
1318
1318
Expect ("MULTI" ).
1319
- Expect ("PTTL" , "a " ).
1320
- Expect ("GET" , "a " ).
1319
+ Expect ("PTTL" , "a1 " ).
1320
+ Expect ("GET" , "a1 " ).
1321
1321
Expect ("EXEC" ).
1322
1322
ReplyString ("OK" ).
1323
1323
ReplyString ("OK" ).
1324
1324
ReplyString ("OK" ).
1325
1325
ReplyString ("OK" ).
1326
1326
Reply (RedisMessage {typ : '_' })
1327
+ mock .Expect ("CLIENT" , "CACHING" , "YES" ).
1328
+ Expect ("MULTI" ).
1329
+ Expect ("PTTL" , "a2" ).
1330
+ Expect ("GET" , "a2" ).
1331
+ Expect ("EXEC" ).
1332
+ ReplyString ("OK" ).
1333
+ ReplyString ("OK" ).
1334
+ ReplyError ("MOVED 0 127.0.0.1" ).
1335
+ ReplyError ("MOVED 0 127.0.0.1" ).
1336
+ Reply (RedisMessage {typ : '_' })
1327
1337
}()
1328
1338
1329
- v , err := p .DoCache (context .Background (), Cacheable (cmds .NewCompleted ([]string {"GET" , "a" })), 10 * time .Second ).ToMessage ()
1330
- if err != ErrDoCacheAborted {
1331
- t .Errorf ("unexpected err, got %v" , err )
1332
- }
1333
- if v .IsCacheHit () {
1334
- t .Errorf ("unexpected cache hit" )
1335
- }
1336
- if v , entry := p .cache .Flight ("a" , "GET" , time .Second , time .Now ()); v .typ != 0 || entry != nil {
1337
- t .Errorf ("unexpected cache value and entry %v %v" , v , entry )
1339
+ for i , key := range []string {"a1" , "a2" } {
1340
+ v , err := p .DoCache (context .Background (), Cacheable (cmds .NewCompleted ([]string {"GET" , key })), 10 * time .Second ).ToMessage ()
1341
+ if i == 0 {
1342
+ if err != ErrDoCacheAborted {
1343
+ t .Errorf ("unexpected err, got %v" , err )
1344
+ }
1345
+ } else {
1346
+ if re , ok := err .(* RedisError ); ! ok {
1347
+ t .Errorf ("unexpected err, got %v" , err )
1348
+ } else if _ , moved := re .IsMoved (); ! moved {
1349
+ t .Errorf ("unexpected err, got %v" , err )
1350
+ }
1351
+ }
1352
+ if v .IsCacheHit () {
1353
+ t .Errorf ("unexpected cache hit" )
1354
+ }
1355
+ if v , entry := p .cache .Flight (key , "GET" , time .Second , time .Now ()); v .typ != 0 || entry != nil {
1356
+ t .Errorf ("unexpected cache value and entry %v %v" , v , entry )
1357
+ }
1338
1358
}
1339
1359
}
1340
1360
@@ -1641,20 +1661,42 @@ func TestClientSideCachingExecAbortMGet(t *testing.T) {
1641
1661
ReplyString ("OK" ).
1642
1662
ReplyString ("OK" ).
1643
1663
Reply (RedisMessage {typ : '_' })
1664
+ mock .Expect ("CLIENT" , "CACHING" , "YES" ).
1665
+ Expect ("MULTI" ).
1666
+ Expect ("PTTL" , "b1" ).
1667
+ Expect ("PTTL" , "b2" ).
1668
+ Expect ("MGET" , "b1" , "b2" ).
1669
+ Expect ("EXEC" ).
1670
+ ReplyString ("OK" ).
1671
+ ReplyString ("OK" ).
1672
+ ReplyString ("OK" ).
1673
+ ReplyString ("OK" ).
1674
+ ReplyError ("MOVED 0 127.0.0.1" ).
1675
+ Reply (RedisMessage {typ : '_' })
1644
1676
}()
1645
1677
1646
- v , err := p .DoCache (context .Background (), Cacheable (cmds .NewMGetCompleted ([]string {"MGET" , "a1" , "a2" })), 10 * time .Second ).ToMessage ()
1647
- if err != ErrDoCacheAborted {
1648
- t .Errorf ("unexpected err, got %v" , err )
1649
- }
1650
- if v .IsCacheHit () {
1651
- t .Errorf ("unexpected cache hit" )
1652
- }
1653
- if v , entry := p .cache .Flight ("a1" , "GET" , time .Second , time .Now ()); v .typ != 0 || entry != nil {
1654
- t .Errorf ("unexpected cache value and entry %v %v" , v , entry )
1655
- }
1656
- if v , entry := p .cache .Flight ("a2" , "GET" , time .Second , time .Now ()); v .typ != 0 || entry != nil {
1657
- t .Errorf ("unexpected cache value and entry %v %v" , v , entry )
1678
+ for i , pair := range [][2 ]string {{"a1" , "a2" }, {"b1" , "b2" }} {
1679
+ v , err := p .DoCache (context .Background (), Cacheable (cmds .NewMGetCompleted ([]string {"MGET" , pair [0 ], pair [1 ]})), 10 * time .Second ).ToMessage ()
1680
+ if i == 0 {
1681
+ if err != ErrDoCacheAborted {
1682
+ t .Errorf ("unexpected err, got %v" , err )
1683
+ }
1684
+ } else {
1685
+ if re , ok := err .(* RedisError ); ! ok {
1686
+ t .Errorf ("unexpected err, got %v" , err )
1687
+ } else if _ , moved := re .IsMoved (); ! moved {
1688
+ t .Errorf ("unexpected err, got %v" , err )
1689
+ }
1690
+ }
1691
+ if v .IsCacheHit () {
1692
+ t .Errorf ("unexpected cache hit" )
1693
+ }
1694
+ if v , entry := p .cache .Flight (pair [0 ], "GET" , time .Second , time .Now ()); v .typ != 0 || entry != nil {
1695
+ t .Errorf ("unexpected cache value and entry %v %v" , v , entry )
1696
+ }
1697
+ if v , entry := p .cache .Flight (pair [1 ], "GET" , time .Second , time .Now ()); v .typ != 0 || entry != nil {
1698
+ t .Errorf ("unexpected cache value and entry %v %v" , v , entry )
1699
+ }
1658
1700
}
1659
1701
}
1660
1702
@@ -1925,6 +1967,11 @@ func TestClientSideCachingExecAbortDoMultiCache(t *testing.T) {
1925
1967
Expect ("PTTL" , "a2" ).
1926
1968
Expect ("GET" , "a2" ).
1927
1969
Expect ("EXEC" ).
1970
+ Expect ("CLIENT" , "CACHING" , "YES" ).
1971
+ Expect ("MULTI" ).
1972
+ Expect ("PTTL" , "a3" ).
1973
+ Expect ("GET" , "a3" ).
1974
+ Expect ("EXEC" ).
1928
1975
ReplyString ("OK" ).
1929
1976
ReplyString ("OK" ).
1930
1977
ReplyString ("OK" ).
@@ -1937,26 +1984,41 @@ func TestClientSideCachingExecAbortDoMultiCache(t *testing.T) {
1937
1984
ReplyString ("OK" ).
1938
1985
ReplyString ("OK" ).
1939
1986
ReplyString ("OK" ).
1987
+ Reply (RedisMessage {typ : '_' }).
1988
+ ReplyString ("OK" ).
1989
+ ReplyString ("OK" ).
1990
+ ReplyString ("OK" ).
1991
+ ReplyError ("MOVED 0 127.0.0.1" ).
1940
1992
Reply (RedisMessage {typ : '_' })
1941
1993
}()
1942
1994
1943
1995
arr := p .DoMultiCache (context .Background (), []CacheableTTL {
1944
1996
CT (Cacheable (cmds .NewCompleted ([]string {"GET" , "a1" })), time .Second * 10 ),
1945
1997
CT (Cacheable (cmds .NewCompleted ([]string {"GET" , "a2" })), time .Second * 10 ),
1998
+ CT (Cacheable (cmds .NewCompleted ([]string {"GET" , "a3" })), time .Second * 10 ),
1946
1999
}... ).s
1947
2000
for i , resp := range arr {
1948
2001
v , err := resp .ToMessage ()
1949
2002
if i == 0 {
1950
2003
if v .integer != 1 {
1951
2004
t .Errorf ("unexpected cached response, expected %v, got %v" , 1 , v .integer )
1952
2005
}
1953
- } else {
2006
+ } else if i == 1 {
1954
2007
if err != ErrDoCacheAborted {
1955
2008
t .Errorf ("unexpected err, got %v" , err )
1956
2009
}
1957
2010
if v .IsCacheHit () {
1958
2011
t .Errorf ("unexpected cache hit" )
1959
2012
}
2013
+ } else if i == 2 {
2014
+ if re , ok := err .(* RedisError ); ! ok {
2015
+ t .Errorf ("unexpected err, got %v" , err )
2016
+ } else if _ , moved := re .IsMoved (); ! moved {
2017
+ t .Errorf ("unexpected err, got %v" , err )
2018
+ }
2019
+ if v .IsCacheHit () {
2020
+ t .Errorf ("unexpected cache hit" )
2021
+ }
1960
2022
}
1961
2023
}
1962
2024
if v , entry := p .cache .Flight ("a1" , "GET" , time .Second , time .Now ()); v .integer != 1 {
0 commit comments