Introduction
Redis stores data as simple pairs of keys and values. This makes it very fast and easy to find information.
Redis stores data as simple pairs of keys and values. This makes it very fast and easy to find information.
SET key value GET key
SET user:1001 "John Doe" GET user:1001
SET page_views 150
GET page_viewsThis example saves the status "active" for a session with ID "abc123" and then retrieves it.
SET session:abc123 "active"
GET session:abc123Keys should be unique to avoid overwriting data.
Use meaningful key names to keep your data organized.
Redis values can be more than strings, but key-value is the simplest model.
Redis stores data as key-value pairs for fast access.
Keys are unique names; values hold the data.
This model is great for caching, sessions, and counters.
user:1 with value John?SET key value.SET counter 10 INCR counter GET counterWhat will be the output of the last command?
SET counter 10 sets the key counter to string "10". Then, INCR counter increments the numeric value by 1.INCR mykey but get an error. Which of the following is the most likely cause?mykey is not an integer -> Option Dsession:{session_id} with the session data as the value uses a unique key pattern with session IDs, which is best practice. Store all sessions in a single key as a JSON string stores all sessions in one key, making access slow and complex. Use the same key session for all users and overwrite values overwrites data. Store session data as keys and user IDs as values reverses key-value roles, which is inefficient.session:{session_id} with the session data as the value -> Option APass the test and this pattern moves unknown