数据库中的密钥被某些开发人员另存为 获取“ 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