Skip to content
Victor Rodrigues edited this page Aug 8, 2013 · 1 revision

If you want to have friends sorted by some weight (say, BFF: 100, family: 80, colleague: 40, …), you can use a sorted_set for that.

friends = Hari('user#42').sorted_set(:friends)

=> #<Hari::Keys::SortedSet:0x007fb5c42a6df0>

This returns an object to call Redis sorted_set operations. If you want instead all the sorted set members, call it with the hashbang !

Hari('user#42').sorted_set!(:friends_ids)

=> ["bill", "john", "mark"]

These are the operations you can do with a sorted set in Hari:

friends.add 10, 'john', 30, 'bill', 50, 'jack'
friends << [10, 'john', 30, 'bill', 50, 'jack']

friends.count # also .size or .length
friends.empty?
friends.one?
friends.many?

friends.delete 'bill', 'jack'

friends.score 'john'

friends.include? 'john'

friends.rank 'john' # also .ranking or .position

friends.revrank 'john' # also .reverse_ranking
                       # or   .reverse_position

friends.members
Clone this wiki locally