template.setEnableTransactionSupport(true);
template.multi();
template.opsForValue().set("mykey", "Hello World");
List<String> dataList = template.opsForList().range("mylist", 0, -1);
template.exec();嗨,伙计们。我的redis中有一个名为“mylist”的列表,它的大小是50。
但是当我运行这段代码时,我不能得到我想要的东西。
字段"dataList“是空的,但是,值为"Hello World”的"mykey“仍然存在于我的redis中。
那么如何在spring- data -redis事务中获取我的列表数据呢?非常感谢。
发布于 2016-04-25 21:19:28
SD-Redis中的事务支持有助于参与正在进行的事务,并允许自动提交(exec) /回滚(discard),因此它有助于使用相同的连接将命令包装到线程绑定的多执行块中。
更常见的是,redis transactions和事务中的命令在服务器端排队,并在exec上返回结果列表。
template.multi();
// queue set command
template.opsForValue().set("mykey", "Hello World");
// queue range command
List<String> dataList = template.opsForList().range("mylist", 0, -1);
// execute queued commands
// result[0] = OK
// result[1] = {"item-1", "item-2", "item-", ...}
List<Object> result = template.exec(); https://stackoverflow.com/questions/36764373
复制相似问题