标签:class blog code http com get
使用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")); } }
ServiceStack.Redis常用操作 - 事务、并发锁,布布扣,bubuko.com
ServiceStack.Redis常用操作 - 事务、并发锁
标签:class blog code http com get
原文地址:http://www.cnblogs.com/lyl6796910/p/3791854.html