gpt4 book ai didi

EasyCaching with MessagePack loses Time zone data(使用MessagePack的EasyCach会丢失时区数据)

转载 作者:bug小助手 更新时间:2023-10-24 18:10:24 26 4
gpt4 key购买 nike



I'm using EasyCaching on an ASP.NET MVC app for handling Redis. As stated in the documentation (Precautions), using the MessagePack serializer will cause problems with the time zone data. There is a solution stated there and I'm using it but it's still not working as intended.

This is my current EasyCaching setup:

我在ASP.NETMVC应用程序上使用EasyCaching来处理Redis。正如文档(注意事项)中所述,使用MessagePack序列化程序会导致时区数据出现问题。那里有一个解决方案,我正在使用它,但它仍然没有像预期的那样工作。这是我当前的EasyCaching设置:


builder.Services.AddEasyCaching(options =>
{
options.UseRedis(config =>
{
config.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));

config.SerializerName = "mymsgpack";
}, "redis1");

options.WithMessagePack(x =>
{
x.EnableCustomResolver = true;
x.CustomResolvers = CompositeResolver.Create(new MessagePack.IFormatterResolver[]
{
NativeDateTimeResolver.Instance,
ContractlessStandardResolver.Instance
});
}, "mymsgpack");
});

It's mostly the default configurations. I've implemented a monitoring tool that somewhat works like logging some data. You tell it to add a metric and then it shows all the metrics in a web page. The function call to add a metric (or "log" a metric) looks like this:

这主要是默认配置。我已经实现了一个监控工具,它的工作方式有点像记录一些数据。您告诉它添加一个指标,然后它会在一个网页中显示所有指标。添加指标(或“记录”指标)的函数调用如下所示:


_metric.AddItem("IAM", DateTime.Now, MetricAggregation.Date);

This means that "I want to log the current date-time in the metric called 'IAM', and this metric has an aggregation type of date". The last part is not important (regarding the current problem). When I'm viewing the web page, all the date time data are displayed in GMT (And not GMT+3:30 which is my current time zone).

这意味着“我希望在名为‘IAM’的度量中记录当前的日期-时间,并且该度量的聚合类型为Date”。最后一部分并不重要(关于当前的问题)。当我浏览网页时,所有的日期时间数据都以GMT显示(而不是我当前的时区GMT+3:30)。


Before using EasyCaching, I used an in-memory solution and stored all the data in a dictionary. That worked as intended but I wanted to store the data for when the server goes down or fails for any reason.

在使用EasyCaching之前,我使用了内存中的解决方案,并将所有数据存储在字典中。这可以达到预期的效果,但我想存储数据,以备服务器因任何原因出现故障时使用。


I'm not insisting on using MessagePack for serialization, it was what EasyCaching used as default in their setup guide. But any help is appreciated, thanks.

我并不坚持使用MessagePack进行序列化,这是EasyCending在其安装指南中默认使用的。不过,我很感激你的帮助,谢谢。


更多回答
优秀答案推荐

So I ended up changing the serialization method, since I couldn't do anything else with MessagePack. Using json, the problem is solved:

因此,我最终更改了序列化方法,因为我不能使用MessagePack执行其他任何操作。使用json,这个问题就解决了:


services.AddEasyCaching(options =>
{
options.UseRedis(config =>
{
config.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));

config.SerializerName = "myjson";
}, "redis1");

options.WithJson("myjson");
});

(I've changed the location of this configuration, hence the removal of builder at the start of the code)

(我已经更改了此配置的位置,因此删除了代码开头的Builder)


更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com