这篇文章主要为大家详细介绍了C#实现redis读写的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要为大家详细介绍了C#实现redis读写的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要为大家详细介绍了C#实现redis读写的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
最近做一个c#项目,需要对radis进行读写。
首先引入system.configuration,如下

实现代码如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
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 redis = getmanualsuggestclient()) { redis.remove(key); } } catch (exception ex) { txtlogger.appendstringtotextfile("删除redis key存在异常——" + ex); } } public static bool existsredis(string key) { try { using (var redis = getmanualsuggestclient()) { list<string> isexists = redis.getallitemsfromlist(key); if (isexists != null && isexists.count() > 0) { return true; } } } catch (exception ex) { txtlogger.dumpexception(ex); } return false; } } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持米米素材网。
发表评论