C#.Net微说集.NET

C#操作Redis入门

2017-09-24  本文已影响73人  张中华

1.新建控制台应用程序



2.引用以下四个类库


PM> install-package servicestack

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();
        }
    }
}
上一篇下一篇

猜你喜欢

热点阅读