2014-04-09 72 views
0

我刚开始使用ServiceStack.Redis。我可以将各个键/值放入缓存并从缓存中获取它们。但是,我似乎无法获取缓存中的所有项目或计数项目。使用ServiceStack.Redis获取项目和计数IRedisTypedClient

下面的代码

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); 
} 

回答

0

在你CustomerEntity类: (EG)

public string strManufacturer; 

public string strManufacturer { get; set; } 

我想Redis的无法访问时更换getter和setter没有明确的定义。

我无法将我的C#对象存储在redis中,此修改解决了我的问题。 我正在在Redis的-CLI输出

"{}" 

使这一修改和GETALL()之前,当我“获得”的关键。计数返回0,在您的情况。 如果您要在生产环境中使用ServiceStack.Redis,您还应该注意ServiceStack.Redis的许可条款。有关SO的讨论,请参阅here