zoukankan      html  css  js  c++  java
  • Redis 安装与简单示例 <第一篇>

    一、Redis的安装

      Redis下载地址如下:https://github.com/dmajkic/redis/downloads

      解压后根据自己机器的实际情况选择32位或者64位。下载解压后图片如下:

      

    1. redis-server.exe redis服务器的daemon启动程序
    2. redis.conf redis配置文件
    3. redis-cli.exe redis命令行操作工具。当然,也可以用telnet根据其纯文本协议来操作
    4. redis-check-dump.exe 本地数据库检查
    5. redis-check-aof.exe 更新日志检查
    6. redis-benchmark.exe 性能测试,用以模拟同时由N个客户端发送M个 SETs/GETs 查询 (类似于 Apache的 ab 工具)

      上图中的redis-server.exe为其服务端程序。双击它运行。

      

      如果你希望将此服务设置为windows系统服务,下载Redis服务安装软件(https://github.com/rgl/redis/downloads),安装即可。

      安装完成在服务(右击我的电脑--管理--服务和应用程序--服务)中找到此服务,将其设置为自动延迟启动即可。

      

      在redis文件夹下,找到redis-cli.exe文件,它就是Redis客户端程序。

      打开输入:set name jerry

      即在Redis中插入了一条key为name,value为jerry的数据,

      继续输入:get name

      得到value保存的数据jerry。

      

      使用使用:keys * 可以查询Redis一共保存了多少条数据

      

    二、在Asp.net中使用Redis

      1、先使用Nuget安装个 C# Redis client for the Redis NoSQL DB。

      

      其实就是ServiceStack.Redis,这是官网推荐的C#客户端。

      下面来看看最简单的示例:

    复制代码
    public ActionResult Index()
    {
        RedisClientManagerConfig RedisConfig = new RedisClientManagerConfig();
        RedisConfig.AutoStart = true;
        RedisConfig.MaxReadPoolSize = 60;
        RedisConfig.MaxWritePoolSize = 60;
    
        PooledRedisClientManager prcm = new PooledRedisClientManager(new List<string>() { "127.0.0.1" }, new List<string>() { "127.0.0.1" }, RedisConfig);
    
        using (IRedisClient RClient = prcm.GetClient())
        {
            RClient.Add("p", "撼地神牛");
        }
        using (IRedisClient RClient = prcm.GetClient())
        {
            Response.Write(RClient.Get<string>("p"));
        }
    
        return Content("");
    }
    复制代码

       更多关于Redis的操作,建议可以观看红丸的《Redis实战》,以及这个不错的网址:http://redis.readthedocs.org/en/latest/。

  • 相关阅读:
    bzoj 4012: [HNOI2015]开店
    POJ 1054 The Troublesome Frog
    POJ 3171 Cleaning Shifts
    POJ 3411 Paid Roads
    POJ 3045 Cow Acrobats
    POJ 1742 Coins
    POJ 3181 Dollar Dayz
    POJ 3040 Allowance
    POJ 3666 Making the Grade
    洛谷 P3657 [USACO17FEB]Why Did the Cow Cross the Road II P
  • 原文地址:https://www.cnblogs.com/shengfa/p/4313774.html
Copyright © 2011-2022 走看看