idea for keys command

56 views
Skip to first unread message

phpguru

unread,
Feb 24, 2015, 12:24:41 PM2/24/15
to redi...@googlegroups.com
We all know that redis-cli> keys pattern* is expensive; would it be beneficial to add <from> <to> as args, like sets have, so you could do things like paginate through?

redis-cli> keys foo* 0 1 
1) foobar

redis-cli> keys foo* 1 2
1) foobat
2) foobiz

redis-cli> keys foo* 0 3
1) foobar
2) foobat
3) foobiz
4) foobuh

etc.

It was just a random thought. It seems intuitive enough; I'm not a C programmer so I don't know if that would easy or hard to implement or if it would offer any benefit to the expense of the command.

Jan-Erik Rediger

unread,
Feb 24, 2015, 12:41:07 PM2/24/15
to redi...@googlegroups.com
We sorta got this already: SCAN (http://redis.io/commands/scan)
> --
> You received this message because you are subscribed to the Google Groups "Redis DB" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
> To post to this group, send email to redi...@googlegroups.com.
> Visit this group at http://groups.google.com/group/redis-db.
> For more options, visit https://groups.google.com/d/optout.

Matt Palmer

unread,
Feb 24, 2015, 5:24:08 PM2/24/15
to redi...@googlegroups.com
On Tue, Feb 24, 2015 at 09:24:41AM -0800, phpguru wrote:
> We all know that redis-cli> keys pattern* is expensive; would it be
> beneficial to add <from> <to> as args, like sets have, so you could do
> things like paginate through?

No, because the cost of KEYS is almost entirely in the need to scan the entire
keyspace looking for matches. There would be a slight benefit for cases
where you only wanted the first N matches, but that would be tempered by the
"Schlemiel the Painter Algorithm" aspect of the repeated scans for each
pagination request, if you were trying to go through the entire keyspace,
bit by bit.

As has been suggested, if you want to deal with the keyspace bit by bit, use
SCAN.

- Matt

Reply all
Reply to author
Forward
0 new messages