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