键空间
键空间定义用于为 Redis 哈希创建实际键的前缀。
默认情况下,前缀设置为 。
您可以通过在聚合根级别进行设置或通过设置编程配置来更改此默认值。
但是,带 Comments 的键空间将取代任何其他配置。getClass().getName()
@RedisHash
以下示例显示如何使用 annotation 设置键空间配置:@EnableRedisRepositories
示例 1.Keyspace 设置
@EnableRedisRepositories
@Configuration
@EnableRedisRepositories(keyspaceConfiguration = MyKeyspaceConfiguration.class)
public class ApplicationConfig {
//... RedisConnectionFactory and RedisTemplate Bean definitions omitted
public static class MyKeyspaceConfiguration extends KeyspaceConfiguration {
@Override
protected Iterable<KeyspaceSettings> initialConfiguration() {
return Collections.singleton(new KeyspaceSettings(Person.class, "people"));
}
}
}
以下示例演示如何以编程方式设置键空间:
示例 2.编程 Keyspace 设置
@Configuration
@EnableRedisRepositories
public class ApplicationConfig {
//... RedisConnectionFactory and RedisTemplate Bean definitions omitted
@Bean
public RedisMappingContext keyValueMappingContext() {
return new RedisMappingContext(
new MappingConfiguration(new IndexConfiguration(), new MyKeyspaceConfiguration()));
}
public static class MyKeyspaceConfiguration extends KeyspaceConfiguration {
@Override
protected Iterable<KeyspaceSettings> initialConfiguration() {
return Collections.singleton(new KeyspaceSettings(Person.class, "people"));
}
}
}