@Autowired
@Resource(name = "redisTemplate")
private RedisTemplate<String, String> rt;
public void flushdb() {
rt.execute(new RedisCallback<Object>() {
public String doInRedis(RedisConnection connection) throws DataAccessException {
connection.flushDb();
return "ok";
}
});
}
public void set() {
flushdb();
rt.opsForValue().set("a", "1");
List<Object> results = rt.executePipelined(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) throws DataAccessException {
for (int i = 0; i < 10; i++) {
connection.incr("a".getBytes());
}
return null;
}
});
System.out.println(rt.opsForValue().get("a"));
}
转载于:https://my.oschina.net/haokevin/blog/1826429