redis scan returns empty results but nonzero cursor

后端 未结 1 549
囚心锁ツ
囚心锁ツ 2021-01-21 03:55

I have a redis database with a few million keys. Sometimes I need to query keys by the pattern e.g. 2016-04-28:* for which I use scan. First call shoul

1条回答
  •  被撕碎了的回忆
    2021-01-21 04:37

    You'll always need to complete the scan (i.e. get cursor == 0) to be sure there no no matched. You can, however, use the COUNT option to reduce the number of iterations. The default value of 10 is fast If this is a common scenario with your match pattern - start increasing it (e.g. double or powers of two but put a max cap just in case) with every empty reply, to make Redis "search harder" for keys. By doing so, you'll be saving on network round trips so it should "speed things up".

    0 讨论(0)
提交回复
热议问题