【发布时间】:2014-04-01 04:14:42
【问题描述】:
我正在使用 Spring RedisTemplate 来处理与 Redis 相关的操作。我可以存储两种数据类型吗?例如,我想存储 Key、String 以及 Key、Integer。如何做到这一点?
【问题讨论】:
标签: redis
我正在使用 Spring RedisTemplate 来处理与 Redis 相关的操作。我可以存储两种数据类型吗?例如,我想存储 Key、String 以及 Key、Integer。如何做到这一点?
【问题讨论】:
标签: redis
你读过http://docs.spring.io/spring-data/redis/docs/current/reference/html/redis.html吗?
对文档稍作改动,未经测试:
public class Example {
// inject the actual template
@Autowired
private RedisTemplate<String, String> template;
// inject the template as ValueOperations
@Resource(name="redisTemplate")
private ValueOperations<String, Integer> intOp;
@Resource(name="redisTemplate")
private ValueOperations<String, String> stringOp;
public void sampleKeySetting() {
intOp.set('my_int_value', 10);
stringOp.set('my_string_value', 'good!');
}
}
其他数据结构也有XXXXOperations:检查http://docs.spring.io/spring-data/data-keyvalue/docs/current/api/org/springframework/data/keyvalue/redis/core/RedisOperations.html
【讨论】: