Sorting with Ohm

ohm redis monk


In the last 2 months of using Ohm, I have used sort a couple of times, and have ran into some gotchas.

Lesson 1: sort and sort_by are two different beasts

At first I thought that you can just do sort(:by => :field). The following example best illustrates what happens under the hood:

Lesson 2: ALPHA and DESC are friends.

If you come from an SQL world (I did), you may be used to just doing an ORDER BY and just expecting things to work. Here in redis, sort assumes you want it to sort by their double precision numbers by default, but you can also do lexical sorting. As usual, an example best illustrates the different scenarios:

Lesson 3: Will come up, because I'm making this up as I go

But on a more serious note, I need to grok the usecase of :get which corresponds to doing a GET in redis.

blog comments powered by Disqus