For specific comments, the code looks like this:
1 Public Static voidtranstest ()2 {3Redisclient client1 =Newredisclient (host, port);4Redisclient Client2 =Newredisclient (host, port);5 //initial K1 is 16Client1. set<string> ("K1","1");7Console.WriteLine (Client1. get<string> ("K1"));8 //Monitoring K19Client1. Watch ("K1");Ten vartrans =Client1. CreateTransaction (); OneTrans. Queuecommand (r = r.set<string> ("K1","11111111111111")); A //K2 does not exist -Trans. Queuecommand (r = r.set<string> ("K2","2")); - //Other clients modify the value of K1 before a transaction commits theClient2. set<string> ("K1","aaaaaaaaaa"); - //Commit a transaction - trans.commit (); -Console.WriteLine (Client1. get<string> ("K1"));//This will output AAAAAAAAAA +Console.WriteLine (Client1. get<string> ("K2"));//This value will be empty - Console.read (); +}
The Watch for Redis research