| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using FreeRedis;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace WCS.DebugTool
- {
- class Program
- {
- static void Main(string[] args)
- {
- var key = "";
- RedisClient redis = null;
- var last = DateTime.MinValue;
- Task.Run(() =>
- {
- SpinWait.SpinUntil(() => redis != null);
- while (true)
- {
- try
- {
- if ((DateTime.Now - last).TotalMilliseconds < 5000 || key == "")
- {
- Task.Delay(100).Wait();
- }
- else
- {
- last = DateTime.Now;
- redis.Publish("Login", key);
- }
- }
- catch (Exception ex)
- {
- Task.Delay(100).Wait();
- }
- }
- });
- while (true)
- {
- if (redis == null)
- {
- Console.WriteLine("请输入订阅关键字(逗号分隔):");
- redis = new RedisClient(Properties.Settings.Default.Redis);
- key = Console.ReadLine();
- last = DateTime.MinValue;
- var arr = key.Split(',');
- redis.PSubscribe(arr, (channel, msg) =>
- {
- Console.WriteLine($"----------对象:{channel}----------\n{msg}");
- });
- }
- else
- {
- if (Console.ReadKey().Key == ConsoleKey.Escape)
- {
- Console.Clear();
- redis.Dispose();
- redis = null;
- key = "";
- }
- }
- }
-
- }
- }
- }
|