首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ServiceStack.Redis IRedisTypedClient获取项目和计数

使用ServiceStack.Redis IRedisTypedClient获取项目和计数
EN

Stack Overflow用户
提问于 2014-04-10 03:04:59
回答 1查看 859关注 0票数 0

我刚刚开始使用ServiceStack.Redis。我可以将单独的键/值放入缓存并从缓存中获取它们。但是,我似乎不能获得缓存中的所有项或项的计数。

下面是代码

代码语言:javascript
复制
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);
}
EN

回答 1

Stack Overflow用户

发布于 2014-07-31 20:33:02

在您的CustomerEntity类中:(例如)

代码语言:javascript
复制
public string strManufacturer;

应替换为

代码语言:javascript
复制
public string strManufacturer { get; set; }

我猜想当getter和setter没有显式定义时,redis不能访问。

我无法在redis中存储我的C#对象,这个修改为我解决了这个问题。我得到的是输出

代码语言:javascript
复制
"{}"

在redis-cli中,当我在进行此修改之前“获得”密钥时,GetAll().Count返回0,就像您的情况一样。如果您打算在生产环境中使用ServiceStack.Redis,还应该注意它的许可条款。有关SO的讨论,请参阅here

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22971761

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档