@Autowired
RedisTemplate<String,String>
redisTemplate;
redisTemplate.execute(new SessionCallback<Object>
(){
@Override
public <K, V> Object execute(RedisOperations<K, V> operations)
throws DataAccessException {
//开启事务
operations.multi();
for(
int i = 1; i <= 5; i++
) {
redisTemplate.convertAndSend("channel:test", String.format("我是消息{%d}号: %tT", i,
new Date()));
redisTemplate.opsForValue().set("key" + i,"key" +
i);
}
//执行事务
operations.exec();
return null;
}
});
转载于:https://www.cnblogs.com/powerwu/p/11505716.html