1

我正在尝试使用 Memcached 和 Enyim 客户端测试我的 AWS Elasticache 节点,但是由于某种原因,到期时间似乎超过了 1 小时。

我使用以下代码添加了数据:

_client.Store(StoreMode.Set, "testkey", "test", DateTime.Now.AddMinutes(1));

然后我尝试使用检索数据

var data = _client.Get<string>("testkey");

但是,这永远不会检索数据。但是,如果我从现在开始将到期时间更改为 61 分钟,它将存储数据 1 分钟。我用 TimeSpan 而不是 DateTime.Now 试过这个,但遇到了同样的问题。

我还输出DateTime.Now了正确的值,我的 AWS 区域是 EU-West,与输出的时区相同DateTime.Now

4

2 回答 2

1

使用它会更安全:

_client.Store(StoreMode.Set, "testkey", "test", TimeSpan.FromMinutes(1.0));

这样,您不会对 DateTime 和 UTC 有任何依赖。

于 2015-01-04T07:40:12.437 回答
0

I figured it out myself. I didn't really take UTC into account, and that's what the Elasticache instances use. Therefore to fix my issue I just need to use DateTime.UtcNow rather than DateTime.Now

于 2014-09-24T13:37:37.773 回答