Class: Lite::Redis::List
- Inherits:
-
Base
- Object
- Base
- Lite::Redis::List
show all
- Defined in:
- lib/lite/redis/list.rb
Instance Attribute Summary
Attributes inherited from Base
#client
Instance Method Summary
collapse
-
#all(key) ⇒ Object
-
#between(key, start = 1, finish = 0) ⇒ Object
-
#count(key) ⇒ Object
-
#create(key, value, order = :prepend) ⇒ Object
-
#create!(key, value, order = :prepend) ⇒ Object
-
#create_after(key, pivot, value) ⇒ Object
-
#create_before(key, pivot, value) ⇒ Object
-
#create_limit(key, value, limit, order = :prepend) ⇒ Object
-
#create_limit!(key, value, limit, order = :prepend) ⇒ Object
-
#destroy(key, count, value) ⇒ Object
-
#destroy_all(key) ⇒ Object
-
#destroy_except(key, start, finish) ⇒ Object
-
#destroy_first(key, limit = 1) ⇒ Object
-
#destroy_last(key, limit = 1) ⇒ Object
-
#find(key, position = 1) ⇒ Object
-
#first(key, limit = 1) ⇒ Object
-
#last(key, limit = 1) ⇒ Object
-
#move(key, desination) ⇒ Object
-
#move_blocking(key, desination) ⇒ Object
-
#pop(key, order = :prepend) ⇒ Object
-
#pop_blocking(keys, opts = {}) ⇒ Object
-
#update(key, index, value) ⇒ Object
Methods inherited from Base
#initialize, method_missing, #respond_to_method?, #respond_to_missing?
Instance Method Details
#all(key) ⇒ Object
29
30
31
|
# File 'lib/lite/redis/list.rb', line 29
def all(key)
client.lrange(key.to_s, 0, -1)
end
|
#between(key, start = 1, finish = 0) ⇒ Object
25
26
27
|
# File 'lib/lite/redis/list.rb', line 25
def between(key, start = 1, finish = 0)
client.lrange(key.to_s, start - 1, finish - 1)
end
|
#count(key) ⇒ Object
33
34
35
|
# File 'lib/lite/redis/list.rb', line 33
def count(key)
client.llen(key.to_s)
end
|
#create(key, value, order = :prepend) ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/lite/redis/list.rb', line 37
def create(key, value, order = :prepend)
if append?(order)
client.rpush(key.to_s, value)
else
client.lpush(key.to_s, value)
end
end
|
#create!(key, value, order = :prepend) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/lite/redis/list.rb', line 45
def create!(key, value, order = :prepend)
if append?(order)
client.rpushx(key.to_s, value)
else
client.lpushx(key.to_s, value)
end
end
|
#create_after(key, pivot, value) ⇒ Object
77
78
79
|
# File 'lib/lite/redis/list.rb', line 77
def create_after(key, pivot, value)
client.linsert(key.to_s, :after, pivot, value)
end
|
#create_before(key, pivot, value) ⇒ Object
73
74
75
|
# File 'lib/lite/redis/list.rb', line 73
def create_before(key, pivot, value)
client.linsert(key.to_s, :before, pivot, value)
end
|
#create_limit(key, value, limit, order = :prepend) ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/lite/redis/list.rb', line 53
def create_limit(key, value, limit, order = :prepend)
if append?(order)
client.rpush(key.to_s, value)
else
client.lpush(key.to_s, value)
end
client.ltrim(key.to_s, 0, limit - 1)
end
|
#create_limit!(key, value, limit, order = :prepend) ⇒ Object
63
64
65
66
67
68
69
70
71
|
# File 'lib/lite/redis/list.rb', line 63
def create_limit!(key, value, limit, order = :prepend)
if append?(order)
client.rpushx(key.to_s, value)
else
client.lpushx(key.to_s, value)
end
client.ltrim(key.to_s, 0, limit - 1)
end
|
#destroy(key, count, value) ⇒ Object
93
94
95
|
# File 'lib/lite/redis/list.rb', line 93
def destroy(key, count, value)
client.lrem(key.to_s, count, value)
end
|
#destroy_all(key) ⇒ Object
109
110
111
|
# File 'lib/lite/redis/list.rb', line 109
def destroy_all(key)
client.ltrim(key.to_s, -1, 0)
end
|
#destroy_except(key, start, finish) ⇒ Object
105
106
107
|
# File 'lib/lite/redis/list.rb', line 105
def destroy_except(key, start, finish)
client.ltrim(key.to_s, start - 1, finish - 1)
end
|
#destroy_first(key, limit = 1) ⇒ Object
97
98
99
|
# File 'lib/lite/redis/list.rb', line 97
def destroy_first(key, limit = 1)
client.ltrim(key.to_s, limit, -1)
end
|
#destroy_last(key, limit = 1) ⇒ Object
101
102
103
|
# File 'lib/lite/redis/list.rb', line 101
def destroy_last(key, limit = 1)
client.ltrim(key.to_s, 0, -(limit + 1))
end
|
#find(key, position = 1) ⇒ Object
7
8
9
|
# File 'lib/lite/redis/list.rb', line 7
def find(key, position = 1)
client.lindex(key.to_s, position - 1)
end
|
#first(key, limit = 1) ⇒ Object
11
12
13
14
15
16
|
# File 'lib/lite/redis/list.rb', line 11
def first(key, limit = 1)
value = client.lrange(key.to_s, 0, -1)
return value.first if limit == 1
value.first(limit)
end
|
#last(key, limit = 1) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/lite/redis/list.rb', line 18
def last(key, limit = 1)
value = client.lrange(key.to_s, 0, -1)
return value.last if limit == 1
value.last(limit)
end
|
#move(key, desination) ⇒ Object
85
86
87
|
# File 'lib/lite/redis/list.rb', line 85
def move(key, desination)
client.rpoplpush(key.to_s, desination.to_s)
end
|
#move_blocking(key, desination) ⇒ Object
89
90
91
|
# File 'lib/lite/redis/list.rb', line 89
def move_blocking(key, desination)
brpoplpush(key.to_s, desination.to_s)
end
|
#pop(key, order = :prepend) ⇒ Object
113
114
115
116
117
118
119
|
# File 'lib/lite/redis/list.rb', line 113
def pop(key, order = :prepend)
if append?(order)
client.rpop(key)
else
client.lpop(key)
end
end
|
#pop_blocking(keys, opts = {}) ⇒ Object
121
122
123
124
125
126
127
128
129
|
# File 'lib/lite/redis/list.rb', line 121
def pop_blocking(keys, opts = {})
timeout = opts[:timeout] || 0
if append?(opts[:order] || :prepend)
client.brpop(keys, timeout)
else
client.blpop(keys, timeout)
end
end
|
#update(key, index, value) ⇒ Object
81
82
83
|
# File 'lib/lite/redis/list.rb', line 81
def update(key, index, value)
client.lset(key.to_s, index, value)
end
|