Overactive Vocabulary

When In Doubt, Ameliorate

RSS

Relix 2.0.0

Relix is a Ruby library that makes it easy to build and use various types of secondary indexes backed by Redis. We use it heavily at Spreedly to give us fast access to our Riak-backed models (we didn’t use Riak’s secondary indexing since it didn’t exist when we started building Spreedly Core). Relix’s README is full of details on it’s philosophy and usage, and I’ll be doing a post eventually about why and how we use it at Spreedly.

Relix 2.0.0 brings a major version bump, due to the fact that it now requires Redis 2.6. This allows us to leverage Lua scripting, which is a big win for some use cases, especially since Relix does all it can to pipeline Redis requests.

The new feature driving the usage of Lua scripting is the ability to index and retrieve the list of values being indexed by a multi index:

1
2
3
4
5
6
class User
  relix.multi :account_id, index_values: true
end

# Enables this call
User.lookup_values(:account_id)

So whereas normally you’d look up all the users with a given account_id, lookup_values allows you to look up all the account id’s that are indexed. This is super handy for doing aggregate lookups by a multi index:

1
2
3
4
User.lookup_values(:account_id).each do |account_id|
  users_for_account = User.lookup{|q| q[:account_id].eq(account_id)}
  # Aggregate processing for the users in the account
end

2.0.0 also adds a deprecation mechanism and uses it to deprecate direct access to IndexSet#indexes in favor of IndexSet#[].

You can grab 2.0.0 hot off of Rubygems, report any issues you encounter on Github, and contact me via the details on my Github profile if there’s anything I can help with.

And let me know if you’re using Relix - I’d love to hear about anything and everything it’s being used for!