Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Redis · Command

GET

GET returns the string value stored at a key. It returns nil for a missing key and errors when the key contains a non-string value.

Since
Redis Open Source 1.0.0

How it works

GET looks up one key and returns its stored string value. A missing key produces nil, while a key containing a non-string value causes an error because GET supports strings only.

Syntax

GET key

Parameters

NameTypeDescription
keykeyThe name of the key whose string value should be retrieved.

Returns

The string value stored at the key; nil when the key does not exist; an error if the stored value is not a string.

Key points

  • GET retrieves the value associated with the specified key.
  • A missing key is represented by a nil reply.
  • The command is intended for Redis String values, not every Redis data type.
  • Its ACL categories identify it as a read operation for strings with fast classification.
  • Redis introduced GET in Redis Open Source 1.0.0.

Common mistakes

  • GET cannot read a key whose value has another Redis data type; use the command appropriate for that type.

Example: Read a string value

redis-cli SET user:42:name Ada
redis-cli GET user:42:name
# "Ada"

Stores a string and then retrieves it by key using the Redis command-line client.

When to use it

Cache lookup

Read a cached string by its cache key.

Session and token retrieval

Fetch a previously stored session token or identifier.

Existence-aware reads

Check whether a string key currently has a value.

Interview questions

QWhat does GET return when the key does not exist, and what is its complexity?

GET has O(1) time complexity and belongs to the read, string, and fast ACL categories. It returns the string stored at the requested key, or nil when that key is absent.

Follow-up: What happens when the key contains a list? GET returns an error because it only handles string values.

QWhat argument does GET require and what kind of reply does it produce?

The command accepts one required argument, key, which identifies the value to retrieve. The result is a bulk string reply when the key exists, or nil for a missing key.

Follow-up: How would you retrieve a hash instead? Use a hash-specific command such as HGET, supplying the key and field.

QWhat is the command syntax and when was GET introduced?

GET is available since Redis Open Source 1.0.0. Its syntax is GET key, and it reads rather than modifies the stored value.

Follow-up: How can a value be written before reading it? Use SET with the key and string value, then call GET with that key.

  • SET
  • HGET
  • GETDEL
  • GETEX

Source: GET | Docs. Checked 2026-10-16.