• Redis学习笔记


    Redis学习笔记

    李涛 2017-1-5

    Redis知识

    1、Redis入门介绍http://www.cnblogs.com/zhili/p/QuickstartRedis.html

    2、redis asp.net客户端应用方式

    (1)应用nuget中的StackExchange.Redis或ServiceStack.Redis

    区别详见http://www.cnblogs.com/qtqq/p/5951201.html

    (2)ServiceStack.Redis使用http://www.cnblogs.com/fx2008/p/4218299.html

    食药监项目中应用

    1、redis配置应用参照nopcommerce3.8开源项目(http://www.nopcommerce.com/downloads.aspx),引用nuget中的StackExchange.Redis

    2、在PharmacyKindergartenMonitor.Core项目中应用nuget安装StackExchange.Redis

    3、PharmacyKindergartenMonitor.Core.Caching文件夹下添加类RedisCacheManager : ICacheManager,用于缓存的增删改查(仿真数据库)。读取缓存时先从perRequest中查找,没有的话再去找redis。

    4、PharmacyKindergartenMonitor.Core.Caching文件夹下添加RedisConnectionWrapper及对应接口,用于管理redis的连接事情

    5、(1)PharmacyKindergartenMonitor.Core.Configuration中添加类PharmacyKindergartenMonitorConfig : IConfigurationSectionHandler,用于将web项目中的config文件中相关的配置信息读取存放于类中,便于依赖注入等其他类调用。

    (2)修改webconfig文件,配置<PharmacyKindergartenMonitorConfig>节点相关信息。Web启动时走global文件中EngineContext.Initialize(false);

    PharmacyKindergartenMonitor.Core.Infrastructure. EngineContext  Initialize方法会读取webconfig中<PharmacyKindergartenMonitorConfig>节点内容,存放成PharmacyKindergartenMonitorConfig config对象,并用config信息构造IEngine,              

                    Singleton<IEngine>.Instance.Initialize(config);(

    方法中RegisterDependencies(config) 依赖注入;

                RunStartupTasks();启动初始化的各种任务,如automapper)

    6、PharmacyKindergartenMonitor.Framework DependencyRegistrar类中书写cacheManager的注入,及service注入时选择cacheManage

      //cache manager

                builder.RegisterType<RedisConnectionWrapper>().As<IRedisConnectionWrapper>().SingleInstance();

                builder.RegisterType<RedisCacheManager>().As<ICacheManager>().Named<ICacheManager>("nop_cache_static").InstancePerLifetimeScope();

                builder.RegisterType<PerRequestCacheManager>().As<ICacheManager>().Named<ICacheManager>("nop_cache_per_request").InstancePerLifetimeScope();

     

      //pass RedisCacheManager to SettingService as cacheManager (cache settngs between requests)

           builder.RegisterType<PermissionService>().As<IPermissionService>()

                    .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static"))

                    .InstancePerLifetimeScope();

    7、服务器端

    https://github.com/MSOpenTech/Redis上下载redis,解压缩后放置服务器上,双击打开redis-server.exe,启动redis服务即可。在客户端的webconfig配置好相应的ip地址。默认端口号可省略。

    安装测试参见http://www.cnblogs.com/fx2008/p/4218114.html

    8、redis 桌面管理工具,方便redis内容的可视化管理

    参照 http://www.cnblogs.com/taoshengyujiu/p/6514747.html

    9、redis端口及密码修改,并在后台启动服务

    (1)解压后的文件,将redis.windows改成redis,好像不改也行。

     

    (2)将redis.config文件打开修改,默认端口号6379,可以自定义修改,比如port 6666

    # Accept connections on the specified port, default is 6379.

    # If port 0 is specified Redis will not listen on a TCP socket.

    port 6379

    (3)设置redis密码,去掉requirepass,取消注释,将foobar改为想要的密码。比如改成 requirepass test123

    # Warning: since Redis is pretty fast an outside user can try up to

    # 150k passwords per second against a good box. This means that you should

    # use a very strong password otherwise it will be very easy to break.

    #

    #requirepass foobar

    (4)运行cmd命令,转换到redis文件夹路径(比如d:/temp/redis),先敲D:回车,再敲cd temp edis回车。运行安装redis-service服务。

    redis-server  --service-install redis.conf  --service-name redisservice6666

    其中redisservice6666是自主定义的服务名称,成功后在机器服务列表中将会看到redisservice6666.(win10 在搜索框中搜索服务或者win+R services.msc)

     

    (5)应用redis-cli测试下redis-service。其中-h为安装redis服务器的ip,127.0。0.1是本机。-p为端口号,-a为密码

    Redis-cli.exe  -h 127.0.0.1 –p 6666 –a test123

    Set name ‘liming’

    Get name

  • 相关阅读:
    参数化邮箱登录.py
    javaWeb服务详解(含源代码,测试通过,注释) ——web.xml
    javaWeb服务详解(含源代码,测试通过,注释) ——applicationContext.xml
    javaWeb服务详解(含源代码,测试通过,注释) ——applicationContext.xml
    javaWeb服务详解(含源代码,测试通过,注释) ——Emp的Service层
    javaWeb服务详解(含源代码,测试通过,注释) ——Emp的Service层
    javaWeb服务详解(含源代码,测试通过,注释) ——Dept的Service层
    轻院1605: 数字序列
    轻院2270: 跳跳的书包
    出队
  • 原文地址:https://www.cnblogs.com/taoshengyujiu/p/6251630.html
Copyright © 2020-2023  润新知