从redisteamplet获取详细信息作为列表

时间:2018-06-26 08:48:54

标签: java spring

数据库中的密钥被某些开发人员另存为  获取“ 1234.13.tmpl-seq” “ [\” java.util.ArrayList \“,[12,23]]”

我想使用redisTemplate获取密钥。我正在执行以下

@Repository
public class TemplateRepositoryImpl implements TemplateRepository {

private ValueOperations<String, Object> valueOperations;
 private RedisTemplate<String, Object> redisTemplate;

@Autowired
public TemplateRepositoryImpl(RedisTemplate<String, Object> redisTemplate) {
    this.redisTemplate = redisTemplate;
}

@PostConstruct
private void init() {
    valueOperations = this.redisTemplate.opsForValue();

}

@Override
public String getTemplateSequenceinString(String key) {
    System.out.println("the key recieved is " + key);
    return (String) valueOperations.get(key);
}

}

配置类

 @Configuration
public class AppConfig {

@Bean
public RedisTemplate<String, Object> redisObjectemplate(RedisConnectionFactory connectionFactory) {
    RedisTemplate<String, Object> template = new RedisTemplate<>();
    template.setConnectionFactory(connectionFactory);
    template.setKeySerializer(new StringRedisSerializer());
    template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
    return template;
}

}

我正在尝试使用

进行访问
 List l  = tmpl.getElementFromRedis(1234.13.tmpl-seq, ArrayList.class)

但由于

而出现异常

java.lang.ClassCastException:无法将java.lang.String转换为java.util.ArrayList

0 个答案:

没有答案