41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
|
|
using CSRedis;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace ConsoleApp2
|
|||
|
|
{
|
|||
|
|
public class GoodRedis
|
|||
|
|
{
|
|||
|
|
public static CSRedisClient? redis6;
|
|||
|
|
|
|||
|
|
private const string ip = "127.0.0.1";
|
|||
|
|
private const string port = "6379";
|
|||
|
|
static GoodRedis()
|
|||
|
|
{
|
|||
|
|
var redisHostStr = string.Format("{0}:{1}", ip, port);
|
|||
|
|
if (!string.IsNullOrEmpty(redisHostStr))
|
|||
|
|
{
|
|||
|
|
redis6 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=6");
|
|||
|
|
//string channel = "__keyevent@6__:expired";
|
|||
|
|
string channel = "__keyevent@6__:expired";
|
|||
|
|
var QQQ = new ValueTuple<string, Action<CSRedisClient.SubscribeMessageEventArgs>>(channel, (msg) =>
|
|||
|
|
{
|
|||
|
|
//body 是键
|
|||
|
|
string data = msg.Body;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Console.WriteLine(data);
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
redis6.Subscribe(QQQ);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|