Back to Catalog
There are many Redis client drivers, such as Servicestack.redis, Stackexchange.redis and so on, here I use Servicestack.redis as an example, introduce the way to implement concurrent lock in Redis driver, concurrency is the simultaneous access and operation of the same resources, and for Redis, if you multiple threads together modify the Val of a key UE, then will appear concurrency, in order to ensure data integrity, then need to use concurrent lock, in the major languages, have their own implementation method, regardless of C,c#,java or SQL Server has this concept!
using(Iredisclient rclient =Lind.DDD.RedisClient.RedisManager.GetClient ()) {Rclient.add ("Zzlkey",1); //supports iredistypedclient and iredisclient using(Rclient.acquirelock ("Lock") {Console.WriteLine ("Concurrent Lock"); varCounter = rclient.get<int> ("Zzlkey");Rclient.set ("Zzlkey", Counter +1); Console.WriteLine (Rclient.get<int> ("MyKey"));
Thread.Sleep (1000); } }
The above code is simply a function of the concurrency lock, the process is to request a lock on the Redis server, and then send instructions, we know that the use of the function is the concept of scope, that is, your lock after using, will be released.
Back to Catalog
Redis Learning Note ~redis concurrency lock mechanism