Skip to main content




GitHub: - Serverless data for Redis and Kafka

Command cheatsheet:



Top 5 uses of Redis

  • String
    • Session
    • Cache
    • Distributed Lock
  • Int
    • Counter
    • Rate Limiter
    • Global ID
  • Hash
    • Shopping Cart
  • Bitmap
    • User Retention
  • List
    • Message Queue
  • ZSet
    • Rank/Leaderboard

Interesting articles on the docs

Redis patterns example by building a Twitter clone: authentication with a cookie:

Remember that we are only able to access data in a direct way, without secondary indexes. It's not possible to tell Redis to return the key that holds a specific value. This is also our strength. This new paradigm is forcing us to organize data so that everything is accessible by primary key, speaking in relational DB terms.

Use Redis for client-side caching:

VS memcached

Redis may be one of the most overrated system in modern software architecture. Its usefulness may more limited than many people think. First is about caching, people should use memcached instead, because:

  • Redis has external fragmentation, meaning it can theoretically use much more than RAM set by its 'maxmemory'. In the containerized environment it is quite easy for the Redis instances to be killed by the OOM Killer. If you turn on active defrag it will affect the performance of the main core.
  • It is single threaded, that little core can easily be saturated under load: It is weird that a caching systems should protect db against load itself became crumble under high load.
  • If you turned on Redis persistence, because of 'fork' it can double the RAM usage because of Copy On Write. To safely avoid this condition you cannot realistically give Redis more than Half of your system RAM, a very wasteful limitation.

Memcached is designed for caching, so it doesn't have these RAM problems. Even plain old relational databases doesn't have, too.


On macOS, use brew install redis as explained in

Start and stop

brew services start redis
brew services stop redis

# Check the status of the service
brew services info redis

# Restart after a Redis upgrade with Brew
brew services restart redis

CLI redis-cli


Connect to a local instance: redis-cli

Connect to a remote instance:

redis-cli -h <host> -p <port> -a <password>

Default address is and default port is 6379, so doing redis-cli is like doing redis-cli -h -p 6379.

To authenticate, you can alternatively provide the password using the envar REDISCLI_AUTH. You can also connect without specifying the password (ie redis-cli -h <host> -p <port>), but you won't be able to add, change or query data until you run the command AUTH <password> to authenticate.

Test the connection: PING


Get all keys:

  • SCAN. Preferred since it's O(1). Returns a cursor. According to the docs can be used in production without the downside of commands like KEYS or SMEMBERS that may block the server for a long time (even several seconds) when called against big collections of keys or elements. Examples:
    • SCAN 0
    • SCAN 0 MATCH something:*
  • KEYS *. Warning: is O(N).

See discussion at

Get type of key: TYPE <key>. It returns 'none' when the key does not exist.

Delete a key: DEL key1 key2 ....

Data types

Hashes are the ideal data structure to represent objects. For example we use Hashes in order to represent Users and Updates in our Twitter clone.