我目前正在使用内存缓存,并希望使用 Redis 切换到分布式缓存机制。我查看了 ServiceStack 的客户端,但限速许可对我不起作用,因此似乎推荐使用 Booksleeve。
我已经设置了一个测试程序来设置并从 Booksleeve 返回相同的值,但我得到的结果似乎不是我预期的格式,我不确定什么是正确的方法处理这个是(我可以看到的文档方式并不多)。这是我的简单测试程序:
RedisConnection conn = new RedisConnection("localhost", 6379);
conn.Open();
conn.Strings.Set(1, "test", 100);
var task = conn.Strings.Get(1, "test");
task.Wait();
var x = task.Result; // byte[] result = {49, 48, 48};
var str = BitConverter.ToString(x); // string result = "31-30-30";
var l = BitConverter.ToInt64(x, 0); // Destination array is not long enough to copy all the items in the collection. Check array index and length.
如您所见,我在任何时候都无法取回使用原始“Set”语句缓存的相同值“100”。有趣的是,我似乎无法按数值缓存(因为 Get 和 Set 是 的成员conn.Strings
)。推荐的方法是只处理.ToString()
所有数字键值吗?
关于为什么我无法取回原始缓存值(以及这样做的最佳实践)的任何解释将不胜感激。