C#操作Redis入门

作者: 张中华 | 来源:发表于2017-09-24 14:50 被阅读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();
            }
        }
    }
    

    相关文章

      网友评论

        本文标题:C#操作Redis入门

        本文链接:https://www.haomeiwen.com/subject/pnskextx.html