First, the business
Example of executing a transaction using iredisclient:
using (iredisclient rclient = prcm. Getclient ()) { rclient.add ("key", 1); using (iredistransaction IRT = rclient.createtransaction ()) { IRT. Queuecommand (r = R.set ("key")); Irt. Queuecommand (r = r.increment ("key", 1)); Irt.commit (); Commit TRANSACTION } Response.Write (rclient.get<string> ("key")); }
Second, the concurrent lock
Example of using Iredisclient to request a lock:
using (iredisclient rclient = prcm. Getclient ()) { rclient.add ("MyKey", 1); Supports iredistypedclient and iredisclient using (Rclient.acquirelock ("Testlock")) { Response.Write ("Request concurrent lock <br/> "); var counter = rclient.get<int> ("MyKey"); Thread.Sleep (+); Rclient.set ("MyKey", counter + 1); Response.Write (rclient.get<int> ("MyKey")); } }
Servicestack.redis common operations-transactions, concurrency locks