2014-04-09 71 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