简体   繁体   中英

Storing custom .Net objects in Azure Redis Cache with StackExchange.Redis

We're implementing StackExchange.Redis for storing all information regarding three e-commerce sites (aproximately 18,500 products). The information is stored in a SQL Server database, mapped to custom objects and then added in an Azure Redis Cache using this key naming convention:

urn:products:{0}:{1}

(where 0 is the store identifier and 1 is the product identifier). I read Where are KEYS, SCAN, FLUSHDB etc? and was able to get keys matching the urn:products:{0} by pattern. The issue that we´re facing is that our project involves a lot of GetAllProducts List < Products > , GetAllCategories List < Categories > and then used by LINQ functions.

Based on this:

  • I tried storing all products (list of custom objects) in one key ( urn:products:all ), but that approach generated timeouts in Azure Redis Cache. Is this method the suggested one? Or is it preferable to store each product in separate keys?
  • I don't think that is correct to loop each of the keys to get each value. Is it possible to get a collection of keys/values by pattern?
  • I also read HASHES, however I don't think that they help in our requirement.

I'm wondering your approach to call tons of records at once. I recommend to slice them no more than a thousand records.

Redis only has very limited feature, so your requirement may not be fulfilled. Redis is good for cache or simple key-value getter and setter. For that, you may consider other memory-based databases such as MongoDB.

In your case, Redis Set is the best approach to combine or substract with given conditions, or Hash is for property-based object storing. Whatever approach you choose, you will use two or more datatypes because Redis datatypes are not so versatile.

RedisCookbook describes good example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM