Module: Lite::Redis::StringHelper
Instance 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
Instance Method Details
#append(key, value) ⇒ Object
50 51 52 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 50 def append(key, value) client.append(key.to_s, value) end |
#bit_count(key, start = 0, finish = -1)) ⇒ Object
78 79 80 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 78 def bit_count(key, start = 0, finish = -1) client.bitcount(key.to_s, start, finish) end |
#bit_where(operation, key, *keys) ⇒ Object
82 83 84 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 82 def bit_where(operation, key, *keys) client.bitop(operation, key, *keys) end |
#create(key, value, opts = {}) ⇒ Object
24 25 26 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 24 def create(key, value, opts = {}) client.set(key.to_s, value, **opts) end |
#create!(key, value) ⇒ Object
28 29 30 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 28 def create!(key, value) client.setnx(key.to_s, value) end |
#create_each(*args) ⇒ Object
32 33 34 35 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 32 def create_each(*args) args = stringify_keys(*args) client.mset(args) end |
#create_each!(*args) ⇒ Object
37 38 39 40 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 37 def create_each!(*args) args = stringify_keys(*args) client.msetnx(args) end |
#create_until(key, value, seconds, format = :seconds) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 42 def create_until(key, value, seconds, format = :seconds) if seconds?(format) client.setex(key.to_s, seconds, value) else client.psetex(key.to_s, seconds, value) end end |
#decrement(key, value = 1) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 58 def decrement(key, value = 1) if value == 1 client.decr(key.to_s) else client.decrby(key.to_s, value) end end |
#find(key) ⇒ Object
7 8 9 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 7 def find(key) client.get(key.to_s) end |
#find_each(*args) ⇒ Object
11 12 13 14 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 11 def find_each(*args) args = stringify_keys(*args) client.mget(args) end |
#get_bit(key, offset) ⇒ Object
86 87 88 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 86 def get_bit(key, offset) client.getbit(key.to_s, offset) end |
#increment(key, value = 1) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 66 def increment(key, value = 1) case value when Float then client.incrbyfloat(key.to_s, value) when 1 then client.incr(key.to_s) else client.incrby(key.to_s, value) end end |
#length(key) ⇒ Object
16 17 18 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 16 def length(key) client.strlen(key.to_s) end |
#replace(key, value, offset) ⇒ Object
54 55 56 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 54 def replace(key, value, offset) client.setrange(key.to_s, offset, value) end |
#reset(key, value = 0) ⇒ Object
74 75 76 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 74 def reset(key, value = 0) client.getset(key.to_s, value) end |
#set_bit(key, offset, bit) ⇒ Object
90 91 92 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 90 def set_bit(key, offset, bit) client.setbit(key.to_s, offset, bit) end |
#split(key, start, finish) ⇒ Object
20 21 22 |
# File 'lib/lite/redis/helpers/string_helper.rb', line 20 def split(key, start, finish) client.getrange(key.to_s, start, finish) end |