What is the easiest way to simulate a database table with an index in a key value store?

database, key-value, redis, riak

Solution

If you use Redis (an advanced key-value store that supports strings, lists, sets, etc.) Then this is quite easy. I have already developed a C# redis client that has native support for storing POCO's data models. These exact same POCO's can be used by OrmLite to store it in a RDBMS.

By the way Redis is fast, I have a benchmark that stores and retrieves the entire Northwind Database (3202 records) in under 1.2 seconds (running inside a UnitTest on a 3yo iMac).

I store entities in two ways

- Distinct entities, where I combine the Class type name and Primary Key to create a unique key e.g. `urn:user:1`

- I then maintain a separate set of primary keys (in a Redis Set) to keep track of all my entities, using a key like: `ids:user`

- In a Redis server side list - which acts very much like a table with support for paging, using a key like: `lists:user`

Problem

What is the easiest way to simulate a database table with an index in a key value store? The key value store has NO ranged queries and NO ordered keys. The things I want to simulate (in order of priority): - Create tables - Add columns - Create indexes - Query based on primary key - Query based on arbitrary columns

Original source