zoukankan      html  css  js  c++  java
  • 初涉AWS 之 ElasticCache——Redis在.Net中的用法

    拿到一个测试aws账号开始捣鼓。

    aws上可用ElasticCache包括Redis和MemCached,此篇说redis,下篇讲MemCached。

    什么是aws Elasticcache

    其中包括基本的介绍和配置信息入门。

    在.Net客户端上安装配置相关组件

    NuGet中下载Amazon.ElastiCacheCluster程序包并引用

    在Appconfig中进行相应配置

     1 <configSections>
     2     <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
     3     <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
     4     <section name="clusterclient" type="Amazon.ElastiCacheCluster.ClusterConfigSettings, Amazon.ElastiCacheCluster" />
     5   <section name="membase" type="Membase.Configuration.MembaseClientSection, Membase" /></configSections>
     6   <clusterclient>
     7     <!-- the hostname and port values are from step 1 above -->
     8     <endpoint hostname="{ip地址}" port="6379" />
     9     <!--bigdata-redis.xdnqsx.0001.cnn1.cache.amazonaws.com.cn-->
    10   </clusterclient>
    appconfig

    Q问题,为什么不能用aws控制台中的DNS,必须要用ip地址。

    接着是client中redis connection的修改,代码实现起来比azure要方便一些,当然aws对加密这一块做的不如azure,sql 的connection也是如此,可能是并不担心?

     1 private static readonly Lazy<ConnectionMultiplexer> LazyConnection = new Lazy<ConnectionMultiplexer>(() =>
     2         {
     3             _logger.Info(LoggerSourceName, "Begin to create Redis connection");
     4 
     5             //read connection information from storage/configuration-redis/Redis.config           
     6             string redisConnectionString;
     7             redisConnectionString = DANCode1Config.ClusterClientHostname + ":" + DANCode1Config.ClusterClientPort;
     8 
     9             ConfigurationOptions options = ConfigurationOptions.Parse(redisConnectionString);
    10             //options.ConnectTimeout = 60 * 1000;
    11             options.SyncTimeout = 60 * 1000;
    12             options.ResponseTimeout = 60 * 1000;
    13 
    14 
    15             ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(options);
    16             redis.ConfigurationChanged += redis_ConfigurationChanged;
    17             redis.ConfigurationChangedBroadcast += redis_ConfigurationChangedBroadcast;
    18             redis.ConnectionFailed += redis_ConnectionFailed;
    19             redis.ConnectionRestored += redis_ConnectionRestored;
    20             return redis;
    21         });
    redis connection

    配置完后,所有原先读写redis的地方都不需要更改。

  • 相关阅读:
    找出2n+1个数中不成对的那个(升级版)
    找出2n+1个数中不成对的那个
    随手记,完美的记账软件
    NOD32强制卸载工具使用方法【转】
    中医养生重在养“气”【灵枢针灸-袁医生】
    美国大学对本科生培养的12条标准【转】
    Windows软件使用Q&A集锦【持续更新】
    VLSI和ASIC的区别(转)
    Verilog 模块参数重定义(转)
    FPGA技术的一些基本概念(综合、BlackBox)(转)
  • 原文地址:https://www.cnblogs.com/riusmary/p/8352490.html
Copyright © 2011-2022 走看看