Module: RedisModel::Types::List

Includes:
Base
Defined in:
lib/redis_model/types/list.rb

Overview

Internal: Methods needed for List type.

Instance Method Summary collapse

Methods included from Base

#connection, #del, #exists?

Instance Method Details

#<<(value) ⇒ Object Also known as: push

Public: Pushes a element into the list using RPUSH command.

Returns true.



33
34
35
# File 'lib/redis_model/types/list.rb', line 33

def <<(value)
  connection.rpush key_label, value
end

#[](index) ⇒ Object

Public: Retrieves a element in the list using LINDEX command.

Returns String containing value of the specified element.



26
27
28
# File 'lib/redis_model/types/list.rb', line 26

def [](index)
  connection.lindex key_label, index
end

#countObject Also known as: length

Public: Retrieves length of Redis list using LLEN command.

Returns Integer containing length of the list.



17
18
19
# File 'lib/redis_model/types/list.rb', line 17

def count
  connection.llen key_label
end

#to_aObject

Public: Fetches elements in Redis list as Array using LRANGE command.

Returns Array containing elements in the list.



10
11
12
# File 'lib/redis_model/types/list.rb', line 10

def to_a
  connection.lrange key_label, 0, -1
end