Why Redis Has 16384 Slots?

Redis is an open source, in-memory data structure store, used as a database, cache, and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, and geospatial indexes with radius queries.

Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.

 Exclusive Slots & Free Spins Offers: 

In this article we will be discussing one of the more unique aspects of Redis – it’s slot system. Redis uses a concept called consistent hashing to map keys to slots.

This is different from the more commonly used approach of hashing by modulus where each key is hashed and the resulting hash is used to determine which slot the key falls into. .

With consistent hashing, each slot is mapped to a point on a ring. The ring is initialized with a random number of points (slots).

When a key is hashed, it too is mapped to a point on the ring. The key is then stored in the slot whose point is clockwise closest to the key’s point. So if we have a ring with 8 slots and we hash the key “foo” to point 500 on the ring, “foo” will be stored in slot 6 because it is clockwise closest to 500: .

400–500–600
|
|
200–300–350–450–550–650–750–850–950–1050–1150–1200 |
| |
| 1800–1900 |
| | |
| | |
1600————————————————1700————–2000

Redis’ use of consistent hashing allows for great flexibility when adding or removing slots from the cluster as there isn’t any need to re-hash all keys. This means that Redis can easily scale horizontally.