How do I get list of keys/values using Booksleeve?

287 views Asked by At

I'm trying to get a list of values, where key name starts with let's say "monkey".

I really couldn't find a doc on this. :(

How can I do this? What API should I use? Keys, Sets, Strings? What method?

Or it is not available yet, but a workaround?

Thanks

1

There are 1 answers

0
Marc Gravell On

Redis does not have a "get all keys like {x} along with their values" command, but it does have:

  • get all keys like {x}
  • get value of key / keys

Whether your approach is sensible in the first place depends a bit on which server version you are using. If you are on a recent version then the library will use SCAN, which is not terrible. On older server versions it will use KEYS, which is to be avoided at all costs. I am not at a PC so this is pseudo-code only, but:

foreach(var batch in db.GetKeys("monkey*")
    .Batchify(100))
{
     list.AddRange(await db.Strings.GetString(batch));
}

Note that this isn't optimized - the batches could be fun much more concurrently than the above - but I would need a keyboard and compiler to demonstrate that!