redis/get

Get Key Value

Retrieve the string value stored at a key.

redis
string
basic
read

Command

GET key

Explanation

The GET command fetches the value of a key. If the key doesn’t exist, Redis returns `(nil)` instead of an error. This is one of the most commonly used commands for reading string data. It can be used in conjunction with other operations to build caching and lookup systems.

Common Use Cases

  • Retrieving user session data from cache
  • Fetching counters, configuration values, or tokens
  • Reading cached API responses

Best Practices

  • Use descriptive key names to make lookups meaningful
  • Handle `(nil)` responses gracefully in your app logic
  • Avoid frequent polling with GET — consider Pub/Sub for real-time updates

Common Mistakes to Avoid

  • Expecting GET to work on non-string data types like hashes or lists
  • Not handling `(nil)` return properly in application code

Troubleshooting

Problem: GET returns nil unexpectedly

Solution: Verify the key exists using `EXISTS key`.

Problem: Wrong data format retrieved

Solution: Ensure consistent serialization/deserialization across writes and reads.

Examples

Retrieve value stored in key 'name'

GET name

Get JSON-like session data for a specific user

GET session:user123