Leveraging Redis Hashes and the StackExchange API for Rapid Prototyping
The Redis Cache is a excellent persistence option for rapid storage and retrieval of cached data. Also referred to as a store for key-value pairs, or a data structure server, Redis is fairly easy to both learn and use. For learning, I used Karl Seguin's post on Redis along with the searchable index of commands provided by Redis. To make life easier, I also included the general purpose Redis client written by the developers at StackExchange.
Here are my methods that mimic basic CRUD operations for a generic product or service issues list using Redis instead of a database. The RedisKey is just a C# string, but doesn't have to be. You'll notice I use hashes instead of strings in the methods below. The reason for this is not so I can have one key to manage a collection of field/value pairs within a Redis hash. What's the difference between a string's key and its corresponding value and a hash's field and its corresponding value other than implementation and efficiency? When using hashes, you need a key to retrieve the hash itself, and a field "value" to retrieve the actual "value" associated with the field. When you choose to use strings, the key is used as a value you associate with another value.
A key is very much like a key in a dictionary or associative array. For strings, all you need is the key to look up your corresponding value, which can be many different .NET types, including a binary object. The key used for setting and getting hashes is similar, but you will retrieve the entire hash of field/value pairs using a single key. Should you wish to retrieve a hash field/value pair, you can do that too, and easily, but you need both the key and the field value.
Efficieny; this leads me to the next point, which is taken from "An introduction to Redis data types and abstractions"; "It is worth noting that small hashes (i.e., a few elements with small values) are encoded in special way in memory that make them very memory efficient" (http://redis.io/topics/data-types-intro). Interestingly enough, the Redis command(s) docs state that "Redis running on an entry level laptop can scan a 1 million key database in 40 milliseconds."