Skip to content

Use Redis Cluster-compatible naming for Redis keys

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

If we were to do Redis sharding (see also #38002 (closed)), we'd want the maximum flexibility in how we do so. The simplest solution to that seems to be to use hash tags in keys: https://redis.io/topics/cluster-spec#keys-hash-tags

TLDR; if a key contains a balance pair of curly braces with content in between them, that content is used for computing the hash slot. Some examples from the docs:

Key Part used for hash
{user1000}.following user1000
{user1000}.followers user1000
foo{}{bar} foo{}{bar}
foo{bar}{zap} bar

Note that we don't have to use Redis Cluster to benefit from this - we could write something ourselves, we could use twemproxy, etc.

This would have benefits event if we didn't shard based on it, as it would give our Redis keys more consistency, making it easier for engineers to understand the context.

Edited by 🤖 GitLab Bot 🤖