I. Transactions
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", 20); IRT. queuecommand (r => r. increment ("key", 1); IRT. commit (); // submit the transaction} response. write (rclient. get <string> ("key "));}
Ii. Concurrent lock
Example of applying for a lock using iredisclient:
Using (iredisclient rclient = prcm. getclient () {rclient. add ("mykey", 1); // supports iredistypedclient and iredisclient using (rclient. acquirelock ("testlock") {response. write ("apply for concurrent lock <br/>"); var counter = rclient. get <int> ("mykey"); thread. sleep (1, 100); rclient. set ("mykey", counter + 1); response. write (rclient. get <int> ("mykey "));}}
Servicestack. redis common operations-transactions and concurrent locks