Show List
Working with keys in Redis
In Redis, keys are used to store and retrieve data. Here's an explanation of some of the ways to work with keys in Redis along with examples:
SET key value: Set a key to hold a string value.
sqlCopy code
SET name "John"
GET key: Get the value of a key.
sqlCopy code
GET name
EXISTS key: Check if a key exists.
sqlCopy code
EXISTS name
DEL key: Delete a key.
cssCopy code
DEL name
INCR key: Increment the value of a key by 1.
sqlCopy code
SET counter 0
INCR counter
EXPIRE key seconds: Set a timeout on a key, after which the key will be automatically deleted.
sqlCopy code
SET session_id "abcd1234"
EXPIRE session_id 3600
KEYS pattern: Return all keys matching a given pattern.
sqlCopy code
SET user:1 name "John"
SET user:2 name "Jane"
KEYS user:*
These are just a few examples of the many ways to work with keys in Redis. Redis offers a wide range of key-based operations, which can be used to build sophisticated applications.
Leave a Comment