himekami
himekami

Reputation: 1459

Using redis.io to store object

I'm developing a windows server application which primary functions are to store object data (may come in serialized objects or jsons or xmls or binaries) and retrieve them in a very fast way.

I read that a lot of people are recommending redis.io and also the fact the stackexchange has the necessary bindings makes me want to go this route.

The problem is i don't get the idea of how to come up with the "key" value in order to store that particular data in the db. Am i supposed to resort to hashed value as the key? or is there an auto-created key i can use in redis.io ?

Thank you.

Upvotes: 0

Views: 1637

Answers (1)

Manu Manjunath
Manu Manjunath

Reputation: 6421

Yes, Redis can be used for object caching and Stack Exchange's Redis client for C# works pretty well.

Few things:

  • Redis doesn't have a key auto-generation mechanism
  • Generate an id of your own. Form a key like class-full-name#object_id, where you generate the object id.
  • Do not rely on Object.GetHashCode().
  • Maintain the relation between 'Redis key' to 'object serialised data' externally. That is, if you are using a List<Employee>, change them to Dictionary<String, Employee> (where key is the object id)
  • Redis supports dictionaries (calls it 'hashes') - these are best suited for object persistence. Instead of serialising the entire object and storing it as a single key, you can store the object in a 'hash' with fields as variable names of class and values as variable values. This enables faster retrieval if you want to fetch selected fields of the object. (See: http://redis.io/topics/data-types#hashes, http://redis.io/commands/#hash)

Upvotes: 2

Related Questions