static void Main(string[] args) { string subKey = "VicTestKeyspace"; /* 通过config set指令来在线keyspace配置. * * 开启所有的事件 * redis-cli config set notify-keyspace-events KEA * * 开启keyspace Events * redis-cli config set notify-keyspace-events KA * * 开启keyspace 所有List 操作的 Events * redis-cli config set notify-keyspace-events Kl */ string value = ""; var redis = new MyRedis(); redis.Subscriber.Subscribe($"__keyspace@0__:{subKey}", (channel, eventType) => { value = eventType == "set" ? redis.StringGet(subKey) : ""; Console.WriteLine($"[{DateTime.Now:HH:mm:ss}] {channel} {eventType} {value}"); });
private void button1_Click(object sender, EventArgs e) { MyRedis redis = new MyRedis(); redis.ConnectDb(); redis.OpenDb(); redis.subscrib("msg", (rc, rv) => { MessageBox.Show((string)rv); }); }
static void Main(string[] args) { var newLine = System.Environment.NewLine; Console.WriteLine("請輸入指令,輸入exit退出" + newLine + "StringSet VicTestKeyspace 999" + newLine + "StringGet VicTestKeyspace" + newLine + "KeyDelete VicTestKeyspace"); string input; MyRedis redis = new MyRedis(); string msg = ""; while (true) { input = Console.ReadLine(); if (input.ToLower() == "exit") { break; } msg = ""; if (!string.IsNullOrEmpty(input)) { string[] command = input.Split(' '); switch (command[0].ToLower()) { case "stringset": redis.StringSet(command[1], command[2]); msg = "Done"; break; case "stringget": msg = redis.StringGet(command[1]); break; case "keydelete": redis.KeyDelete(command[1]); msg = "Done"; break; default: msg = "Incorrenct Command"; break; } Console.WriteLine(msg); } } }