Class: Rudis::List
Instance Method Summary
collapse
Methods inherited from Structure
#default_options, #del, #exists?, #expire, #expire_at, #redis_type, #rename, #ttl, #type, #watch
Methods inherited from Base
#default_options, #initialize, #key, #redis
Methods inherited from Rudis
key
Constructor Details
This class inherits a constructor from Rudis::Base
Instance Method Details
#[](thing) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/rudis/structures/list.rb', line 29
def [](thing)
if thing.is_a? Fixnum
index thing
elsif thing.is_a? Range
range thing
end
end
|
#all ⇒ Object
Also known as:
to_a
24
25
26
|
# File 'lib/rudis/structures/list.rb', line 24
def all
range 0..-1
end
|
#empty? ⇒ Boolean
10
11
12
|
# File 'lib/rudis/structures/list.rb', line 10
def empty?
len == 0
end
|
#index(i) ⇒ Object
14
15
16
|
# File 'lib/rudis/structures/list.rb', line 14
def index(i)
type.get(redis.lindex(key, i.to_i))
end
|
#len ⇒ Object
Also known as:
length, size, count
3
4
5
|
# File 'lib/rudis/structures/list.rb', line 3
def len
redis.llen(key)
end
|
#lpop ⇒ Object
Also known as:
shift
60
61
62
63
|
# File 'lib/rudis/structures/list.rb', line 60
def lpop
e = redis.lpop(key)
e && type.get(e)
end
|
#lpush(val) ⇒ Object
Also known as:
unshift, >>
54
55
56
|
# File 'lib/rudis/structures/list.rb', line 54
def lpush(val)
redis.lpush(key, type.put(val))
end
|
#range(range) ⇒ Object
18
19
20
21
22
|
# File 'lib/rudis/structures/list.rb', line 18
def range(range)
redis.lrange(key, range.first.to_i, range.last.to_i).map do |e|
type.get(e)
end
end
|
#rpop ⇒ Object
Also known as:
pop
48
49
50
51
|
# File 'lib/rudis/structures/list.rb', line 48
def rpop
e = redis.rpop(key)
e && type.get(e)
end
|
#rpush(val) ⇒ Object
Also known as:
push, <<
42
43
44
|
# File 'lib/rudis/structures/list.rb', line 42
def rpush(val)
redis.rpush(key, type.put(val))
end
|
#set(i, val) ⇒ Object
Also known as:
[]=
37
38
39
|
# File 'lib/rudis/structures/list.rb', line 37
def set(i, val)
redis.lset(key, i.to_i, type.put(val))
end
|
#trim(range) ⇒ Object
Also known as:
trim!
66
67
68
|
# File 'lib/rudis/structures/list.rb', line 66
def trim(range)
redis.trim(key, range.first.to_i, range.last.to_i)
end
|