Skip to content

Commit 5d8893c

Browse files
committed
RC: Redis hashing policy
1 parent 801741d commit 5d8893c

File tree

1 file changed

+49
-26
lines changed

1 file changed

+49
-26
lines changed

content/operate/rc/databases/configuration/clustering.md

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Redis server.
3838
An instance that belongs to a cluster can manage multiple hash
3939
slots. This division of the key space, known as _sharding_, is achieved by
4040
hashing the key names, or parts of these (key hash tags), in order to
41-
obtain the hash slot in which a key should reside.
41+
obtain the hash slot in which a key should reside. Redis Cloud supports several [hashing policies]().
4242

4343
Even when using multiple Redis processes, the use of a Redis
4444
Enterprise Cloud cluster is nearly transparent to the application that
@@ -86,46 +86,69 @@ are supported, with the following limitations:
8686
and pipelining are supported with Redis Cloud cluster
8787
like if it were a non-cluster DB.
8888

89-
## Manage the hashing policy
89+
## Hashing policies and hash tags {#manage-the-hashing-policy}
9090

91-
Redis defaults to the [standard hashing policy](#standard-hashing-policy).
92-
The clustering configuration of a Redis Cloud instance can be changed.
93-
However, hashing policy changes delete existing data
91+
The hashing policy determines how data is distributed across multiple Redis processes of a database. It uses a hashing function to map keys to hash slots in these processes, ensuring an even distribution of data for optimal performance and scalability.
92+
93+
The hashing function uses the entire key name to calculate the hash slot, unless the key name contains a **hash tag**, represented by a `{...}` pattern.
94+
95+
If the key contains a `{...}` pattern, only the substring between `{` and `}` is hashed in order to obtain the hash slot.
96+
97+
You can use the `{...}` pattern to direct related keys to the same hash slot, so that multi-key operations are supported on them. On the other hand, not using a hashtag in the key's name results in a (statistically) even distribution of keys across the keyspace's shards, which improves resource utilization. If your application does not perform multi-key operations, you don't need to construct key names with hashtags.
98+
99+
Redis Cloud offers 3 hashing policies, which differ in the way hash-tags are processed. Redis defaults to the [standard hashing policy](#standard-hashing-policy).
100+
101+
{{< warning >}}
102+
You can change the hashing policy after you create your database. However, hashing policy changes delete existing data
94103
(FLUSHDB) before they're applied.
95104

96105
These changes include:
97106

98-
1. Changing the hashing policy, either from standard to custom or vice versa.
107+
1. Changing the hashing policy.
99108
1. Changing the order of custom hashing policy rules.
100109
1. Adding rules before existing ones in the custom hashing policy.
101110
1. Deleting rules from the custom hashing policy.
102111
1. Disabling clustering for the database.
112+
{{< /warning >}}
113+
114+
### Redis hashing policy
115+
116+
{{< note >}}
117+
This policy is available for databases created after MONTH DAY, 2025.
118+
{{< /note >}}
119+
120+
The Redis hashing policy is identical to the [hashing policy used by Redis Community Edition]({{< relref "/operate/oss_and_stack/reference/cluster-spec#hash-tags" >}}). This policy is recommended for most users and should be selected if any of the following conditions apply:
121+
- This is your first Redis Cloud account, and you are starting fresh.
122+
- You are migrating data from Redis Community Edition or other Redis-managed platforms.
123+
- Your application does not use hashtags in database key names.
124+
- Your application uses binary data as key names.
103125

104126
### Standard hashing policy
105127

106-
When using the standard hashing policy, a Redis Cloud cluster
107-
behaves like a standard Redis cluster, and hashing is
108-
performed as follows:
109-
110-
1. Keys with a hashtag: a key's hashtag is any substring between '{'
111-
and '}' in the key's name. That means that when a key's name
112-
includes the pattern '{...}', the hashtag is used as input for the
113-
hashing function. For example, the following key names have the same
114-
hashtag and are mapped to the same slot: foo{bar},
115-
{bar}baz & foo{bar}baz.
116-
1. Keys without a hashtag: when a key doesn't contain the '{...}'
117-
pattern, the entire key's name is used for hashing.
118-
119-
You can use the '{...}' pattern to direct related keys to the same hash
120-
slot, so that multi-key operations are supported on them. On the other
121-
hand, not using a hashtag in the key's name results in a
122-
(statistically) even distribution of keys across the keyspace's shards,
123-
which improves resource utilization.
124-
If your application does not perform multi-key operations, you don't
125-
need to construct key names with hashtags.
128+
The Standard hashing policy is mostly consistent with the Redis hashing policy, and will generate the same hash-slot calculation in the following cases:
129+
1. Keys with a single hashtag: a key's hashtag is any substring between '{' and '}' in the key's name. That means that when a key's name includes the pattern '{...}', the hashtag is used as input for the hashing function. For example, the following key names have the same hashtag and are mapped to the same slot: foo{bar}, {bar}baz & foo{bar}baz.
130+
1. Keys without a hashtag: when a key doesn't contain the '{...}' pattern, the entire key's name is used for hashing
131+
132+
However, this policy is less recommended and should be selected only if any of the following conditions apply:
133+
- Your application uses empty hashtags to hash different keys to the same hashslot
134+
- Your application uses multiple curly brackets within a key’s name
135+
136+
In some cases, the Standard hashing policy behaves differently from the Redis hashing policy:
137+
1. Using empty hashtags (“{}”): the Standard hashing policy does not ignore empty hashtags, so 2 keys which start with empty hashtags will be hashed to the same hashslot (while the Redis hashing policy would ignore them).
138+
For example: given 2 keys {}foo and {}bar, hashing would be:
139+
- Standard hashing policy: to the same hash slot
140+
- Redis hashing policy: to different hash slots
141+
2. Using multiple curly brackets: when a key’s name contains multiple curly brackets, the Standard hashing calculation might be different than the Redis hashing policy.
142+
For example: given 2 keys {foo}bar} and {foo}qux}:
143+
- Standard hashing policy: substrings “foo}bar” and “foo}qux” will be used for the 1st and 2nd key respectively, hashed each key to a different hash-slot.
144+
- Redis hashing policy: the substring “foo” will be used for both keys, hashing them to the same slot.
126145

127146
### Custom hashing policy
128147

148+
{{< note >}}
149+
The custom hashing policy is not recommended and will be deprecated in the future. Select this option only if you are already using a custom hashing policy with your existing Redis Cloud databases.
150+
{{< /note >}}
151+
129152
A Redis Cloud cluster can be configured to use a custom hashing
130153
policy. A custom hashing policy is required when different keys need to
131154
be kept together on the same shard to allow multi-key operations. Redis

0 commit comments

Comments
 (0)