You should work hard to avoid the need to scan the keyspace. KYES
is literally a server stopper, but even if you have SCAN
available: don't do that. Now, you could choose to keep the keys of things you have available in a set somewhere, but there is no SRANGE
etc - in 2. you'd have to use SMEMBERS
, which is still going to need to return a few million records - but at least they will all be available. In later server versions, you have access to SCAN
(think: KEYS
) and SSCAN
(think: SMEMBERS
), but ultimately you simply have the issue of wanting millions of rows, which is never free.
If possible, you could mitigate the impact by using a master/slave pair, and running the expensive operations on the slave. At least other clients will be able to do something while you're killing the server.