无法设置Spring Data Redis TimeToLive

时间:2019-05-13 15:00:34

标签: spring spring-boot redis spring-data-redis

我有一个应用程序,用于将一些数据存储到Redis并检索它。当我使用timetolive注释字段时,当我为其设置值时,redis-cli无法显示超时。我的配置类;

@ComponentScan("com.ykb.frd.fraudbase.entity.redis")
@EnableRedisRepositories(basePackages = "com.ykb.frd.fraudbase.repository.redis")
@Configuration
@PropertySource({"classpath:application.properties"})
public class RedisConfiguration {

    @Autowired
    Environment environment;

    @Bean
    public RedisTemplate<String, Object> redisTemplate() {
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        template.setConnectionFactory(jedisConnectionFactory());
        return template;
    }

    @Bean
    JedisConnectionFactory jedisConnectionFactory() {
        String host = environment.getProperty("redis.host");
        String portStr = environment.getProperty("redis.port");
        int port=6379;
        if(portStr!=null) {
            port=Integer.valueOf(portStr);
        }
        String passwordStr = environment.getProperty("redis.password");
        RedisPassword password = RedisPassword.of(passwordStr);
        RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(host,port);
        redisStandaloneConfiguration.setPassword(password);
        return new JedisConnectionFactory(redisStandaloneConfiguration);
    }

} 

我的实体;

@Getter
@Setter
@RedisHash("userSearch")
public class UserSearchEntity implements Serializable {
    @Id
    @Indexed
    private Integer cifNo;
    private String firstName;
    private String lastName;
    private String tckn;

    @TimeToLive
    private Long expiration;
}

存储库;

@Repository
public interface UserSearchRepository extends CrudRepository<UserSearchEntity,String> {
    UserSearchEntity findByCifNo(Integer cifNo);
}

我该如何解决此问题?

0 个答案:

没有答案