簡體   English   中英

如何配置EnyimMemcachedCore以訪問AWS Lambda中的Elasticache?

[英]How to configure EnyimMemcachedCore to access Elasticache in AWS Lambda?

我正在嘗試將一個簡單的Memcached客戶端從.NET 4移植到AWS Lambda上的.Net Core。 我正在努力配置新的EnyimMemcachedCore客戶端,因為示例( https://github.com/cnblogs/EnyimMemcachedCore )使用appsettings.json來設置配置,但是使用.net core的Lambda函數不使用appsettings.json。 我需要能夠在C#代碼中設置服務器/端口/端點。

誰能給我一個使用EnyimMemcachedCore手動創建配置的示例嗎?

Enyim的標准.net使用很容易通過鍵獲取並返回值:

using Enyim.Caching;
using Enyim.Caching.Configuration;
using Enyim.Caching.Memcached;

...
// setup Enyim memcached client
MemcachedClient myCache;
MemcachedClientConfiguration config;
config = new MemcachedClientConfiguration(); 
config.AddServer("theIP", thePort);
config.Protocol = MemcachedProtocol.Text;

// instantiate client
myCache = new MemcachedClient(config);

// get the stored item
var result = myCache.Get(key);

如何使用EnyimMemcachedCore做類似的事情(在代碼中配置memcached客戶端,而不是在配置文件中)?

// setup Enyim memcached client
var config = new MemcachedClientConfiguration();

//add each node manually if you can't get the Amazon.ElastiCacheCluster config for Core, 
//but if you can, use that instead of MemcachedClientConfiguration
config.AddServer("something.0001.usw1.cache.amazonaws.com", 11211);
config.AddServer("something.0002.usw1.cache.amazonaws.com", 11211);

config.Protocol = MemcachedProtocol.Text;

// instantiate client
var myCache = new Enyim.Caching.MemcachedClient(config);

您可以單獨添加節點,直到群集配置可用於.NET Core(如果尚未配置)為止。

我猜到今天(2018年9月18日)已修復。我嘗試了以下appsettings,使用了具有一個節點的memcache的配置端點

"enyimMemcached": {
    "Servers": [
        {
            "Address": "st-cache-01-v2.l0nmej.cfg.xxxx.cache.amazonaws.com",
            "Port": 11211
        }
    ]
}

以及ConfigureServices上的代碼

services.AddEnyimMemcached(Configuration);

它像魅力一樣運作。 我還沒有嘗試過兩個節點。 如果不適用於多個節點,請隨時糾正我

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM