Pattern Matching
MiftahDB provides powerful pattern matching capabilities for working with keys. You can use patterns in multiple methods, such as:
db.keys(pattern)
db.pagination(limit, page, pattern)
db.count(pattern)
db.countExpired(pattern)
The pattern syntax follows SQL-like wildcard matching:
%
: Matches any sequence of characters (including none)._
: Matches exactly one character.
// Match keys starting with "user:"
db.keys("user:%");
// Match keys ending with "osama"
db.keys("%osama");
// Match keys starting with "osama" and ending with any number of characters
db.keys("osama%");
// Match keys that are exactly 3 characters long
db.keys("___");
// Combine patterns: Match keys starting with "log", followed by exactly two characters, and ending with any number of characters
db.keys("log__:%");