Class: ActiveOrm::Redis::String
- Defined in:
- lib/active_orm/redis/string.rb
Class Method Summary collapse
- .append(key, value) ⇒ Object
- .bit_count(key, start = 0, finish = -1)) ⇒ Object
- .bit_where(operation, key, *keys) ⇒ 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
Methods inherited from Base
Class Method Details
.append(key, value) ⇒ Object
55 56 57 |
# File 'lib/active_orm/redis/string.rb', line 55 def append(key, value) client.append(normalize_key(key), value) end |
.bit_count(key, start = 0, finish = -1)) ⇒ Object
83 84 85 |
# File 'lib/active_orm/redis/string.rb', line 83 def bit_count(key, start = 0, finish = -1) client.bitcount(normalize_key(key), start, finish) end |
.bit_where(operation, key, *keys) ⇒ Object
87 88 89 |
# File 'lib/active_orm/redis/string.rb', line 87 def bit_where(operation, key, *keys) client.bitop(operation, key, *keys) end |
.create(key, value, opts = {}) ⇒ Object
27 28 29 |
# File 'lib/active_orm/redis/string.rb', line 27 def create(key, value, opts = {}) client.set(normalize_key(key), value, opts) end |
.create!(key, value) ⇒ Object
31 32 33 |
# File 'lib/active_orm/redis/string.rb', line 31 def create!(key, value) client.setnx(normalize_key(key), value) end |
.create_each(*args) ⇒ Object
35 36 37 38 |
# File 'lib/active_orm/redis/string.rb', line 35 def create_each(*args) args = stringify_keys(args) client.mset(args) end |
.create_each!(*args) ⇒ Object
40 41 42 43 |
# File 'lib/active_orm/redis/string.rb', line 40 def create_each!(*args) args = stringify_keys(args) client.msetnx(args) end |
.create_until(key, value, seconds, format = :seconds) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/active_orm/redis/string.rb', line 45 def create_until(key, value, seconds, format = :seconds) normalized_key = normalize_key(key) if seconds?(format) client.setex(normalized_key, seconds, value) else client.psetex(normalized_key, seconds, value) end end |
.decrement(key, value = 1) ⇒ Object
63 64 65 66 67 |
# File 'lib/active_orm/redis/string.rb', line 63 def decrement(key, value = 1) normalized_key = normalize_key(key) value == 1 ? client.decr(normalized_key) : client.decrby(normalized_key, value) end |
.find(key) ⇒ Object
6 7 8 9 10 |
# File 'lib/active_orm/redis/string.rb', line 6 def find(key) value = client.get(normalize_key(key)) value = (value) if evaluate? value end |
.find_each(*args) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/active_orm/redis/string.rb', line 12 def find_each(*args) args = stringify_keys(args) value = client.mget(args) value = (value) if evaluate? value end |
.get_bit(key, offset) ⇒ Object
91 92 93 |
# File 'lib/active_orm/redis/string.rb', line 91 def get_bit(key, offset) client.getbit(normalize_key(key), offset) end |
.increment(key, value = 1) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/active_orm/redis/string.rb', line 69 def increment(key, value = 1) normalized_key = normalize_key(key) if value.is_a?(Float) client.incrbyfloat(normalized_key, value) else value == 1 ? client.incr(normalized_key) : client.incrby(normalized_key, value) end end |
.length(key) ⇒ Object
19 20 21 |
# File 'lib/active_orm/redis/string.rb', line 19 def length(key) client.strlen(normalize_key(key)) end |
.replace(key, value, offset) ⇒ Object
59 60 61 |
# File 'lib/active_orm/redis/string.rb', line 59 def replace(key, value, offset) client.setrange(normalize_key(key), offset, value) end |
.reset(key, value = 0) ⇒ Object
79 80 81 |
# File 'lib/active_orm/redis/string.rb', line 79 def reset(key, value = 0) client.getset(normalize_key(key), value) end |
.set_bit(key, offset, bit) ⇒ Object
95 96 97 |
# File 'lib/active_orm/redis/string.rb', line 95 def set_bit(key, offset, bit) client.setbit(normalize_key(key), offset, bit) end |
.split(key, start, finish) ⇒ Object
23 24 25 |
# File 'lib/active_orm/redis/string.rb', line 23 def split(key, start, finish) client.getrange(normalize_key(key), start, finish) end |