• 初涉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的地方都不需要更改。

  • 相关阅读:
    #Git 21天打卡第一天 01天0526
    老徐第六期百人计划之职业发展方向&学习方向
    LR12.53安装中文补丁包,录制后回放脚本一致卡在编译的问题
    常用oracle语句整理
    LoadRunner11之批量插入SQL数据~2
    LoadRunner12之SQLServer数据库批量插入--.Net协议
    Jmeter连接Oracle数据库简单使用
    AppScan安装使用
    SQL多表连接
    [剑指Offer] 4.二维数组的查找
  • 原文地址:https://www.cnblogs.com/riusmary/p/8352490.html
Copyright © 2020-2023  润新知