Redis Repositories Running on a Cluster

在集群式 Redis 环境中,你可以使用 Redis 存储库支持。有关 ConnectionFactory 配置的详细信息,请参考 “Redis Cluster” 部分。尽管如此,仍需执行一些额外的配置,因为默认键分配会将实体和辅助索引分散到整个集群及其插槽中。

下表显示了有关集群中数据的详细信息(基于前面的示例):

Key Type Slot Node

people:e2c7dcee-b8cd-4424-883e-736ce564363e

id for hash

15171

127.0.0.1:7381

people:a9d4b3a0-50d3-4538-a2fc-f7fc2581ee56

id for hash

7373

127.0.0.1:7380

people:firstname:rand

index

1700

127.0.0.1:7379

当所有涉及的键映射到相同的时隙时,某些命令(如 SINTERSUNION)只能在服务器端处理。否则,必须在客户端完成计算。因此,将键空间固定到某个时隙很有用,这可以立刻利用 Redis 服务器端的计算。下表显示执行此操作时会发生什么(注意时隙列中的更改和节点列中的端口值):

Key Type Slot Node

{people}:e2c7dcee-b8cd-4424-883e-736ce564363e

id for hash

2399

127.0.0.1:7379

{people}:a9d4b3a0-50d3-4538-a2fc-f7fc2581ee56

id for hash

2399

127.0.0.1:7379

{people}:firstname:rand

index

2399

127.0.0.1:7379

使用 @RedisHash("{yourkeyspace}") 为键空间定义别针并将其固定到特定插槽中,当您使用 Redis 集群时。