Introduction
The KEYS command helps find all keys in Redis that match a pattern. It is like searching for files by name on your computer.
KEYS pattern
KEYS user:*
KEYS *session*
KEYS *
SET user:1 Alice SET user:2 Bob SET session:123 active KEYS user:*
KEYS * do?KEYS commandKEYS command searches for keys matching a given pattern.** matches all keys in the current database.KEYS * lists all keys [OK]user:* without quotes to match keys starting with 'user:'.user:1, user:2, admin:1, what is the output of KEYS user:*?user:*user:1 and user:2.admin:1 does not start with 'user:', so it is excluded.KEYS user?*?? matches exactly one character in Redis patterns.user?*? matches exactly one character [OK]KEYS is discouraged in productionKEYS blocks Redis and can cause performance issues on large datasets.SCAN with MATCH for safe iterationSCAN iterates keys incrementally without blocking, using MATCH *session* to filter keys containing 'session'.SCAN 0 MATCH *session* iteratively -> Option BSCAN is safe for production key matching [OK]Pass the test and this pattern moves unknown