Reputation: 4124
I am using stackexchange.redis api to access simple List of string into Redis. Now I needed to Add/Update/Delete/Get List into redis Then Access the objects like lst.Find(h=>h.Id == "1") e.t.c Basically a functionality to Manipulate ReferenceType object. I can't find it build in there. Anybody know how can i do this?
Upvotes: 3
Views: 2849
Reputation: 1063964
This is a broad subject. There are two ways of storing complex objects in Redis: serialization, and hashes. Serialization is opaque blobs - only(usually) interpreted by the calling application. I discussed this in this github issue that I suspect is also you. Hashes are name/value pairs inside a single key (kinda like dynamic database columns, ... -ish) - this allows fetch of a subset of properties, etc.
Note that you can't have hashes inside lists.
Next we have the issue of lookup by an id. If you use a Redis list, you can fetch by position only: not by some property. I suspect you're also thinking of Redis with RDBMS goggles, but Redis simply doesnt work like that.
Personally, I would have a key per item, named by the primary key. For example keys like /user/12345
. Then fetching (or updating) user 12345 is a case of reading (or writing) to the key by name. Redis does not natively support additional indexing, but you can implement indexes manually using additional storage. For example, a hash in /users/ssid
that maps whatever572618
to the user that has that id.
Josiah Carlson's "Redis in Action" book may be of use to you in understanding how to work with Redis.
Upvotes: 2