设置一个 zip 文件到 redis 缓存
Set a zip file to redis cache
我的问题是将 zip 文件保存并读取到位于 Azure 上的 Redis 缓存数据库。我用 StackExchange.Redis 尝试了一些东西,但我没有成功。你知道这方面的任何例子或解决方案吗?
我的代码像 that.For 这段代码我遇到超时错误。
ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("filecache.redis.cache.windows.net:6380,password=123,ssl=True,abortConnect=False");
IDatabase cache = connection.GetDatabase();
byte[] fileBytes = File.ReadAllBytes(@"c:\test.zip");
var str = Convert.ToBase64String(fileBytes);
cache.StringSet("f1", str);
var key1 = cache.StringGet("f1");
这是错误:
StackExchange.Redis.RedisTimeoutException occurred
HResult=0x80131505
Message=Timeout performing SET f1, inst: 0, mgr: Inactive, err: never, queue: 2, qu: 1, qs: 1, qc: 0, wr: 1, wq: 1, in: 0, ar: 0, clientName: NLBRLT-MCOPUR, serverEndpoint: Unspecified/BatchReportCache.redis.cache.windows.net:6380, keyHashSlot: 2046, IOCP: (Busy=0,Free=1000,Min=4,Max=1000), WORKER: (Busy=0,Free=2047,Min=4,Max=2047) (Please take a look at this article for some common client-side issues that can cause timeouts: http://stackexchange.github.io/StackExchange.Redis/Timeouts)
Source=StackExchange.Redis
首先,不建议大家上传大文件到redis缓存。
您收到此错误的原因是您将大文件上传到redis 缓存。上传文件和满足连接限制需要很多时间。
Redis是为小容量缓存设计的,不是大文件,如果你想上传大文件,请使用Azure存储。更详细的可以参考这个article.
如果您仍想向其上传大文件,您可以更改连接字符串中的 synctimeout 值。
改成这样:
ynctimeout=100000(this value is about when your request will time out),{redisname}.redis.cache.windows.net:6380,password={key},ssl=True,abortConnect=False
旁边的测试演示。
将zip上传到redis需要将近20秒。
我的问题是将 zip 文件保存并读取到位于 Azure 上的 Redis 缓存数据库。我用 StackExchange.Redis 尝试了一些东西,但我没有成功。你知道这方面的任何例子或解决方案吗?
我的代码像 that.For 这段代码我遇到超时错误。
ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("filecache.redis.cache.windows.net:6380,password=123,ssl=True,abortConnect=False");
IDatabase cache = connection.GetDatabase();
byte[] fileBytes = File.ReadAllBytes(@"c:\test.zip");
var str = Convert.ToBase64String(fileBytes);
cache.StringSet("f1", str);
var key1 = cache.StringGet("f1");
这是错误:
StackExchange.Redis.RedisTimeoutException occurred HResult=0x80131505 Message=Timeout performing SET f1, inst: 0, mgr: Inactive, err: never, queue: 2, qu: 1, qs: 1, qc: 0, wr: 1, wq: 1, in: 0, ar: 0, clientName: NLBRLT-MCOPUR, serverEndpoint: Unspecified/BatchReportCache.redis.cache.windows.net:6380, keyHashSlot: 2046, IOCP: (Busy=0,Free=1000,Min=4,Max=1000), WORKER: (Busy=0,Free=2047,Min=4,Max=2047) (Please take a look at this article for some common client-side issues that can cause timeouts: http://stackexchange.github.io/StackExchange.Redis/Timeouts) Source=StackExchange.Redis
首先,不建议大家上传大文件到redis缓存。
您收到此错误的原因是您将大文件上传到redis 缓存。上传文件和满足连接限制需要很多时间。
Redis是为小容量缓存设计的,不是大文件,如果你想上传大文件,请使用Azure存储。更详细的可以参考这个article.
如果您仍想向其上传大文件,您可以更改连接字符串中的 synctimeout 值。
改成这样:
ynctimeout=100000(this value is about when your request will time out),{redisname}.redis.cache.windows.net:6380,password={key},ssl=True,abortConnect=False
旁边的测试演示。
将zip上传到redis需要将近20秒。