Redis uses C # programs to operate Redis

Source: Internet
Author: User

One, the NuGet package required for installation operation

Second, write

Redis only sets the expiration time by the key value, not the expiration of some values inside value

2.1 String Type

/// <summary>        ///writing to Redis/// </summary>        /// <param name= "key" >Key Value</param>        /// <param name= "value" >value</param>        /// <param name= "Date" >expiry date</param>         Public Static voidSetString (stringKeystringValue,datetime? Date =NULL)        {            //connectionmultiplexer.connect ("localhost:6379,password=123456"))            using(varRedis = Connectionmultiplexer.connect ("Localhost"))            {                //Write                vardb =Redis.                Getdatabase (); Db. Stringset ("Key","123456"); //Set Expiration Date                if(Date! =NULL) {DateTime time= DateTime.Now.AddSeconds ( -); Db. Keyexpire ("Key", time); }                varresult = db. Stringget ("Key"); }        }

Third, read

 // <summary>        ///read the contents of Redis/// </summary>        /// <param name= "key" ></param>        /// <returns></returns>         Public Static stringGetString (stringkey) {            using(varRedis = Connectionmultiplexer.connect ("Localhost"))            {                //Read                vardb =Redis.                Getdatabase (); varresult =db.                Stringget (key); returnresult; }        }

Redis uses C # programs to operate Redis

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.