如何配置 EnyimMemcachedCore 来访问 AWS Lambda 中的 Elasticache?

Pet*_*eld 5 c# memcached enyim .net-core 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);
Run Code Online (Sandbox Code Playgroud)

如何使用 EnyimMemcachedCore 执行类似的操作(在代码中配置 memcached 客户端,而不是在配置文件中)?

phi*_*n5d 1

// 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);
Run Code Online (Sandbox Code Playgroud)

您可以单独添加节点,直到集群配置可用于 .NET Core(如果还没有)