Bird
Raised Fist0
Redisquery~10 mins

Redis CLI (redis-cli) basics - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Redis CLI (redis-cli) basics
Start redis-cli
↓
Type command
↓
Send command to Redis server
↓
Server processes command
↓
Receive response
↓
Display response
↓
Type next command or exit
This flow shows how redis-cli takes your typed command, sends it to the Redis server, gets the answer, and shows it back to you.
Execution Sample
Redis
redis-cli
> SET name "Alice"
> GET name
> DEL name
This example shows setting a key, getting its value, and deleting the key using redis-cli.
Execution Table
StepCommand EnteredActionServer ResponseOutput Displayed
1redis-cliStart CLI sessionConnected to Redis serverReady for commands
2SET name "Alice"Store key 'name' with value 'Alice'OKOK
3GET nameRetrieve value of key 'name'"Alice""Alice"
4DEL nameDelete key 'name'(integer) 1(integer) 1
5GET nameTry to get deleted key(nil)(nil)
6exitClose CLI sessionConnection closedSession ended
💡 User types 'exit' to end the redis-cli session
Variable Tracker
KeyStartAfter SETAfter DELFinal
namedoes not exist"Alice"deleteddoes not exist
Key Moments - 3 Insights
Why does GET return (nil) after DEL?
Because DEL removed the key 'name', so GET finds no value. See execution_table step 5 where GET returns (nil).
What does the (integer) 1 mean after DEL?
It means one key was deleted successfully. Look at execution_table step 4 where DEL returns (integer) 1.
Why do we see "OK" after SET command?
SET returns "OK" to confirm the key was stored. Check execution_table step 2 for this confirmation.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the output displayed after the GET name command at step 3?
A(nil)
B"Alice"
C"OK"
D(integer) 1
💡 Hint
Check the 'Output Displayed' column at step 3 in the execution_table.
At which step does the key 'name' get deleted?
AStep 4
BStep 3
CStep 2
DStep 5
💡 Hint
Look at the 'Command Entered' and 'Action' columns in the execution_table.
If you try GET name after DEL, what will redis-cli show?
A"Alice"
B"OK"
C(nil)
D(integer) 1
💡 Hint
See execution_table step 5 for the output after GET on a deleted key.
Concept Snapshot
redis-cli basics:
- Start redis-cli to connect to Redis server
- Type commands like SET, GET, DEL
- Server processes and replies
- Responses show success or data
- Use 'exit' to quit CLI
Full Transcript
This visual trace shows how redis-cli works step-by-step. First, you start redis-cli which connects to the Redis server. Then you type commands such as SET to store a key, GET to retrieve it, and DEL to delete it. Each command is sent to the server, which processes it and sends back a response. The CLI displays this response so you see if the command succeeded or what data was returned. For example, after SET name "Alice", the server replies OK. When you GET name, it returns Alice. After DEL name, the key is removed, so GET name returns (nil). Finally, typing exit closes the session. This helps beginners see exactly what happens inside redis-cli as they type commands.

Practice

(1/5)
1. What does the Redis CLI command SET key value do?
easy
A. Retrieves the value of the key
B. Deletes the key from Redis
C. Stores the value under the given key in Redis
D. Lists all keys in Redis

Solution

  1. Step 1: Understand the SET command

    The SET command in Redis stores a value under a specified key.
  2. Step 2: Match command to action

    Since SET assigns a value to a key, it stores data rather than deleting or retrieving it.
  3. Final Answer:

    Stores the value under the given key in Redis -> Option C
  4. Quick Check:

    SET command = store value [OK]
Hint: SET means store a value for a key [OK]
Common Mistakes:
  • Confusing SET with GET
  • Thinking SET deletes keys
  • Assuming SET lists keys
2. Which of the following is the correct syntax to get the value of a key named user1 in Redis CLI?
easy
A. KEYS user1
B. GET user1
C. DEL user1
D. SET user1

Solution

  1. Step 1: Identify the command to retrieve a value

    The GET command is used to fetch the value stored at a key in Redis.
  2. Step 2: Check syntax correctness

    GET followed by the key name is the correct syntax to get the value of 'user1'.
  3. Final Answer:

    GET user1 -> Option B
  4. Quick Check:

    GET command syntax = GET key [OK]
Hint: GET retrieves value, SET stores, DEL deletes [OK]
Common Mistakes:
  • Using SET instead of GET
  • Using DEL to get value
  • Using KEYS to get value
3. What will be the output of the following Redis CLI commands?
SET count 10
INCR count
GET count
medium
A. "11"
B. "10"
C. Error: wrong type operation
D. nil

Solution

  1. Step 1: Analyze the commands step-by-step

    SET count 10 stores the string "10" under key 'count'. INCR count increments the integer value by 1.
  2. Step 2: Understand INCR effect and GET result

    INCR converts the string "10" to integer 10, adds 1 to make 11. GET count returns "11" as a string.
  3. Final Answer:

    "11" -> Option A
  4. Quick Check:

    INCR on "10" = "11" [OK]
Hint: INCR adds 1 to numeric string values [OK]
Common Mistakes:
  • Expecting original value "10"
  • Thinking INCR causes error
  • Expecting nil for existing key
4. You run the command GET mykey but get an error: WRONGTYPE Operation against a key holding the wrong kind of value. What is the likely cause?
medium
A. The key holds a non-string value like a list or set
B. The key does not exist
C. The Redis server is down
D. The GET command is misspelled

Solution

  1. Step 1: Understand the error message

    The error means GET was used on a key that stores a data type other than string, like a list or set.
  2. Step 2: Identify the cause from options

    Since the key exists but is not a string, GET cannot retrieve it, causing the error.
  3. Final Answer:

    The key holds a non-string value like a list or set -> Option A
  4. Quick Check:

    WRONGTYPE error = wrong data type for GET [OK]
Hint: GET works only on string keys, not lists or sets [OK]
Common Mistakes:
  • Thinking key does not exist
  • Assuming server is down
  • Misspelling GET causes this error
5. You want to store a user's name and age in Redis using redis-cli. Which sequence of commands correctly stores the name "Alice" and age 30, then retrieves both values?
hard
A. SET user:name Alice SET user:age 30 HGET user:name HGET user:age
B. LPUSH user Alice 30 LRANGE user 1 1
C. SET user Alice 30 GET user
D. HSET user name Alice age 30 HGET user name HGET user age

Solution

  1. Step 1: Identify the best data structure for multiple fields

    Using a hash (HSET) allows storing multiple fields like name and age under one key.
  2. Step 2: Check commands for storing and retrieving fields

    HSET user name Alice age 30 stores both fields. HGET user name and HGET user age retrieve them separately.
  3. Final Answer:

    HSET user name Alice age 30 HGET user name HGET user age -> Option D
  4. Quick Check:

    Use hashes for multiple related fields [OK]
Hint: Use HSET/HGET for multiple fields in one key [OK]
Common Mistakes:
  • Using SET with multiple values
  • Using list commands for key-value pairs
  • Trying to GET multiple values at once
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard