redis_test.go 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  1. package redis
  2. import (
  3. "crypto/tls"
  4. "errors"
  5. "io"
  6. "strconv"
  7. "testing"
  8. "time"
  9. "github.com/alicebob/miniredis/v2"
  10. red "github.com/go-redis/redis"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestRedis_Exists(t *testing.T) {
  14. runOnRedis(t, func(client *Redis) {
  15. _, err := New(client.Addr, badType()).Exists("a")
  16. assert.NotNil(t, err)
  17. ok, err := client.Exists("a")
  18. assert.Nil(t, err)
  19. assert.False(t, ok)
  20. assert.Nil(t, client.Set("a", "b"))
  21. ok, err = client.Exists("a")
  22. assert.Nil(t, err)
  23. assert.True(t, ok)
  24. })
  25. }
  26. func TestRedisTLS_Exists(t *testing.T) {
  27. runOnRedisTLS(t, func(client *Redis) {
  28. _, err := New(client.Addr, badType()).Exists("a")
  29. assert.NotNil(t, err)
  30. ok, err := client.Exists("a")
  31. assert.NotNil(t, err)
  32. assert.False(t, ok)
  33. assert.NotNil(t, client.Set("a", "b"))
  34. ok, err = client.Exists("a")
  35. assert.NotNil(t, err)
  36. assert.False(t, ok)
  37. })
  38. }
  39. func TestRedis_Eval(t *testing.T) {
  40. runOnRedis(t, func(client *Redis) {
  41. _, err := New(client.Addr, badType()).Eval(`redis.call("EXISTS", KEYS[1])`, []string{"notexist"})
  42. assert.NotNil(t, err)
  43. _, err = client.Eval(`redis.call("EXISTS", KEYS[1])`, []string{"notexist"})
  44. assert.Equal(t, Nil, err)
  45. err = client.Set("key1", "value1")
  46. assert.Nil(t, err)
  47. _, err = client.Eval(`redis.call("EXISTS", KEYS[1])`, []string{"key1"})
  48. assert.Equal(t, Nil, err)
  49. val, err := client.Eval(`return redis.call("EXISTS", KEYS[1])`, []string{"key1"})
  50. assert.Nil(t, err)
  51. assert.Equal(t, int64(1), val)
  52. })
  53. }
  54. func TestRedis_GeoHash(t *testing.T) {
  55. runOnRedis(t, func(client *Redis) {
  56. _, err := client.GeoHash("parent", "child1", "child2")
  57. assert.NotNil(t, err)
  58. })
  59. }
  60. func TestRedis_Hgetall(t *testing.T) {
  61. runOnRedis(t, func(client *Redis) {
  62. assert.Nil(t, client.Hset("a", "aa", "aaa"))
  63. assert.Nil(t, client.Hset("a", "bb", "bbb"))
  64. _, err := New(client.Addr, badType()).Hgetall("a")
  65. assert.NotNil(t, err)
  66. vals, err := client.Hgetall("a")
  67. assert.Nil(t, err)
  68. assert.EqualValues(t, map[string]string{
  69. "aa": "aaa",
  70. "bb": "bbb",
  71. }, vals)
  72. })
  73. }
  74. func TestRedis_Hvals(t *testing.T) {
  75. runOnRedis(t, func(client *Redis) {
  76. assert.NotNil(t, New(client.Addr, badType()).Hset("a", "aa", "aaa"))
  77. assert.Nil(t, client.Hset("a", "aa", "aaa"))
  78. assert.Nil(t, client.Hset("a", "bb", "bbb"))
  79. _, err := New(client.Addr, badType()).Hvals("a")
  80. assert.NotNil(t, err)
  81. vals, err := client.Hvals("a")
  82. assert.Nil(t, err)
  83. assert.ElementsMatch(t, []string{"aaa", "bbb"}, vals)
  84. })
  85. }
  86. func TestRedis_Hsetnx(t *testing.T) {
  87. runOnRedis(t, func(client *Redis) {
  88. assert.Nil(t, client.Hset("a", "aa", "aaa"))
  89. assert.Nil(t, client.Hset("a", "bb", "bbb"))
  90. _, err := New(client.Addr, badType()).Hsetnx("a", "bb", "ccc")
  91. assert.NotNil(t, err)
  92. ok, err := client.Hsetnx("a", "bb", "ccc")
  93. assert.Nil(t, err)
  94. assert.False(t, ok)
  95. ok, err = client.Hsetnx("a", "dd", "ddd")
  96. assert.Nil(t, err)
  97. assert.True(t, ok)
  98. vals, err := client.Hvals("a")
  99. assert.Nil(t, err)
  100. assert.ElementsMatch(t, []string{"aaa", "bbb", "ddd"}, vals)
  101. })
  102. }
  103. func TestRedis_HdelHlen(t *testing.T) {
  104. runOnRedis(t, func(client *Redis) {
  105. assert.Nil(t, client.Hset("a", "aa", "aaa"))
  106. assert.Nil(t, client.Hset("a", "bb", "bbb"))
  107. _, err := New(client.Addr, badType()).Hlen("a")
  108. assert.NotNil(t, err)
  109. num, err := client.Hlen("a")
  110. assert.Nil(t, err)
  111. assert.Equal(t, 2, num)
  112. val, err := client.Hdel("a", "aa")
  113. assert.Nil(t, err)
  114. assert.True(t, val)
  115. vals, err := client.Hvals("a")
  116. assert.Nil(t, err)
  117. assert.ElementsMatch(t, []string{"bbb"}, vals)
  118. })
  119. }
  120. func TestRedis_HIncrBy(t *testing.T) {
  121. runOnRedis(t, func(client *Redis) {
  122. _, err := New(client.Addr, badType()).Hincrby("key", "field", 2)
  123. assert.NotNil(t, err)
  124. val, err := client.Hincrby("key", "field", 2)
  125. assert.Nil(t, err)
  126. assert.Equal(t, 2, val)
  127. val, err = client.Hincrby("key", "field", 3)
  128. assert.Nil(t, err)
  129. assert.Equal(t, 5, val)
  130. })
  131. }
  132. func TestRedis_Hkeys(t *testing.T) {
  133. runOnRedis(t, func(client *Redis) {
  134. assert.Nil(t, client.Hset("a", "aa", "aaa"))
  135. assert.Nil(t, client.Hset("a", "bb", "bbb"))
  136. _, err := New(client.Addr, badType()).Hkeys("a")
  137. assert.NotNil(t, err)
  138. vals, err := client.Hkeys("a")
  139. assert.Nil(t, err)
  140. assert.ElementsMatch(t, []string{"aa", "bb"}, vals)
  141. })
  142. }
  143. func TestRedis_Hmget(t *testing.T) {
  144. runOnRedis(t, func(client *Redis) {
  145. assert.Nil(t, client.Hset("a", "aa", "aaa"))
  146. assert.Nil(t, client.Hset("a", "bb", "bbb"))
  147. _, err := New(client.Addr, badType()).Hmget("a", "aa", "bb")
  148. assert.NotNil(t, err)
  149. vals, err := client.Hmget("a", "aa", "bb")
  150. assert.Nil(t, err)
  151. assert.EqualValues(t, []string{"aaa", "bbb"}, vals)
  152. vals, err = client.Hmget("a", "aa", "no", "bb")
  153. assert.Nil(t, err)
  154. assert.EqualValues(t, []string{"aaa", "", "bbb"}, vals)
  155. })
  156. }
  157. func TestRedis_Hmset(t *testing.T) {
  158. runOnRedis(t, func(client *Redis) {
  159. assert.NotNil(t, New(client.Addr, badType()).Hmset("a", nil))
  160. assert.Nil(t, client.Hmset("a", map[string]string{
  161. "aa": "aaa",
  162. "bb": "bbb",
  163. }))
  164. vals, err := client.Hmget("a", "aa", "bb")
  165. assert.Nil(t, err)
  166. assert.EqualValues(t, []string{"aaa", "bbb"}, vals)
  167. })
  168. }
  169. func TestRedis_Hscan(t *testing.T) {
  170. runOnRedis(t, func(client *Redis) {
  171. key := "hash:test"
  172. fieldsAndValues := make(map[string]string)
  173. for i := 0; i < 1550; i++ {
  174. fieldsAndValues["filed_"+strconv.Itoa(i)] = randomStr(i)
  175. }
  176. err := client.Hmset(key, fieldsAndValues)
  177. assert.Nil(t, err)
  178. var cursor uint64 = 0
  179. sum := 0
  180. for {
  181. _, _, err := New(client.Addr, badType()).Hscan(key, cursor, "*", 100)
  182. assert.NotNil(t, err)
  183. reMap, next, err := client.Hscan(key, cursor, "*", 100)
  184. assert.Nil(t, err)
  185. sum += len(reMap)
  186. if next == 0 {
  187. break
  188. }
  189. cursor = next
  190. }
  191. assert.Equal(t, sum, 3100)
  192. _, err = New(client.Addr, badType()).Del(key)
  193. assert.NotNil(t, err)
  194. _, err = client.Del(key)
  195. assert.Nil(t, err)
  196. })
  197. }
  198. func TestRedis_Incr(t *testing.T) {
  199. runOnRedis(t, func(client *Redis) {
  200. _, err := New(client.Addr, badType()).Incr("a")
  201. assert.NotNil(t, err)
  202. val, err := client.Incr("a")
  203. assert.Nil(t, err)
  204. assert.Equal(t, int64(1), val)
  205. val, err = client.Incr("a")
  206. assert.Nil(t, err)
  207. assert.Equal(t, int64(2), val)
  208. })
  209. }
  210. func TestRedis_IncrBy(t *testing.T) {
  211. runOnRedis(t, func(client *Redis) {
  212. _, err := New(client.Addr, badType()).Incrby("a", 2)
  213. assert.NotNil(t, err)
  214. val, err := client.Incrby("a", 2)
  215. assert.Nil(t, err)
  216. assert.Equal(t, int64(2), val)
  217. val, err = client.Incrby("a", 3)
  218. assert.Nil(t, err)
  219. assert.Equal(t, int64(5), val)
  220. })
  221. }
  222. func TestRedis_Keys(t *testing.T) {
  223. runOnRedis(t, func(client *Redis) {
  224. err := client.Set("key1", "value1")
  225. assert.Nil(t, err)
  226. err = client.Set("key2", "value2")
  227. assert.Nil(t, err)
  228. _, err = New(client.Addr, badType()).Keys("*")
  229. assert.NotNil(t, err)
  230. keys, err := client.Keys("*")
  231. assert.Nil(t, err)
  232. assert.ElementsMatch(t, []string{"key1", "key2"}, keys)
  233. })
  234. }
  235. func TestRedis_HyperLogLog(t *testing.T) {
  236. runOnRedis(t, func(client *Redis) {
  237. client.Ping()
  238. r := New(client.Addr, badType())
  239. _, err := r.Pfadd("key1")
  240. assert.NotNil(t, err)
  241. _, err = r.Pfcount("*")
  242. assert.NotNil(t, err)
  243. err = r.Pfmerge("*")
  244. assert.NotNil(t, err)
  245. })
  246. }
  247. func TestRedis_List(t *testing.T) {
  248. runOnRedis(t, func(client *Redis) {
  249. _, err := New(client.Addr, badType()).Lpush("key", "value1", "value2")
  250. assert.NotNil(t, err)
  251. val, err := client.Lpush("key", "value1", "value2")
  252. assert.Nil(t, err)
  253. assert.Equal(t, 2, val)
  254. _, err = New(client.Addr, badType()).Rpush("key", "value3", "value4")
  255. assert.NotNil(t, err)
  256. val, err = client.Rpush("key", "value3", "value4")
  257. assert.Nil(t, err)
  258. assert.Equal(t, 4, val)
  259. _, err = New(client.Addr, badType()).Llen("key")
  260. assert.NotNil(t, err)
  261. val, err = client.Llen("key")
  262. assert.Nil(t, err)
  263. assert.Equal(t, 4, val)
  264. vals, err := client.Lrange("key", 0, 10)
  265. assert.Nil(t, err)
  266. assert.EqualValues(t, []string{"value2", "value1", "value3", "value4"}, vals)
  267. _, err = New(client.Addr, badType()).Lpop("key")
  268. assert.NotNil(t, err)
  269. v, err := client.Lpop("key")
  270. assert.Nil(t, err)
  271. assert.Equal(t, "value2", v)
  272. val, err = client.Lpush("key", "value1", "value2")
  273. assert.Nil(t, err)
  274. assert.Equal(t, 5, val)
  275. _, err = New(client.Addr, badType()).Rpop("key")
  276. assert.NotNil(t, err)
  277. v, err = client.Rpop("key")
  278. assert.Nil(t, err)
  279. assert.Equal(t, "value4", v)
  280. val, err = client.Rpush("key", "value4", "value3", "value3")
  281. assert.Nil(t, err)
  282. assert.Equal(t, 7, val)
  283. _, err = New(client.Addr, badType()).Lrem("key", 2, "value1")
  284. assert.NotNil(t, err)
  285. n, err := client.Lrem("key", 2, "value1")
  286. assert.Nil(t, err)
  287. assert.Equal(t, 2, n)
  288. _, err = New(client.Addr, badType()).Lrange("key", 0, 10)
  289. assert.NotNil(t, err)
  290. vals, err = client.Lrange("key", 0, 10)
  291. assert.Nil(t, err)
  292. assert.EqualValues(t, []string{"value2", "value3", "value4", "value3", "value3"}, vals)
  293. n, err = client.Lrem("key", -2, "value3")
  294. assert.Nil(t, err)
  295. assert.Equal(t, 2, n)
  296. vals, err = client.Lrange("key", 0, 10)
  297. assert.Nil(t, err)
  298. assert.EqualValues(t, []string{"value2", "value3", "value4"}, vals)
  299. })
  300. }
  301. func TestRedis_Mget(t *testing.T) {
  302. runOnRedis(t, func(client *Redis) {
  303. err := client.Set("key1", "value1")
  304. assert.Nil(t, err)
  305. err = client.Set("key2", "value2")
  306. assert.Nil(t, err)
  307. _, err = New(client.Addr, badType()).Mget("key1", "key0", "key2", "key3")
  308. assert.NotNil(t, err)
  309. vals, err := client.Mget("key1", "key0", "key2", "key3")
  310. assert.Nil(t, err)
  311. assert.EqualValues(t, []string{"value1", "", "value2", ""}, vals)
  312. })
  313. }
  314. func TestRedis_SetBit(t *testing.T) {
  315. runOnRedis(t, func(client *Redis) {
  316. err := New(client.Addr, badType()).SetBit("key", 1, 1)
  317. assert.NotNil(t, err)
  318. err = client.SetBit("key", 1, 1)
  319. assert.Nil(t, err)
  320. })
  321. }
  322. func TestRedis_GetBit(t *testing.T) {
  323. runOnRedis(t, func(client *Redis) {
  324. err := client.SetBit("key", 2, 1)
  325. assert.Nil(t, err)
  326. _, err = New(client.Addr, badType()).GetBit("key", 2)
  327. assert.NotNil(t, err)
  328. val, err := client.GetBit("key", 2)
  329. assert.Nil(t, err)
  330. assert.Equal(t, 1, val)
  331. })
  332. }
  333. func TestRedis_BitCount(t *testing.T) {
  334. runOnRedis(t, func(client *Redis) {
  335. for i := 0; i < 11; i++ {
  336. err := client.SetBit("key", int64(i), 1)
  337. assert.Nil(t, err)
  338. }
  339. _, err := New(client.Addr, badType()).BitCount("key", 0, -1)
  340. assert.NotNil(t, err)
  341. val, err := client.BitCount("key", 0, -1)
  342. assert.Nil(t, err)
  343. assert.Equal(t, int64(11), val)
  344. val, err = client.BitCount("key", 0, 0)
  345. assert.Nil(t, err)
  346. assert.Equal(t, int64(8), val)
  347. val, err = client.BitCount("key", 1, 1)
  348. assert.Nil(t, err)
  349. assert.Equal(t, int64(3), val)
  350. val, err = client.BitCount("key", 0, 1)
  351. assert.Nil(t, err)
  352. assert.Equal(t, int64(11), val)
  353. val, err = client.BitCount("key", 2, 2)
  354. assert.Nil(t, err)
  355. assert.Equal(t, int64(0), val)
  356. })
  357. }
  358. func TestRedis_BitOpAnd(t *testing.T) {
  359. runOnRedis(t, func(client *Redis) {
  360. err := client.Set("key1", "0")
  361. assert.Nil(t, err)
  362. err = client.Set("key2", "1")
  363. assert.Nil(t, err)
  364. _, err = New(client.Addr, badType()).BitOpAnd("destKey", "key1", "key2")
  365. assert.NotNil(t, err)
  366. val, err := client.BitOpAnd("destKey", "key1", "key2")
  367. assert.Nil(t, err)
  368. assert.Equal(t, int64(1), val)
  369. valStr, err := client.Get("destKey")
  370. assert.Nil(t, err)
  371. // destKey binary 110000 ascii 0
  372. assert.Equal(t, "0", valStr)
  373. })
  374. }
  375. func TestRedis_BitOpNot(t *testing.T) {
  376. runOnRedis(t, func(client *Redis) {
  377. err := client.Set("key1", "\u0000")
  378. assert.Nil(t, err)
  379. _, err = New(client.Addr, badType()).BitOpNot("destKey", "key1")
  380. assert.NotNil(t, err)
  381. val, err := client.BitOpNot("destKey", "key1")
  382. assert.Nil(t, err)
  383. assert.Equal(t, int64(1), val)
  384. valStr, err := client.Get("destKey")
  385. assert.Nil(t, err)
  386. assert.Equal(t, "\xff", valStr)
  387. })
  388. }
  389. func TestRedis_BitOpOr(t *testing.T) {
  390. runOnRedis(t, func(client *Redis) {
  391. err := client.Set("key1", "1")
  392. assert.Nil(t, err)
  393. err = client.Set("key2", "0")
  394. assert.Nil(t, err)
  395. _, err = New(client.Addr, badType()).BitOpOr("destKey", "key1", "key2")
  396. assert.NotNil(t, err)
  397. val, err := client.BitOpOr("destKey", "key1", "key2")
  398. assert.Nil(t, err)
  399. assert.Equal(t, int64(1), val)
  400. valStr, err := client.Get("destKey")
  401. assert.Nil(t, err)
  402. assert.Equal(t, "1", valStr)
  403. })
  404. }
  405. func TestRedis_BitOpXor(t *testing.T) {
  406. runOnRedis(t, func(client *Redis) {
  407. err := client.Set("key1", "\xff")
  408. assert.Nil(t, err)
  409. err = client.Set("key2", "\x0f")
  410. assert.Nil(t, err)
  411. _, err = New(client.Addr, badType()).BitOpXor("destKey", "key1", "key2")
  412. assert.NotNil(t, err)
  413. val, err := client.BitOpXor("destKey", "key1", "key2")
  414. assert.Nil(t, err)
  415. assert.Equal(t, int64(1), val)
  416. valStr, err := client.Get("destKey")
  417. assert.Nil(t, err)
  418. assert.Equal(t, "\xf0", valStr)
  419. })
  420. }
  421. func TestRedis_BitPos(t *testing.T) {
  422. runOnRedis(t, func(client *Redis) {
  423. // 11111111 11110000 00000000
  424. err := client.Set("key", "\xff\xf0\x00")
  425. assert.Nil(t, err)
  426. _, err = New(client.Addr, badType()).BitPos("key", 0, 0, -1)
  427. assert.NotNil(t, err)
  428. val, err := client.BitPos("key", 0, 0, 2)
  429. assert.Nil(t, err)
  430. assert.Equal(t, int64(12), val)
  431. val, err = client.BitPos("key", 1, 0, 2)
  432. assert.Nil(t, err)
  433. assert.Equal(t, int64(0), val)
  434. val, err = client.BitPos("key", 0, 1, 2)
  435. assert.Nil(t, err)
  436. assert.Equal(t, int64(12), val)
  437. val, err = client.BitPos("key", 1, 1, 2)
  438. assert.Nil(t, err)
  439. assert.Equal(t, int64(8), val)
  440. val, err = client.BitPos("key", 1, 2, 2)
  441. assert.Nil(t, err)
  442. assert.Equal(t, int64(-1), val)
  443. })
  444. }
  445. func TestRedis_Persist(t *testing.T) {
  446. runOnRedis(t, func(client *Redis) {
  447. _, err := New(client.Addr, badType()).Persist("key")
  448. assert.NotNil(t, err)
  449. ok, err := client.Persist("key")
  450. assert.Nil(t, err)
  451. assert.False(t, ok)
  452. err = client.Set("key", "value")
  453. assert.Nil(t, err)
  454. ok, err = client.Persist("key")
  455. assert.Nil(t, err)
  456. assert.False(t, ok)
  457. err = New(client.Addr, badType()).Expire("key", 5)
  458. assert.NotNil(t, err)
  459. err = client.Expire("key", 5)
  460. assert.Nil(t, err)
  461. ok, err = client.Persist("key")
  462. assert.Nil(t, err)
  463. assert.True(t, ok)
  464. err = New(client.Addr, badType()).Expireat("key", time.Now().Unix()+5)
  465. assert.NotNil(t, err)
  466. err = client.Expireat("key", time.Now().Unix()+5)
  467. assert.Nil(t, err)
  468. ok, err = client.Persist("key")
  469. assert.Nil(t, err)
  470. assert.True(t, ok)
  471. })
  472. }
  473. func TestRedis_Ping(t *testing.T) {
  474. runOnRedis(t, func(client *Redis) {
  475. ok := client.Ping()
  476. assert.True(t, ok)
  477. })
  478. }
  479. func TestRedis_Scan(t *testing.T) {
  480. runOnRedis(t, func(client *Redis) {
  481. err := client.Set("key1", "value1")
  482. assert.Nil(t, err)
  483. err = client.Set("key2", "value2")
  484. assert.Nil(t, err)
  485. _, _, err = New(client.Addr, badType()).Scan(0, "*", 100)
  486. assert.NotNil(t, err)
  487. keys, _, err := client.Scan(0, "*", 100)
  488. assert.Nil(t, err)
  489. assert.ElementsMatch(t, []string{"key1", "key2"}, keys)
  490. })
  491. }
  492. func TestRedis_Sscan(t *testing.T) {
  493. runOnRedis(t, func(client *Redis) {
  494. key := "list"
  495. var list []string
  496. for i := 0; i < 1550; i++ {
  497. list = append(list, randomStr(i))
  498. }
  499. lens, err := client.Sadd(key, list)
  500. assert.Nil(t, err)
  501. assert.Equal(t, lens, 1550)
  502. var cursor uint64 = 0
  503. sum := 0
  504. for {
  505. _, _, err := New(client.Addr, badType()).Sscan(key, cursor, "", 100)
  506. assert.NotNil(t, err)
  507. keys, next, err := client.Sscan(key, cursor, "", 100)
  508. assert.Nil(t, err)
  509. sum += len(keys)
  510. if next == 0 {
  511. break
  512. }
  513. cursor = next
  514. }
  515. assert.Equal(t, sum, 1550)
  516. _, err = New(client.Addr, badType()).Del(key)
  517. assert.NotNil(t, err)
  518. _, err = client.Del(key)
  519. assert.Nil(t, err)
  520. })
  521. }
  522. func TestRedis_Set(t *testing.T) {
  523. runOnRedis(t, func(client *Redis) {
  524. _, err := New(client.Addr, badType()).Sadd("key", 1, 2, 3, 4)
  525. assert.NotNil(t, err)
  526. num, err := client.Sadd("key", 1, 2, 3, 4)
  527. assert.Nil(t, err)
  528. assert.Equal(t, 4, num)
  529. _, err = New(client.Addr, badType()).Scard("key")
  530. assert.NotNil(t, err)
  531. val, err := client.Scard("key")
  532. assert.Nil(t, err)
  533. assert.Equal(t, int64(4), val)
  534. _, err = New(client.Addr, badType()).Sismember("key", 2)
  535. assert.NotNil(t, err)
  536. ok, err := client.Sismember("key", 2)
  537. assert.Nil(t, err)
  538. assert.True(t, ok)
  539. _, err = New(client.Addr, badType()).Srem("key", 3, 4)
  540. assert.NotNil(t, err)
  541. num, err = client.Srem("key", 3, 4)
  542. assert.Nil(t, err)
  543. assert.Equal(t, 2, num)
  544. _, err = New(client.Addr, badType()).Smembers("key")
  545. assert.NotNil(t, err)
  546. vals, err := client.Smembers("key")
  547. assert.Nil(t, err)
  548. assert.ElementsMatch(t, []string{"1", "2"}, vals)
  549. _, err = New(client.Addr, badType()).Srandmember("key", 1)
  550. assert.NotNil(t, err)
  551. members, err := client.Srandmember("key", 1)
  552. assert.Nil(t, err)
  553. assert.Len(t, members, 1)
  554. assert.Contains(t, []string{"1", "2"}, members[0])
  555. _, err = New(client.Addr, badType()).Spop("key")
  556. assert.NotNil(t, err)
  557. member, err := client.Spop("key")
  558. assert.Nil(t, err)
  559. assert.Contains(t, []string{"1", "2"}, member)
  560. _, err = New(client.Addr, badType()).Smembers("key")
  561. assert.NotNil(t, err)
  562. vals, err = client.Smembers("key")
  563. assert.Nil(t, err)
  564. assert.NotContains(t, vals, member)
  565. _, err = New(client.Addr, badType()).Sadd("key1", 1, 2, 3, 4)
  566. assert.NotNil(t, err)
  567. num, err = client.Sadd("key1", 1, 2, 3, 4)
  568. assert.Nil(t, err)
  569. assert.Equal(t, 4, num)
  570. num, err = client.Sadd("key2", 2, 3, 4, 5)
  571. assert.Nil(t, err)
  572. assert.Equal(t, 4, num)
  573. _, err = New(client.Addr, badType()).Sunion("key1", "key2")
  574. assert.NotNil(t, err)
  575. vals, err = client.Sunion("key1", "key2")
  576. assert.Nil(t, err)
  577. assert.ElementsMatch(t, []string{"1", "2", "3", "4", "5"}, vals)
  578. _, err = New(client.Addr, badType()).Sunionstore("key3", "key1", "key2")
  579. assert.NotNil(t, err)
  580. num, err = client.Sunionstore("key3", "key1", "key2")
  581. assert.Nil(t, err)
  582. assert.Equal(t, 5, num)
  583. _, err = New(client.Addr, badType()).Sdiff("key1", "key2")
  584. assert.NotNil(t, err)
  585. vals, err = client.Sdiff("key1", "key2")
  586. assert.Nil(t, err)
  587. assert.EqualValues(t, []string{"1"}, vals)
  588. _, err = New(client.Addr, badType()).Sdiffstore("key4", "key1", "key2")
  589. assert.NotNil(t, err)
  590. num, err = client.Sdiffstore("key4", "key1", "key2")
  591. assert.Nil(t, err)
  592. assert.Equal(t, 1, num)
  593. })
  594. }
  595. func TestRedis_SetGetDel(t *testing.T) {
  596. runOnRedis(t, func(client *Redis) {
  597. err := New(client.Addr, badType()).Set("hello", "world")
  598. assert.NotNil(t, err)
  599. err = client.Set("hello", "world")
  600. assert.Nil(t, err)
  601. _, err = New(client.Addr, badType()).Get("hello")
  602. assert.NotNil(t, err)
  603. val, err := client.Get("hello")
  604. assert.Nil(t, err)
  605. assert.Equal(t, "world", val)
  606. ret, err := client.Del("hello")
  607. assert.Nil(t, err)
  608. assert.Equal(t, 1, ret)
  609. })
  610. }
  611. func TestRedis_SetExNx(t *testing.T) {
  612. runOnRedis(t, func(client *Redis) {
  613. err := New(client.Addr, badType()).Setex("hello", "world", 5)
  614. assert.NotNil(t, err)
  615. err = client.Setex("hello", "world", 5)
  616. assert.Nil(t, err)
  617. _, err = New(client.Addr, badType()).Setnx("hello", "newworld")
  618. assert.NotNil(t, err)
  619. ok, err := client.Setnx("hello", "newworld")
  620. assert.Nil(t, err)
  621. assert.False(t, ok)
  622. ok, err = client.Setnx("newhello", "newworld")
  623. assert.Nil(t, err)
  624. assert.True(t, ok)
  625. val, err := client.Get("hello")
  626. assert.Nil(t, err)
  627. assert.Equal(t, "world", val)
  628. val, err = client.Get("newhello")
  629. assert.Nil(t, err)
  630. assert.Equal(t, "newworld", val)
  631. ttl, err := client.Ttl("hello")
  632. assert.Nil(t, err)
  633. assert.True(t, ttl > 0)
  634. _, err = New(client.Addr, badType()).SetnxEx("newhello", "newworld", 5)
  635. assert.NotNil(t, err)
  636. ok, err = client.SetnxEx("newhello", "newworld", 5)
  637. assert.Nil(t, err)
  638. assert.False(t, ok)
  639. num, err := client.Del("newhello")
  640. assert.Nil(t, err)
  641. assert.Equal(t, 1, num)
  642. ok, err = client.SetnxEx("newhello", "newworld", 5)
  643. assert.Nil(t, err)
  644. assert.True(t, ok)
  645. val, err = client.Get("newhello")
  646. assert.Nil(t, err)
  647. assert.Equal(t, "newworld", val)
  648. })
  649. }
  650. func TestRedis_SetGetDelHashField(t *testing.T) {
  651. runOnRedis(t, func(client *Redis) {
  652. err := client.Hset("key", "field", "value")
  653. assert.Nil(t, err)
  654. _, err = New(client.Addr, badType()).Hget("key", "field")
  655. assert.NotNil(t, err)
  656. val, err := client.Hget("key", "field")
  657. assert.Nil(t, err)
  658. assert.Equal(t, "value", val)
  659. _, err = New(client.Addr, badType()).Hexists("key", "field")
  660. assert.NotNil(t, err)
  661. ok, err := client.Hexists("key", "field")
  662. assert.Nil(t, err)
  663. assert.True(t, ok)
  664. _, err = New(client.Addr, badType()).Hdel("key", "field")
  665. assert.NotNil(t, err)
  666. ret, err := client.Hdel("key", "field")
  667. assert.Nil(t, err)
  668. assert.True(t, ret)
  669. ok, err = client.Hexists("key", "field")
  670. assert.Nil(t, err)
  671. assert.False(t, ok)
  672. })
  673. }
  674. func TestRedis_SortedSet(t *testing.T) {
  675. runOnRedis(t, func(client *Redis) {
  676. ok, err := client.Zadd("key", 1, "value1")
  677. assert.Nil(t, err)
  678. assert.True(t, ok)
  679. ok, err = client.Zadd("key", 2, "value1")
  680. assert.Nil(t, err)
  681. assert.False(t, ok)
  682. val, err := client.Zscore("key", "value1")
  683. assert.Nil(t, err)
  684. assert.Equal(t, int64(2), val)
  685. _, err = New(client.Addr, badType()).Zincrby("key", 3, "value1")
  686. assert.NotNil(t, err)
  687. val, err = client.Zincrby("key", 3, "value1")
  688. assert.Nil(t, err)
  689. assert.Equal(t, int64(5), val)
  690. _, err = New(client.Addr, badType()).Zscore("key", "value1")
  691. assert.NotNil(t, err)
  692. val, err = client.Zscore("key", "value1")
  693. assert.Nil(t, err)
  694. assert.Equal(t, int64(5), val)
  695. _, err = New(client.Addr, badType()).Zadds("key")
  696. assert.NotNil(t, err)
  697. val, err = client.Zadds("key", Pair{
  698. Key: "value2",
  699. Score: 6,
  700. }, Pair{
  701. Key: "value3",
  702. Score: 7,
  703. })
  704. assert.Nil(t, err)
  705. assert.Equal(t, int64(2), val)
  706. _, err = New(client.Addr, badType()).ZRevRangeWithScores("key", 1, 3)
  707. assert.NotNil(t, err)
  708. pairs, err := client.ZRevRangeWithScores("key", 1, 3)
  709. assert.Nil(t, err)
  710. assert.EqualValues(t, []Pair{
  711. {
  712. Key: "value2",
  713. Score: 6,
  714. },
  715. {
  716. Key: "value1",
  717. Score: 5,
  718. },
  719. }, pairs)
  720. rank, err := client.Zrank("key", "value2")
  721. assert.Nil(t, err)
  722. assert.Equal(t, int64(1), rank)
  723. rank, err = client.Zrevrank("key", "value1")
  724. assert.Nil(t, err)
  725. assert.Equal(t, int64(2), rank)
  726. _, err = New(client.Addr, badType()).Zrank("key", "value4")
  727. assert.NotNil(t, err)
  728. _, err = client.Zrank("key", "value4")
  729. assert.Equal(t, Nil, err)
  730. _, err = New(client.Addr, badType()).Zrem("key", "value2", "value3")
  731. assert.NotNil(t, err)
  732. num, err := client.Zrem("key", "value2", "value3")
  733. assert.Nil(t, err)
  734. assert.Equal(t, 2, num)
  735. ok, err = client.Zadd("key", 6, "value2")
  736. assert.Nil(t, err)
  737. assert.True(t, ok)
  738. ok, err = client.Zadd("key", 7, "value3")
  739. assert.Nil(t, err)
  740. assert.True(t, ok)
  741. ok, err = client.Zadd("key", 8, "value4")
  742. assert.Nil(t, err)
  743. assert.True(t, ok)
  744. _, err = New(client.Addr, badType()).Zremrangebyscore("key", 6, 7)
  745. assert.NotNil(t, err)
  746. num, err = client.Zremrangebyscore("key", 6, 7)
  747. assert.Nil(t, err)
  748. assert.Equal(t, 2, num)
  749. ok, err = client.Zadd("key", 6, "value2")
  750. assert.Nil(t, err)
  751. assert.True(t, ok)
  752. _, err = New(client.Addr, badType()).Zadd("key", 7, "value3")
  753. assert.NotNil(t, err)
  754. ok, err = client.Zadd("key", 7, "value3")
  755. assert.Nil(t, err)
  756. assert.True(t, ok)
  757. _, err = New(client.Addr, badType()).Zcount("key", 6, 7)
  758. assert.NotNil(t, err)
  759. num, err = client.Zcount("key", 6, 7)
  760. assert.Nil(t, err)
  761. assert.Equal(t, 2, num)
  762. _, err = New(client.Addr, badType()).Zremrangebyrank("key", 1, 2)
  763. assert.NotNil(t, err)
  764. num, err = client.Zremrangebyrank("key", 1, 2)
  765. assert.Nil(t, err)
  766. assert.Equal(t, 2, num)
  767. _, err = New(client.Addr, badType()).Zcard("key")
  768. assert.NotNil(t, err)
  769. card, err := client.Zcard("key")
  770. assert.Nil(t, err)
  771. assert.Equal(t, 2, card)
  772. _, err = New(client.Addr, badType()).Zrange("key", 0, -1)
  773. assert.NotNil(t, err)
  774. vals, err := client.Zrange("key", 0, -1)
  775. assert.Nil(t, err)
  776. assert.EqualValues(t, []string{"value1", "value4"}, vals)
  777. _, err = New(client.Addr, badType()).Zrevrange("key", 0, -1)
  778. assert.NotNil(t, err)
  779. vals, err = client.Zrevrange("key", 0, -1)
  780. assert.Nil(t, err)
  781. assert.EqualValues(t, []string{"value4", "value1"}, vals)
  782. _, err = New(client.Addr, badType()).ZrangeWithScores("key", 0, -1)
  783. assert.NotNil(t, err)
  784. pairs, err = client.ZrangeWithScores("key", 0, -1)
  785. assert.Nil(t, err)
  786. assert.EqualValues(t, []Pair{
  787. {
  788. Key: "value1",
  789. Score: 5,
  790. },
  791. {
  792. Key: "value4",
  793. Score: 8,
  794. },
  795. }, pairs)
  796. _, err = New(client.Addr, badType()).ZrangebyscoreWithScores("key", 5, 8)
  797. assert.NotNil(t, err)
  798. pairs, err = client.ZrangebyscoreWithScores("key", 5, 8)
  799. assert.Nil(t, err)
  800. assert.EqualValues(t, []Pair{
  801. {
  802. Key: "value1",
  803. Score: 5,
  804. },
  805. {
  806. Key: "value4",
  807. Score: 8,
  808. },
  809. }, pairs)
  810. _, err = New(client.Addr, badType()).ZrangebyscoreWithScoresAndLimit(
  811. "key", 5, 8, 1, 1)
  812. assert.NotNil(t, err)
  813. pairs, err = client.ZrangebyscoreWithScoresAndLimit("key", 5, 8, 1, 1)
  814. assert.Nil(t, err)
  815. assert.EqualValues(t, []Pair{
  816. {
  817. Key: "value4",
  818. Score: 8,
  819. },
  820. }, pairs)
  821. pairs, err = client.ZrangebyscoreWithScoresAndLimit("key", 5, 8, 1, 0)
  822. assert.Nil(t, err)
  823. assert.Equal(t, 0, len(pairs))
  824. _, err = New(client.Addr, badType()).ZrevrangebyscoreWithScores("key", 5, 8)
  825. assert.NotNil(t, err)
  826. pairs, err = client.ZrevrangebyscoreWithScores("key", 5, 8)
  827. assert.Nil(t, err)
  828. assert.EqualValues(t, []Pair{
  829. {
  830. Key: "value4",
  831. Score: 8,
  832. },
  833. {
  834. Key: "value1",
  835. Score: 5,
  836. },
  837. }, pairs)
  838. _, err = New(client.Addr, badType()).ZrevrangebyscoreWithScoresAndLimit(
  839. "key", 5, 8, 1, 1)
  840. assert.NotNil(t, err)
  841. pairs, err = client.ZrevrangebyscoreWithScoresAndLimit("key", 5, 8, 1, 1)
  842. assert.Nil(t, err)
  843. assert.EqualValues(t, []Pair{
  844. {
  845. Key: "value1",
  846. Score: 5,
  847. },
  848. }, pairs)
  849. pairs, err = client.ZrevrangebyscoreWithScoresAndLimit("key", 5, 8, 1, 0)
  850. assert.Nil(t, err)
  851. assert.Equal(t, 0, len(pairs))
  852. _, err = New(client.Addr, badType()).Zrevrank("key", "value")
  853. assert.NotNil(t, err)
  854. client.Zadd("second", 2, "aa")
  855. client.Zadd("third", 3, "bbb")
  856. val, err = client.Zunionstore("union", ZStore{
  857. Weights: []float64{1, 2},
  858. Aggregate: "SUM",
  859. }, "second", "third")
  860. assert.Nil(t, err)
  861. assert.Equal(t, int64(2), val)
  862. _, err = New(client.Addr, badType()).Zunionstore("union", ZStore{})
  863. assert.NotNil(t, err)
  864. vals, err = client.Zrange("union", 0, 10000)
  865. assert.Nil(t, err)
  866. assert.EqualValues(t, []string{"aa", "bbb"}, vals)
  867. ival, err := client.Zcard("union")
  868. assert.Nil(t, err)
  869. assert.Equal(t, 2, ival)
  870. })
  871. }
  872. func TestRedis_Pipelined(t *testing.T) {
  873. runOnRedis(t, func(client *Redis) {
  874. assert.NotNil(t, New(client.Addr, badType()).Pipelined(func(pipeliner Pipeliner) error {
  875. return nil
  876. }))
  877. err := client.Pipelined(
  878. func(pipe Pipeliner) error {
  879. pipe.Incr("pipelined_counter")
  880. pipe.Expire("pipelined_counter", time.Hour)
  881. pipe.ZAdd("zadd", Z{Score: 12, Member: "zadd"})
  882. return nil
  883. },
  884. )
  885. assert.Nil(t, err)
  886. _, err = New(client.Addr, badType()).Ttl("pipelined_counter")
  887. assert.NotNil(t, err)
  888. ttl, err := client.Ttl("pipelined_counter")
  889. assert.Nil(t, err)
  890. assert.Equal(t, 3600, ttl)
  891. value, err := client.Get("pipelined_counter")
  892. assert.Nil(t, err)
  893. assert.Equal(t, "1", value)
  894. score, err := client.Zscore("zadd", "zadd")
  895. assert.Nil(t, err)
  896. assert.Equal(t, int64(12), score)
  897. })
  898. }
  899. func TestRedisString(t *testing.T) {
  900. runOnRedis(t, func(client *Redis) {
  901. client.Ping()
  902. _, err := getRedis(NewRedis(client.Addr, ClusterType))
  903. assert.Nil(t, err)
  904. assert.Equal(t, client.Addr, client.String())
  905. assert.NotNil(t, New(client.Addr, badType()).Ping())
  906. })
  907. }
  908. func TestRedisScriptLoad(t *testing.T) {
  909. runOnRedis(t, func(client *Redis) {
  910. client.Ping()
  911. _, err := New(client.Addr, badType()).ScriptLoad("foo")
  912. assert.NotNil(t, err)
  913. _, err = client.ScriptLoad("foo")
  914. assert.NotNil(t, err)
  915. })
  916. }
  917. func TestRedisEvalSha(t *testing.T) {
  918. runOnRedis(t, func(client *Redis) {
  919. client.Ping()
  920. scriptHash, err := client.ScriptLoad(`return redis.call("EXISTS", KEYS[1])`)
  921. assert.Nil(t, err)
  922. result, err := client.EvalSha(scriptHash, []string{"key1"})
  923. assert.Nil(t, err)
  924. assert.Equal(t, int64(0), result)
  925. })
  926. }
  927. func TestRedisToPairs(t *testing.T) {
  928. pairs := toPairs([]red.Z{
  929. {
  930. Member: 1,
  931. Score: 1,
  932. },
  933. {
  934. Member: 2,
  935. Score: 2,
  936. },
  937. })
  938. assert.EqualValues(t, []Pair{
  939. {
  940. Key: "1",
  941. Score: 1,
  942. },
  943. {
  944. Key: "2",
  945. Score: 2,
  946. },
  947. }, pairs)
  948. }
  949. func TestRedisToStrings(t *testing.T) {
  950. vals := toStrings([]interface{}{1, 2})
  951. assert.EqualValues(t, []string{"1", "2"}, vals)
  952. }
  953. func TestRedisBlpop(t *testing.T) {
  954. runOnRedis(t, func(client *Redis) {
  955. client.Ping()
  956. var node mockedNode
  957. _, err := client.Blpop(nil, "foo")
  958. assert.NotNil(t, err)
  959. _, err = client.Blpop(node, "foo")
  960. assert.NotNil(t, err)
  961. })
  962. }
  963. func TestRedisBlpopEx(t *testing.T) {
  964. runOnRedis(t, func(client *Redis) {
  965. client.Ping()
  966. var node mockedNode
  967. _, _, err := client.BlpopEx(nil, "foo")
  968. assert.NotNil(t, err)
  969. _, _, err = client.BlpopEx(node, "foo")
  970. assert.NotNil(t, err)
  971. })
  972. }
  973. func TestRedisGeo(t *testing.T) {
  974. runOnRedis(t, func(client *Redis) {
  975. client.Ping()
  976. geoLocation := []*GeoLocation{{Longitude: 13.361389, Latitude: 38.115556, Name: "Palermo"}, {Longitude: 15.087269, Latitude: 37.502669, Name: "Catania"}}
  977. v, err := client.GeoAdd("sicily", geoLocation...)
  978. assert.Nil(t, err)
  979. assert.Equal(t, int64(2), v)
  980. v2, err := client.GeoDist("sicily", "Palermo", "Catania", "m")
  981. assert.Nil(t, err)
  982. assert.Equal(t, 166274, int(v2))
  983. // GeoHash not support
  984. v3, err := client.GeoPos("sicily", "Palermo", "Catania")
  985. assert.Nil(t, err)
  986. assert.Equal(t, int64(v3[0].Longitude), int64(13))
  987. assert.Equal(t, int64(v3[0].Latitude), int64(38))
  988. assert.Equal(t, int64(v3[1].Longitude), int64(15))
  989. assert.Equal(t, int64(v3[1].Latitude), int64(37))
  990. v4, err := client.GeoRadius("sicily", 15, 37, &red.GeoRadiusQuery{WithDist: true, Unit: "km", Radius: 200})
  991. assert.Nil(t, err)
  992. assert.Equal(t, int64(v4[0].Dist), int64(190))
  993. assert.Equal(t, int64(v4[1].Dist), int64(56))
  994. geoLocation2 := []*GeoLocation{{Longitude: 13.583333, Latitude: 37.316667, Name: "Agrigento"}}
  995. v5, err := client.GeoAdd("sicily", geoLocation2...)
  996. assert.Nil(t, err)
  997. assert.Equal(t, int64(1), v5)
  998. v6, err := client.GeoRadiusByMember("sicily", "Agrigento", &red.GeoRadiusQuery{Unit: "km", Radius: 100})
  999. assert.Nil(t, err)
  1000. assert.Equal(t, v6[0].Name, "Agrigento")
  1001. assert.Equal(t, v6[1].Name, "Palermo")
  1002. })
  1003. }
  1004. func TestRedis_WithPass(t *testing.T) {
  1005. runOnRedis(t, func(client *Redis) {
  1006. err := NewRedis(client.Addr, NodeType, "any").Ping()
  1007. assert.NotNil(t, err)
  1008. })
  1009. }
  1010. func runOnRedis(t *testing.T, fn func(client *Redis)) {
  1011. s, err := miniredis.Run()
  1012. assert.Nil(t, err)
  1013. defer func() {
  1014. client, err := clientManager.GetResource(s.Addr(), func() (io.Closer, error) {
  1015. return nil, errors.New("should already exist")
  1016. })
  1017. if err != nil {
  1018. t.Error(err)
  1019. }
  1020. if client != nil {
  1021. client.Close()
  1022. }
  1023. }()
  1024. fn(NewRedis(s.Addr(), NodeType))
  1025. }
  1026. func runOnRedisTLS(t *testing.T, fn func(client *Redis)) {
  1027. s, err := miniredis.RunTLS(&tls.Config{
  1028. Certificates: make([]tls.Certificate, 1),
  1029. InsecureSkipVerify: true,
  1030. })
  1031. assert.Nil(t, err)
  1032. defer func() {
  1033. client, err := clientManager.GetResource(s.Addr(), func() (io.Closer, error) {
  1034. return nil, errors.New("should already exist")
  1035. })
  1036. if err != nil {
  1037. t.Error(err)
  1038. }
  1039. if client != nil {
  1040. client.Close()
  1041. }
  1042. }()
  1043. fn(New(s.Addr(), WithTLS()))
  1044. }
  1045. func badType() Option {
  1046. return func(r *Redis) {
  1047. r.Type = "bad"
  1048. }
  1049. }
  1050. type mockedNode struct {
  1051. RedisNode
  1052. }
  1053. func (n mockedNode) BLPop(timeout time.Duration, keys ...string) *red.StringSliceCmd {
  1054. return red.NewStringSliceCmd("foo", "bar")
  1055. }