Module: Sohm::Collection
Instance Method Summary collapse
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#fetch(ids) ⇒ Object
Wraps the whole pipelining functionality.
-
#to_a ⇒ Object
Fetch the data from Redis in one go.
-
#to_json(*args) ⇒ Object
Sugar for to_a.to_json for all types of Sets.
Instance Method Details
#each ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'lib/sohm.rb', line 136 def each if block_given? ids.each_slice(1000) do |slice| fetch(slice).each { |e| yield(e) } end else to_enum end end |
#empty? ⇒ Boolean
151 152 153 |
# File 'lib/sohm.rb', line 151 def empty? size == 0 end |
#fetch(ids) ⇒ Object
Wraps the whole pipelining functionality.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/sohm.rb', line 156 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| unless atts.empty? result << model.new(Utils.dict(atts).update(:id => ids[idx])) end end end end |
#to_a ⇒ Object
Fetch the data from Redis in one go.
147 148 149 |
# File 'lib/sohm.rb', line 147 def to_a fetch(ids) end |
#to_json(*args) ⇒ Object
Sugar for to_a.to_json for all types of Sets
13 14 15 |
# File 'lib/sohm/json.rb', line 13 def to_json(*args) to_a.to_json(*args) end |