Reputation: 43
I'm trying to use Spring-Data-Redis APIs,and want to select dbIndex of redis in RedisTemplate. But I cant find any relevant method in RedisTemplate.java, how can i do this?
Upvotes: 4
Views: 4158
Reputation: 2900
you can set database index using jedisConnectionFactory bean. if you are using xml based config, you can set something like this
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:host-name="server" p:port="6379">
<property name="database" value="required index">
<bean/>
if you are using java based config, you can set like this inside config bean
@Bean
public RedisConnectionFactory connectionFactory() {
// other configuration
JedisConnectionFactory connection = new JedisConnectionFactory();
connection.setDatabase("required db index");
// other config
return connection;
}
Upvotes: 2