1.首先安装redis (http://www.runoob.com/redis/redis-install.html)
解压文件在h盘的redis文件夹下
密码可以在redis.windows-service.conf 修改 requirepass xxxxxx
建立一个控制台应用程序,通过nuget安装ServiceStack.Redis
class Program
{
public static ISubscriber sub;
private static string chVoice = "ceshi";
static void Main(string[] args)
{
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("127.0.0.1:6379,password=xxxxxx");
// IDatabase db = redis.GetDatabase();
// string value = "哈哈";
db.StringSet("mykey", value);
// Console.WriteLine(db.StringGet("mykey"));
sub = redis.GetSubscriber();//订阅
// sub.Publish("ceshi", "nimeia");//发布
sub.Subscribe(chVoice, (channel, message) =>
{
Console.WriteLine("hhahha"+ message);
});
Console.ReadKey();
}
}
测试的话可以用文件夹里的redis-cli.exe 开一个客户端