Class: Ohm::List
- Inherits:
-
Collection
- Object
- Collection
- Ohm::List
- Defined in:
- lib/ohm/collection.rb
Overview
Represents a Redis list.
Instance Method Summary (collapse)
- - (Object) <<(value) (also: #push)
-
- (Array) all
Elements of the list.
- - (Boolean) include?(value)
- - (Object) inspect
-
- (String) pop
Return and remove the last element of the list.
-
- (String) shift
Return and remove the first element of the list.
-
- (Integer) size
Returns the number of elements in the list.
- - (Object) unshift(value)
Methods inherited from Collection
#==, #[], #clear, #concat, #each, #empty?, #first, #initialize, #replace, #sort, #to_ary
Constructor Details
This class inherits a constructor from Ohm::Collection
Instance Method Details
- (Object) <<(value) Also known as: push
104 105 106 |
# File 'lib/ohm/collection.rb', line 104 def << value db.rpush(key, value) end |
- (Array) all
Elements of the list.
126 127 128 |
# File 'lib/ohm/collection.rb', line 126 def all db.lrange(key, 0, -1) end |
- (Boolean) include?(value)
135 136 137 |
# File 'lib/ohm/collection.rb', line 135 def include?(value) all.include?(value) end |
- (Object) inspect
139 140 141 |
# File 'lib/ohm/collection.rb', line 139 def inspect "#<List: #{all.inspect}>" end |
- (String) pop
Return and remove the last element of the list.
111 112 113 |
# File 'lib/ohm/collection.rb', line 111 def pop db.rpop(key) end |
- (String) shift
Return and remove the first element of the list.
116 117 118 |
# File 'lib/ohm/collection.rb', line 116 def shift db.lpop(key) end |
- (Integer) size
Returns the number of elements in the list.
131 132 133 |
# File 'lib/ohm/collection.rb', line 131 def size db.llen(key) end |
- (Object) unshift(value)
121 122 123 |
# File 'lib/ohm/collection.rb', line 121 def unshift(value) db.lpush(key, value) end |