Module: RedisCluster::Function::String
- Included in:
- RedisCluster::Function
- Defined in:
- lib/redis_cluster/function/string.rb
Overview
String implement redis strings commands. There will be some adjustment for cluster. see redis.io/commands#string. Most of the code are copied from github.com/redis/redis-rb/blob/master/lib/redis.rb.
SETTER = [:getset, :append, :setbit, :setrange, :set, :setex, :psetex, :setnx, :incr,
:incrby, :incrbyfloat, :decr, :decrby]
GETTER = [:strlen, :bitpos, :bitcount, :getbit, :getrange, :get]
Instance Method Summary collapse
-
#append(key, value) ⇒ Fixnum
Append a value to a key.
-
#bitcount(key, start = 0, stop = -1)) ⇒ Fixnum
Count the number of set bits in a range of the string value stored at key.
-
#bitpos(key, bit, start = nil, stop = nil) ⇒ Fixnum
Return the position of the first bit set to 1 or 0 in a string.
-
#decr(key) ⇒ Fixnum
Decrement the integer value of a key by one.
-
#decrby(key, decrement) ⇒ Fixnum
Decrement the integer value of a key by the given number.
-
#get(key) ⇒ String
Get the value of a key.
-
#getbit(key, offset) ⇒ Fixnum
Returns the bit value at offset in the string value stored at key.
-
#getrange(key, start, stop) ⇒ Fixnum
Get a substring of the string stored at a key.
-
#getset(key, value) ⇒ String
Set the string value of a key and return its old value.
-
#incr(key) ⇒ Fixnum
Increment the integer value of a key by one.
-
#incrby(key, increment) ⇒ Fixnum
Increment the integer value of a key by the given integer number.
-
#incrbyfloat(key, increment) ⇒ Float
Increment the numeric value of a key by the given float number.
-
#psetex(key, ttl, value) ⇒ String
Set the time to live in milliseconds of a key.
-
#set(key, value, options = {}) ⇒ String, Boolean
Set the string value of a key.
-
#setbit(key, offset, value) ⇒ Fixnum
Sets or clears the bit at offset in the string value stored at key.
-
#setex(key, ttl, value) ⇒ String
Set the time to live in seconds of a key.
-
#setnx(key, value) ⇒ Boolean
Set the value of a key, only if the key does not exist.
-
#setrange(key, offset, value) ⇒ Fixnum
Overwrite part of a string at key starting at the specified offset.
-
#strlen(key) ⇒ Fixnum
Get the length of the value stored in a key.
Instance Method Details
#append(key, value) ⇒ Fixnum
Append a value to a key.
185 186 187 |
# File 'lib/redis_cluster/function/string.rb', line 185 def append(key, value) call(key, [:append, key, value]) end |
#bitcount(key, start = 0, stop = -1)) ⇒ Fixnum
Count the number of set bits in a range of the string value stored at key.
195 196 197 |
# File 'lib/redis_cluster/function/string.rb', line 195 def bitcount(key, start = 0, stop = -1) call(key, [:bitcount, key, start, stop], read: true) end |
#bitpos(key, bit, start = nil, stop = nil) ⇒ Fixnum
Return the position of the first bit set to 1 or 0 in a string.
207 208 209 210 211 212 213 |
# File 'lib/redis_cluster/function/string.rb', line 207 def bitpos(key, bit, start = nil, stop = nil) command = [:bitpos, key, bit] command << start if start command << stop if start && stop call(key, command, read: true) end |
#decr(key) ⇒ Fixnum
Decrement the integer value of a key by one.
25 26 27 |
# File 'lib/redis_cluster/function/string.rb', line 25 def decr(key) call(key, [:decr, key]) end |
#decrby(key, decrement) ⇒ Fixnum
Decrement the integer value of a key by the given number.
38 39 40 |
# File 'lib/redis_cluster/function/string.rb', line 38 def decrby(key, decrement) call(key, [:decrby, key, decrement]) end |
#get(key) ⇒ String
Get the value of a key.
136 137 138 |
# File 'lib/redis_cluster/function/string.rb', line 136 def get(key) call(key, [:get, key], read: true) end |
#getbit(key, offset) ⇒ Fixnum
Returns the bit value at offset in the string value stored at key.
176 177 178 |
# File 'lib/redis_cluster/function/string.rb', line 176 def getbit(key, offset) call(key, [:getbit, key, offset], read: true) end |
#getrange(key, start, stop) ⇒ Fixnum
Get a substring of the string stored at a key.
157 158 159 |
# File 'lib/redis_cluster/function/string.rb', line 157 def getrange(key, start, stop) call(key, [:getrange, key, start, stop], read: true) end |
#getset(key, value) ⇒ String
Set the string value of a key and return its old value.
221 222 223 |
# File 'lib/redis_cluster/function/string.rb', line 221 def getset(key, value) call(key, [:getset, key, value.to_s]) end |
#incr(key) ⇒ Fixnum
Increment the integer value of a key by one.
50 51 52 |
# File 'lib/redis_cluster/function/string.rb', line 50 def incr(key) call(key, [:incr, key]) end |
#incrby(key, increment) ⇒ Fixnum
Increment the integer value of a key by the given integer number.
63 64 65 |
# File 'lib/redis_cluster/function/string.rb', line 63 def incrby(key, increment) call(key, [:incrby, key, increment]) end |
#incrbyfloat(key, increment) ⇒ Float
Increment the numeric value of a key by the given float number.
76 77 78 |
# File 'lib/redis_cluster/function/string.rb', line 76 def incrbyfloat(key, increment) call(key, [:incrbyfloat, key, increment], transform: Redis::Floatify) end |
#psetex(key, ttl, value) ⇒ String
Set the time to live in milliseconds of a key.
119 120 121 |
# File 'lib/redis_cluster/function/string.rb', line 119 def psetex(key, ttl, value) call(key, [:psetex, key, ttl, value.to_s]) end |
#set(key, value, options = {}) ⇒ String, Boolean
Set the string value of a key.
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/redis_cluster/function/string.rb', line 90 def set(key, value, = {}) ex = [:ex] px = [:px] args = [:set, key, value.to_s] args.concat(['EX', ex]) if ex args.concat(['PX', px]) if px args.concat(['NX']) if [:nx] args.concat(['XX']) if [:xx] call(key, args, transform: Redis::BoolifySet) end |
#setbit(key, offset, value) ⇒ Fixnum
Sets or clears the bit at offset in the string value stored at key.
167 168 169 |
# File 'lib/redis_cluster/function/string.rb', line 167 def setbit(key, offset, value) call(key, [:setbit, key, offset, value]) end |
#setex(key, ttl, value) ⇒ String
Set the time to live in seconds of a key.
109 110 111 |
# File 'lib/redis_cluster/function/string.rb', line 109 def setex(key, ttl, value) call(key, [:setex, key, ttl, value.to_s]) end |
#setnx(key, value) ⇒ Boolean
Set the value of a key, only if the key does not exist.
128 129 130 |
# File 'lib/redis_cluster/function/string.rb', line 128 def setnx(key, value) call(key, [:setnx, key, value.to_s], transform: Redis::Boolify) end |
#setrange(key, offset, value) ⇒ Fixnum
Overwrite part of a string at key starting at the specified offset.
146 147 148 |
# File 'lib/redis_cluster/function/string.rb', line 146 def setrange(key, offset, value) call(key, [:setrange, key, offset, value.to_s]) end |
#strlen(key) ⇒ Fixnum
Get the length of the value stored in a key.
230 231 232 |
# File 'lib/redis_cluster/function/string.rb', line 230 def strlen(key) call(key, [:strlen, key], read: true) end |