2016-04-21 24 views
0
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无法在spring-data-redis事务中查询列表

但是当我运行这段代码,我无法得到我想要的东西。

字段‘DataList控件’为空,然而,“的myKey”与价值的“Hello World”在我的Redis仍然存在。

那么,如何才能让我的列表数据用于弹簧数据redis的交易?非常感谢。

回答

1

交易suppport在SD-Redis帮助参与正在进行的交易并允许自动提交(exec)/回滚(discard),所以它有助于使用相同的连接将命令封装到线程绑定的多个exec块中。
更一般地说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();         
+0

谢谢你的分析,你的回答对我很有帮助。 –