在上一篇文章中,https://blog.csdn.net/qq_16545625/article/details/104870937
了解了redis的具体使用场景,也已经成功安装了redis,并成功启动了redis服务端,测试了基本的操作。
接下来在C#控制台程序怎么使用redis呢
首先准备必要的dll文件
client四个引用
ServiceStack.Common.dll
ServiceStack.Interfaces.dll
ServiceStack.Redis.dll
ServiceStack.Text.dll
也可以使用这个三个引用
ServiceStack.dll
ServiceStack.Interfaces.dll
ServiceStack.ServiceInferface.dll
链接: https://pan.baidu.com/s/13cbYSLyjiC6_M4s6wQxyxQ 提取码: kc9u
上面提供了两套dll下载,我是通过看到有人都用过所以都测试了一下,具体区别我也不是很清楚。
新建C#控制台应用程序,添加引用
using ServiceStack.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static RedisClient redisClient = new RedisClient("127.0.0.1", 6379); // 设置Redis服务IP和端口
static void Main(string[] args)
{
redisClient.Set("MyName", "Vinkong"); // 设置key为MyName的值
Console.WriteLine(redisClient.Get<string>("MyName"));
Console.Read();
}
}
}