Troubling to specify dynamic env variable in the model class @Hashkey Redis annotation.
Model:
@RedisHash("${spring.redis.namespace}:Book")
public class Book {
@Id
private String id;
private String name;
}
My application.properties file:
spring.redis.namespace=local
The resulting key is "${spring.redis.namespace}:Book" instead of local:Book
Could anyone help me with this?
Please use Keyspaces to do it. There two ways. I use one way to finish your requirement.
@Configuration
@EnableRedisRepositories(keyspaceConfiguration = MyKeyspaceConfiguration.class)
public class ApplicationConfig {
@Value("${spring.redis.namespace}:Book")
String myKey;
//... RedisConnectionFactory and RedisTemplate Bean definitions omitted
public static class MyKeyspaceConfiguration extends KeyspaceConfiguration {
@Override
protected Iterable<KeyspaceSettings> initialConfiguration() {
return Collections.singleton(new KeyspaceSettings(Book.class, myKey));
}
}
}