Search code examples
ruby-on-railsrubyredisohm

Ohm & Redis: when to use set, list or collection?


What is the difference between a collection and a set or list when using Ohm & Redis?

Several of the Ohm examples use a list rather than a collection (see the list doc itself):

class Post < Ohm::Model
  list :comments, Comment
end

class Comment < Ohm::Model
end

What is the rationale for this design choice?


Solution

  • List - ordered list of elements. When you request the entire list, you get the items ordered the way you put them in the list.

    Collection - unordered collection of elements. When you request the collection, items may appear in random order (e.g. unordered).**

    In your example, comments are ordered.

    ** I know that random is not the same as unordered, but it does illustrate the point.