Class: ActiveOrm::Redis::String
Instance Attribute Summary
#client
Attributes inherited from Base
#configuration
Class Method Summary
collapse
-
.append(key, value) ⇒ Object
-
.bit_count(key, start = 0, finish = -1)) ⇒ Object
-
.create(key, value, opts = {}) ⇒ Object
-
.create!(key, value) ⇒ Object
-
.create_each(*args) ⇒ Object
-
.create_each!(*args) ⇒ Object
-
.create_until(key, value, seconds, format = :seconds) ⇒ Object
-
.decrement(key, value = 1) ⇒ Object
-
.find(key) ⇒ Object
-
.find_each(*args) ⇒ Object
-
.get_bit(key, offset) ⇒ Object
-
.increment(key, value = 1) ⇒ Object
-
.length(key) ⇒ Object
-
.replace(key, value, offset) ⇒ Object
-
.reset(key, value = 0) ⇒ Object
-
.set_bit(key, offset, bit) ⇒ Object
-
.split(key, start, finish) ⇒ Object
client, #initialize
Methods included from Base
#evaluate, #evaluate?
Methods inherited from Base
configuration, configuration=, configure
Class Method Details
.append(key, value) ⇒ Object
46
47
48
|
# File 'lib/active_orm/redis/string.rb', line 46
def self.append(key, value)
client.append(normalize_key(key), value)
end
|
.bit_count(key, start = 0, finish = -1)) ⇒ Object
70
71
72
|
# File 'lib/active_orm/redis/string.rb', line 70
def self.bit_count(key, start=0, finish=-1)
client.bitcount(normalize_key(key), start, finish)
end
|
.create(key, value, opts = {}) ⇒ Object
24
25
26
|
# File 'lib/active_orm/redis/string.rb', line 24
def self.create(key, value, opts={})
client.set(normalize_key(key), value, opts)
end
|
.create!(key, value) ⇒ Object
28
29
30
|
# File 'lib/active_orm/redis/string.rb', line 28
def self.create!(key, value)
client.setnx(normalize_key(key), value)
end
|
.create_each(*args) ⇒ Object
32
33
34
35
|
# File 'lib/active_orm/redis/string.rb', line 32
def self.create_each(*args)
args = stringify_keys(args)
client.mset(args)
end
|
.create_each!(*args) ⇒ Object
37
38
39
40
|
# File 'lib/active_orm/redis/string.rb', line 37
def self.create_each!(*args)
args = stringify_keys(args)
client.msetnx(args)
end
|
.create_until(key, value, seconds, format = :seconds) ⇒ Object
42
43
44
|
# File 'lib/active_orm/redis/string.rb', line 42
def self.create_until(key, value, seconds, format=:seconds)
seconds?(format) ? client.setex(normalize_key(key), seconds, value) : client.psetex(normalize_key(key), seconds, value)
end
|
.decrement(key, value = 1) ⇒ Object
54
55
56
|
# File 'lib/active_orm/redis/string.rb', line 54
def self.decrement(key, value=1)
(value == 1) ? client.decr(normalize_key(key)) : client.decrby(normalize_key(key), value)
end
|
.find(key) ⇒ Object
3
4
5
6
7
|
# File 'lib/active_orm/redis/string.rb', line 3
def self.find(key)
value = client.get(normalize_key(key))
value = metamorph(value) if evaluate?
return(value)
end
|
.find_each(*args) ⇒ Object
9
10
11
12
13
14
|
# File 'lib/active_orm/redis/string.rb', line 9
def self.find_each(*args)
args = stringify_keys(args)
value = client.mget(args)
value = metamorph(value) if evaluate?
return(value)
end
|
.get_bit(key, offset) ⇒ Object
74
75
76
|
# File 'lib/active_orm/redis/string.rb', line 74
def self.get_bit(key, offset)
client.getbit(normalize_key(key), offset)
end
|
.increment(key, value = 1) ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/active_orm/redis/string.rb', line 58
def self.increment(key, value=1)
if value.is_a?(Float)
client.incrbyfloat(normalize_key(key), value)
else
(value == 1) ? client.incr(normalize_key(key)) : client.incrby(normalize_key(key), value)
end
end
|
.length(key) ⇒ Object
16
17
18
|
# File 'lib/active_orm/redis/string.rb', line 16
def self.length(key)
client.strlen(normalize_key(key))
end
|
.replace(key, value, offset) ⇒ Object
50
51
52
|
# File 'lib/active_orm/redis/string.rb', line 50
def self.replace(key, value, offset)
client.setrange(normalize_key(key), offset, value)
end
|
.reset(key, value = 0) ⇒ Object
66
67
68
|
# File 'lib/active_orm/redis/string.rb', line 66
def self.reset(key, value=0)
client.getset(normalize_key(key), value)
end
|
.set_bit(key, offset, bit) ⇒ Object
78
79
80
|
# File 'lib/active_orm/redis/string.rb', line 78
def self.set_bit(key, offset, bit)
client.setbit(normalize_key(key), offset, bit)
end
|
.split(key, start, finish) ⇒ Object
20
21
22
|
# File 'lib/active_orm/redis/string.rb', line 20
def self.split(key, start, finish)
client.getrange(normalize_key(key), start, finish)
end
|