I hava an application for store some data to redis and retrieve its. When i use timetolive annotation a field and when i set a value to it redis-cli couldn not show timeout. My Configuration class;

@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);
    }

} 

My Entity;

@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;

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

How can i resolve this issue?

0 Answers