Friday, March 9, 2012

Added Secondary Index support to goriak

Have been pretty heads down on writing business software and was getting a little burnt. So to revive I hacked a little on the driver I have been playing with for Go (golang) to use Riak. There are basically 3 motivations other than I need to do a little fun hacking to recharge the batteries.
  1. Go weekly is getting close to version 1 so they added packaging using the "go command" which I cover in a previous blog.
  2. Riak add secondary index which is so much more developer friendly than before.
  3. The types of problems I really enjoy solving are ones that Go and Riak would be good tools for.
Quick recap is that I had the basic support for key/value store with a hint to the type to structure to marshal it would do the conversion of struct to json and back. Get, Put and Delete basically was all that was implemented at the time. 
Secondary Indexes provide a binary (string) and integer types for indexing. I implemented exact match and range queries. So method signatures:

SearchBin(bucketName, index, value string) ([]string, error) 

SearchBinRange(bucketName, index string, start, end string) ([]string, error) 

SearchInt(bucketName, index string, value int) ([]string, error) 

SearchIntRange(bucketName, index string, start, end int) ([]string, error) 

Now there is a complete example included with the source code:




Time to billed that kill web service! Source code is on bitbucket: https://bitbucket.org/lateefj/goriak/