C#操作Redis入门

1.新建控制台应用程序

《C#操作Redis入门》

2.引用以下四个类库

《C#操作Redis入门》

PM> install-package servicestack

《C#操作Redis入门》

3.获取所有的keys的demo
RedisHelper.cs

using ServiceStack.Redis;
using ServiceStack.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace RedisTestOne
{
    class RedisHelper
    {
        public static void GetAllKeys()
        {
            using (var client = new RedisClient("127.0.0.1",6379))
            {
                client.SetEntryInHash("Person:1", "name", "zzh");
                client.SetEntryInHash("Person:1", "sex", "男");
                List<string> allKeys = client.GetAllKeys();
                foreach(var key in allKeys)
                { 
                    Console.WriteLine(key);
                }
            }
        }
    }
}

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServiceStack.Redis;
using RedisTestOne;

namespace RedisTestOne
{
    class Program
    {
        static void Main(string[] args)
        {
            RedisHelper.GetAllKeys();
            Console.ReadLine();
        }
    }
}

《C#操作Redis入门》

《C#操作Redis入门》

《C#操作Redis入门》

    原文作者:张中华
    原文地址: https://www.jianshu.com/p/bc2d4891e918
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞