C # implements Redis read-write

Source: Internet
Author: User

Recently, a C # project needs to read and write to Radis.

First introduce System.Configuration, as follows

The implementation code is as follows:

public class Manualsuggestredishelper {private static iredisclient getmanualsuggestclient () { var config = configurationmanager.connectionstrings["Redis_manual_video_list"].            Connectionstring.split (': '); if (config. Length = = 3) {int dbnum = Int.                Parse (config[2]); return new Redisclient (config[0], int.            Parse (Config[1]), db:dbnum);            } else {return new redisclient ("192.168.86.15", 6379, Db:8);                }} public static void Addrangetolist (string key, Jsonobject value) {try { using (var Redis = getmanualsuggestclient ()) {Redis. Setentry (key, value.                ToString ());            }} catch (Exception ex) {txtlogger.dumpexception (ex); }} public static void Addrangetosuggestlist (string key, List<striNg> value) {try {using (var Redis = getmanualsuggestclient ()) {Redis.                Addrangetolist (key, value);            }} catch (Exception ex) {txtlogger.dumpexception (ex); }} public static void Remove (string key) {try {using (var red is = Getmanualsuggestclient ()) {Redis.                Remove (key); }} catch (Exception ex) {txtlogger.appendstringtotextfile ("Remove Redis key exists            Exception--"+ ex"); }} public static bool Existsredis (string key) {try {using (VA R Redis = getmanualsuggestclient ()) {list<string> isexists = Redis.                    Getallitemsfromlist (key); if (isexists! = null && Isexists.counT () > 0) {return true;            }}} catch (Exception ex) {txtlogger.dumpexception (ex);        } return false; }    }

C # implements Redis read-write

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.