Cache lookup
Read a cached string by its cache key.
Redis · Command
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.
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.
GET key| Name | Type | Description |
|---|---|---|
key | key | The name of the key whose string value should be retrieved. |
The string value stored at the key; nil when the key does not exist; an error if the stored value is not a string.
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.
Read a cached string by its cache key.
Fetch a previously stored session token or identifier.
Check whether a string key currently has a value.
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.
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.
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.
SETHGETGETDELGETEX