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

  • 相关阅读:
    jQueryrocket
    jQueryrocket
    jQueryrocket
    jQueryrocket
    jQueryrocket
    SPListItem.UpdateOverwriteVersion()真的不会创建新版本吗?
    不能访问本地服务器场。没有注册带有FeatureDependencyId 的 Cmdlet
    SharePoint 2013 另一个程序正在使用此文件,进程无法访问。 (异常来自 HRESULT:0x80070020)
    使用PowerShell修改操作系统“环境变量”
    无法解决“Microsoft.SharePoint.Security, Version=15.0.0.0,”与“Microsoft.SharePoint.Security, Version=14.0.0.0”之间的冲突
  • 原文地址:https://www.cnblogs.com/riusmary/p/8352490.html
Copyright © 2011-2022 走看看