我刚刚开始使用ServiceStack.Redis。我可以将单独的键/值放入缓存并从缓存中获取它们。但是,我似乎不能获得缓存中的所有项或项的计数。
下面是代码
using (RedisClient cacheClient = new RedisClient(cacheServer))
{
IRedisTypedClient<CustomerEntity> customerCache = cacheClient.As<CustomerEntity>();
customer = bl.FetchCustomer(customerId);
//cache for two minutes
customerCache.SetEntry(customerId, customer, new TimeSpan(0, 2, 0));
//These all show the count as 0
logger.Debug(customerCache.GetAll().Count);
logger.Debug(cacheClient.GetAll<CustomerEntity>().Count);
var customers = customerCache.GetAll();
logger.Debug("{0} customers in the cache", customers.Count);
}发布于 2014-07-31 20:33:02
在您的CustomerEntity类中:(例如)
public string strManufacturer;应替换为
public string strManufacturer { get; set; }我猜想当getter和setter没有显式定义时,redis不能访问。
我无法在redis中存储我的C#对象,这个修改为我解决了这个问题。我得到的是输出
"{}"在redis-cli中,当我在进行此修改之前“获得”密钥时,GetAll().Count返回0,就像您的情况一样。如果您打算在生产环境中使用ServiceStack.Redis,还应该注意它的许可条款。有关SO的讨论,请参阅here。
https://stackoverflow.com/questions/22971761
复制相似问题