Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can select dbIndex when I use RedisTemplate in Spring-Data-Redis?

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?

like image 841
Eiven Avatar asked Oct 24 '25 03:10

Eiven


1 Answers

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;
  }
like image 131
lucid Avatar answered Oct 26 '25 16:10

lucid