无法查询 Spring 数据 Redis 事务中的列表


    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 事务中获取我的列表数据呢?非常感谢。

SD-Redis 中的事务支持有助于参与正在进行的事务,并允许自动提交 ( exec )/回滚 ( discard ),因此它有助于将命令包装到使用相同的连接绑定到线程绑定的多执行块中。
更一般地说,redis 事务和事务中的命令在服务器端排队,并在 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();                                   

最新更新