Redis在C#控制台程序的初次使用

在上一篇文章中,https://www.cnblogs.com/Vinkong/p/11649101.html

client四个引用
ServiceStack.Common.dll
ServiceStack.Interfaces.dll
ServiceStack.Redis.dll
ServiceStack.Text.dll
也可以使用这个三个引用
ServiceStack.dll
ServiceStack.Interfaces.dll
ServiceStack.ServiceInferface.dll

了解了redis的具体使用场景,也已经成功安装了redis,并成功启动了redis服务端,测试了基本的操作。

接下来在C#控制台程序怎么使用redis呢

 

上面提供了两套dll下载,我是通过看到有人都用过所以都测试了一下,具体区别我也不是很清楚。

地址:

链接: https://pan.baidu.com/s/13cbYSLyjiC6_M4s6wQxyxQ 提取码: kc9u

新建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();
        }
    }
}

  

posted @ 2020-04-07 14:26  寻找现实的感觉  阅读(332)  评论(0编辑  收藏  举报