module Sohm::Collection

Public Instance Methods

each() { |e| ... } click to toggle source
# File lib/sohm.rb, line 139
def each
  if block_given?
    ids.each_slice(1000) do |slice|
      fetch(slice).each { |e| yield(e) }
    end
  else
    to_enum
  end
end
empty?() click to toggle source
# File lib/sohm.rb, line 154
def empty?
  size == 0
end
fetch(ids) click to toggle source

Wraps the whole pipelining functionality.

# File lib/sohm.rb, line 159
def fetch(ids)
  data = nil

  model.synchronize do
    ids.each do |id|
      redis.queue("HGETALL", namespace[id])
    end

    data = redis.commit
  end

  return [] if data.nil?

  [].tap do |result|
    data.each_with_index do |atts, idx|
      if atts.is_a?(Array) && atts.size > 0
        result << model.new(Utils.dict(atts).update(:id => ids[idx]))
      end
    end
  end
end
to_a() click to toggle source

Fetch the data from Redis in one go.

# File lib/sohm.rb, line 150
def to_a
  fetch(ids)
end
to_json(*args) click to toggle source

Sugar for to_a.to_json for all types of Sets

# File lib/sohm/json.rb, line 13
def to_json(*args)
  to_a.to_json(*args)
end