ServiceStack.Redis常用操作 - 事务、并发锁
发布日期:2018-02-09 浏览次数:1767
一、事务
使用IRedisClient执行事务示例:
using (IRedisClient RClient = prcm.GetClient()) { RClient.Add("key",1); using (IRedisTransaction IRT = RClient.CreateTransaction()) { IRT.QueueCommand(r => r.Set("key", 20)); IRT.QueueCommand(r => r.Increment("key",1)); IRT.Commit(); // 提交事务 } Response.Write(RClient.Get<string>("key")); }
二、并发锁
使用IRedisClient申请锁示例:
using (IRedisClient RClient = prcm.GetClient()) { RClient.Add("mykey",1); // 支持IRedisTypedClient和IRedisClient using (RClient.AcquireLock("testlock")) { Response.Write("申请并发锁<br/>"); var counter = RClient.Get<int>("mykey"); Thread.Sleep(100); RClient.Set("mykey", counter + 1); Response.Write(RClient.Get<int>("mykey")); } }
本文网址:https://www.wyxxw.cn/blog-detail-2-6-245.html
非特殊说明,本文版权归原作者所有,转载请注明出处
提示:本站所有资源仅供学习与参考,请勿用于商业用途。图片来自互联网~如侵犯您的权益,请联系QQ:1067507709.
提示:转载请注明来自:http://www.cnblogs.com/kissdodog/p/3608503.html 。 转载人:momo