.net redis demo

来源:互联网 发布:安卓qq2016协议源码 编辑:程序博客网 时间:2024/05/22 17:01

redis就不多介绍了,这里只提供一个使用简单使用方法

第一下载windows版本的安装包地址:https://github.com/MSOpenTech/redis/releases

第二步就是安装了

启动redis-server.exe服务,或者在服务中直接将redis设置为自动启动即可


第三步 redis运行需要相应的dll来解析,可以在nuget上下载相应的dll (ServiceStack.Redis)

安装这个即可

第四步:代码示例

  class Program
    {
        static RedisClient redisClient = new RedisClient("127.0.0.1", 6679);//redis服务IP和端口
        static void Main(string[] args)
        {
            redisClient.Set("mykey", 1);
            // 支持IRedisTypedClient和IRedisClient
            using (redisClient.AcquireLock("testlock"))
            {
                var counter = redisClient.Get<int>("mykey");
            Console.WriteLine(counter);
            Thread.Sleep(100);


            redisClient.Set("mykey", counter + 1);
            int v = redisClient.Get<int>("mykey");


            Console.WriteLine(v);
            }
        }
    }

0 0
原创粉丝点击