thepirat000 / CachingFramework.Redis

Distributed caching based on StackExchange.Redis and Redis. Includes support for tagging and is cluster-compatible.
Other
287 stars 52 forks source link

Get data from a Hash key contains many small list object in a request to Redis #50

Closed minhncud closed 5 years ago

minhncud commented 5 years ago

Me again, i'm sorry but i have a question. Simple, we have context.Collections.GetRedisDictionary<type, T>("hashkey") to take a hashkey in Redis. But if i have a class: class MultiObject { List list1 { get; set; } List list2 { get; set; } List list3 { get; set; } }

Can i get or set to a hashkey like that: hashkey

It uses to store lists of multiple type objects which have 1~5 records each type. Thank you.

thepirat000 commented 5 years ago

Maybe I don't understand your question, but it looks like you need to store a JSON string on each hash field?

Nothing stops you to do that as long as your class is serializable/deseralizable under the serialization method used.

The values are serialized when storing them on the Redis hash fields,

minhncud commented 5 years ago

Edit: My bad, i think much about RedisDictionary and forgot context.Cache.GetHashedAll("keyname"). Thank you very much and you don't need read below.


This sample is easier to read cake

  • If i only have first 3 fields, i can use context.Collections.GetRedisDictionary<string, Fruit>("HashObjects") to add or get values in Fruit object

  • But in this photo, if i use context.Collections.GetRedisDictionary<string, Fruit>("HashObjects") to get Fruit values and context.Collections.GetRedisDictionary<string, Cake>("HashObjects") to get Cake values, it returns nothing.

  • I want to store both Fruit and Cake in Food like this: food

  • About serialization between Object and Json, do you mean using string as context.Collections.GetRedisDictionary<string, string>("HashObjects") ?