Class: Redis::EnumerableObject

Inherits:
BaseObject show all
Includes:
Enumerable
Defined in:
lib/redis/enumerable_object.rb

Overview

Class representing a Redis enumerable type (list, set, sorted set, or hash).

Direct Known Subclasses

HashKey, List, Set, SortedSet

Instance Attribute Summary

Attributes inherited from BaseObject

#key, #options

Instance Method Summary collapse

Methods inherited from BaseObject

#allow_expiration, #initialize, #redis, #set_expiration, #to_hash, #to_json

Methods included from Helpers::CoreCommands

#delete, #exists, #exists?, #expire, #expireat, #marshal, #move, #persist, #rename, #renamenx, #serializer, #ttl, #type, #unmarshal

Constructor Details

This class inherits a constructor from Redis::BaseObject

Instance Method Details

#as_jsonObject

ActiveSupport’s core extension ‘Enumerable#as_json` implementation is incompatible with ours.



24
25
26
# File 'lib/redis/enumerable_object.rb', line 24

def as_json(*)
  to_hash
end

#each(&block) ⇒ Object

Iterate through each member. Redis::Objects mixes in Enumerable, so you can also use familiar methods like collect, detect, and so forth.



12
13
14
# File 'lib/redis/enumerable_object.rb', line 12

def each(&block)
  value.each(&block)
end

#sort(options = {}) ⇒ Object



16
17
18
19
20
21
# File 'lib/redis/enumerable_object.rb', line 16

def sort(options={})
  return super() if block_given?
  options[:order] = "asc alpha" if options.keys.count == 0  # compat with Ruby
  val = redis.sort(key, **options)
  val.is_a?(Array) ? val.map{|v| unmarshal(v)} : val
end