How can I find the count of all the keys that has a matching pattern.
For example, there are two keys abc:random-text-1
and abc:random-text-2
.
If it's a one-time thing, you can use KEYS as described by x_maras, but you shouldn't use that in your code since KEYS will scan every key in the entire database each time it's called.
If you want to do it frequently, there is no "good" way exactly as you've written because it will always be fairly inefficient to scan every key (even using SCAN, since it would be doing the same thing as KEYS just in a safer manner).
However, if the patterns you need are known ahead of time, you can keep a set of every key that matches the pattern.
SET abc:random-text-1 "blah"
SADD patterns:abc abc:randomtext-1
SET abc:random-text-2 "more blah"
SADD patterns:abc abc:randomtext-2
SCARD patterns:abc
// (integer) 2
SORT patterns:abc BY nosort GET *
// 1) "blah"
// 2) "more blah"