Sha256: 06dc54145413675e25027b8a63b352c6f09679be78b8ae72bbf34ac55c05749d
Contents?: true
Size: 828 Bytes
Versions: 2
Compression:
Stored size: 828 Bytes
Contents
module Lunar class ResultSet include Enumerable attr :key def initialize(key, &block) @key = key @block = block end def each(&block) all.each(&block) end end class SortedResultSet < ResultSet def all(options = {}) start = Integer(options[:start] || 0) limit = Integer(options[:limit] || 0) finish = start + limit - 1 Lunar.redis.zrevrange(key, start, finish).map(&@block) end def size Lunar.redis.zcard(key) end end class UnsortedResultSet < ResultSet def all(options = {}) start = Integer(options[:start] || 0) limit = Integer(options[:limit] || 100) Lunar.redis.sort(key, :limit => [start, limit]).map(&@block) end def size Lunar.redis.scard(key) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
lunar-0.4.1 | lib/lunar/result_set.rb |
lunar-0.4.0 | lib/lunar/result_set.rb |