Redis Learning Note ~redis concurrency lock mechanism

Source: Internet
Author: User
Tags redis server

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.