Skip to main content

Keys

Retrieves keys matching a pattern.

  • Parameters:
    • pattern: Optional SQL LIKE pattern to match keys. Defaults to "%" which matches all keys.
  • Returns:
    • The result of the operation, includes an array of matching keys or an error if the operation failed.
// Get all keys with result type handling
const result = db.keys();
if (result.success) {
console.log(result.data);
} else {
console.log(result.error.message);
}

// Get all keys
const allKeys = db.keys();

// Get keys starting with "user:"
const userKeys = db.keys("user:%");

// Get keys with exactly 5 characters
const fiveCharKeys = db.keys("_____");

// Get keys starting with "log", followed by exactly two characters, and ending with any number of characters
const logKeys = db.keys("log__:%");