Is there any way to match keys aligned reg pattern ^[0-9A-Za-z_-]{80}$?
maomaomqiu opened this issue · 8 comments
Hi,
I use below scripts to enumerate keys like -
ZvNQasfj6U6joJUqFopU6xpzqUaoCfdHhvrqMm50lj5UQ0pMMUZFRE1IODNMRDlJNDhLTVNNUFI4My4u
string pattern = "^[0-9A-Za-z_-]{80}$";
await using var keys = server.KeysAsync(pattern: pattern).GetAsyncEnumerator();
Unluckily there find NO keys (Actually those kind of keys exist), I also try with pattern "[0-9A-Za-z_-]{80}", still no work,
Could anyone help suggest proper pattern?
I try workaround like "Z[0-9A-Za-z_-]{79}$"
, still no work
redis pattern matching for keys
/scan
is not regex - it is glob; the only multiplicity support is ?
(any single) vs *
(any multiple); untested, but if it needs to be exactly 80, maybe you could try [0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-]
(etc, 80 of them)
alternatively, you could perhaps use a glob pattern to do a broad filter, and then apply a secondary regex in the C# code as a fine filter, i.e.
await foreach (var key in server.KeysAsync(pattern: pattern))
{
if (someRegex.IsMatch(key))
{
// more code
}
}
just to clarify: the server limitations are out of our hands - if you want to advocate for having regex support for keys/scan, that would be a topic for https://github.com/redis/redis
Thanks @mgravell , I already try [0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-][0-9A-Za-z_-]
, not work
Another question, will ???..
be heavy cost to redis server? @mgravell
I try ???
, it works
Another question, will ???.. be heavy cost to redis server?
You'd have to measure in your environment, but I wouldn't expect it to be particularly expensive
Thanks @mgravell , love you!