0

I'm just starting to work with ServiceStack.Redis. I can put individual key/values into the cache and get them from the cache. However, I can't seem to get all items or a count of the items in the cache.

Here's the code

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);
}
jovball
  • 126
  • 1
  • 6

1 Answers1

0

In your CustomerEntity class: (e.g)

public string strManufacturer;

should be replaced as

public string strManufacturer { get; set; }

I guess redis can't access when the getter and the setter is not explicitly defined.

I was unable to store my C# objects in redis, this modification fixed the issue for me. I was getting output

"{}"

in redis-cli when I "get" the key before making this modification and GetAll().Count was returning 0 as in your situation. You should also pay attention of license terms of ServiceStack.Redis if you're going to use it in a production environment. See here for the discussion on SO.

Community
  • 1
  • 1