C # Redis Operations Class Library recommendation: StackExchange.Redis.Extensions

Source: Internet
Author: User

Stackexchange is a good C # Redis client, but there are some drawbacks to the operation, and the use of StackExchange.Redis.Extensions has become a highly recommended option for simplifying operations. It makes it quite easy to use Stackexchange.

StackExchange.Redis.Extensions GitHub Address: https://github.com/imperugo/StackExchange.Redis.Extensions

The first step is to install the relevant package with NuGet:

Pm> Install-package StackExchange.Redis.Extensions.Newtonsoft

You can use it when you're done.

The following is a demonstration of a console case that modifies a value with multithreading.

usingSystem;usingSystem.Threading;usingStackExchange.Redis.Extensions.Core;usingStackExchange.Redis.Extensions.Core.Configuration;usingStackExchange.Redis.Extensions.Newtonsoft;namespaceredis{classProgram { Public Static voidIns () {thread thread=NewThread (() =            {                 for(inti =0; I < +; i++) {client. Database.stringincrement ("Key");            }            }); Thread.        Start (); }        Private Staticstackexchangerediscacheclient Client; Static voidMain (string[] args) {            varRedisconfiguration =Newredisconfiguration ()//configuration {Hosts=Newredishost[] {NewRedishost () {Host ="127.0.0.1", Port =6379}                 }            }; Client=NewStackexchangerediscacheclient (NewNewtonsoftserializer (), redisconfiguration); Client. ADD ("Key",0);  for(intj =0; J <Ten; J + +) {Ins (); } thread.sleep ( -); inti = client. get<int> ("Key");            Console.WriteLine (i);        Console.readkey (); }    }}

It is worth noting that if you want to write the relevant configuration into app. Config or Web. config, you need to install another package: StackExchange.Redis.Extensions.LegacyConfiguration

Install-Package StackExchange.Redis.Extensions.LegacyConfiguration

The configuration file will then be able to write the relevant configuration:

<?XML version= "1.0" encoding= "Utf-8"?><Configuration><!--Note that the configsections must be the first child element of the configuration node -    <configsections>          < Sectionname= "Rediscacheclient"type= "StackExchange.Redis.Extensions.LegacyConfiguration.RedisCachingSectionHandler, StackExchange.Redis.Extensions.LegacyConfiguration " />    </configsections>    <rediscacheclientAllowadmin= "true"SSL= "false"ConnectTimeout= " the"Database= "+">        <ServerenumerationstrategyMode= "single"Targetrole= "Preferslave"unreachableserveraction= "Ignoreifotheravailable" />         <hosts>            <AddHost= "127.0.0.1"Cacheport= "6379" />        </hosts>    </rediscacheclient></Configuration>

Then get the configuration in the code with Rediscachingsectionhandler.getconfig ():

var config =new stackexchangerediscacheclient (new Newtonsoftserializer (), config);

C # Redis Operations Class Library recommendation: StackExchange.Redis.Extensions

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.