实现方式一
@Autowired
RedisTemplate<String, ?> redisTemplate;
@SuppressWarnings("resource")
public Object slist() {
JedisConnectionFactory connectionFactory =
(JedisConnectionFactory) redisTemplate.getConnectionFactory();
connectionFactory.setDatabase(1);
List<San> slist = new ArrayList<San>();
ListOperations forList = redisTemplate.opsForList();
List<String> range = forList.range("slist", 0, -1);
for (String object : range) {
San s = JsonUtils.jsonToPojo(object, San.class);
slist.add(s);
}
return slist;
}
实现方式二
@Repository
public class SanDao {
@Autowired
RedisTemplate<String, ?> redisTemplate;
@Autowired
JedisConnectionFactory jedisConnectionFactory;
@SuppressWarnings("resource")
public Object slist() {
jedisConnectionFactory.setDatabase(1);
List<San> slist = new ArrayList<San>();
ListOperations forList = redisTemplate.opsForList();
List<String> range = forList.range("slist", 0, -1);
for (String object : range) {
San s = JsonUtils.jsonToPojo(object, San.class);
slist.add(s);
}
return slist;
}
}