protocol-redis 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,142 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ module Protocol
24
+ module Redis
25
+ module Methods
26
+ module Geospatial
27
+ # Add one or more geospatial items in the geospatial index represented using a sorted set. O(log(N)) for each item added, where N is the number of elements in the sorted set.
28
+ # @see https://redis.io/commands/geoadd
29
+ # @param key [Key]
30
+ def geoadd(key, longitude, latitude, member, *arguments)
31
+ call("GEOADD", longitude, latitude, member, *arguments)
32
+ end
33
+
34
+ # Returns members of a geospatial index as standard geohash strings. O(log(N)) for each member requested, where N is the number of elements in the sorted set.
35
+ # @see https://redis.io/commands/geohash
36
+ # @param key [Key]
37
+ # @param member [String]
38
+ def geohash(key, member, *members)
39
+ call("GEOHASH", key, member, *members)
40
+ end
41
+
42
+ # Returns longitude and latitude of members of a geospatial index. O(log(N)) for each member requested, where N is the number of elements in the sorted set.
43
+ # @see https://redis.io/commands/geopos
44
+ # @param key [Key]
45
+ # @param member [String]
46
+ def geopos(key, member, *members)
47
+ call("GEOPOS", key, member, *members)
48
+ end
49
+
50
+ # Returns the distance between two members of a geospatial index. O(log(N)).
51
+ # @see https://redis.io/commands/geodist
52
+ # @param key [Key]
53
+ # @param member1 [String]
54
+ # @param member2 [String]
55
+ # @param unit [Enum] Distance scale to use, one of "m" (meters), "km" (kilometers), "mi" (miles) or "ft" (feet).
56
+ def geodist(key, from, to, unit = "m")
57
+ call("GEODIST", key, from, to, unit)
58
+ end
59
+
60
+ # Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a point. O(N+log(M)) where N is the number of elements inside the bounding box of the circular area delimited by center and radius and M is the number of items inside the index.
61
+ # @see https://redis.io/commands/georadius
62
+ # @param key [Key]
63
+ # @param longitude [Double]
64
+ # @param latitude [Double]
65
+ # @param radius [Double]
66
+ # @param unit [Enum]
67
+ # @param withcoord [Enum]
68
+ # @param withdist [Enum]
69
+ # @param withhash [Enum]
70
+ def georadius(key, longitude, latitude, radius, unit = "m", withcoord: false, withdist: false, withhash: false, count: nil, store: nil, storedist: nil)
71
+ arguments = [key, longitude, latitude, radius, unit]
72
+
73
+ if withcoord
74
+ arguments.append("WITHCOORD")
75
+ end
76
+
77
+ if withdist
78
+ arguments.append("WITHDIST")
79
+ end
80
+
81
+ if withhash
82
+ arguments.append("WITHHASH")
83
+ end
84
+
85
+ if count
86
+ arguments.append("COUNT", count)
87
+ end
88
+
89
+ if store
90
+ arguments.append("STORE", store)
91
+ end
92
+
93
+ if storedist
94
+ arguments.append("STOREDIST", storedist)
95
+ end
96
+
97
+ call("GEORADIUS", *arguments)
98
+ end
99
+
100
+ # Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a member. O(N+log(M)) where N is the number of elements inside the bounding box of the circular area delimited by center and radius and M is the number of items inside the index.
101
+ # @see https://redis.io/commands/georadiusbymember
102
+ # @param key [Key]
103
+ # @param member [String]
104
+ # @param radius [Double]
105
+ # @param unit [Enum]
106
+ # @param withcoord [Enum]
107
+ # @param withdist [Enum]
108
+ # @param withhash [Enum]
109
+ # @param order [Enum]
110
+ def georadiusbymember(key, member, radius, unit = "m", withcoord: false, withdist: false, withhash: false, count: nil, store: nil, storedist: nil)
111
+ arguments = [key, member, radius, unit]
112
+
113
+ if withcoord
114
+ arguments.append("WITHCOORD")
115
+ end
116
+
117
+ if withdist
118
+ arguments.append("WITHDIST")
119
+ end
120
+
121
+ if withhash
122
+ arguments.append("WITHHASH")
123
+ end
124
+
125
+ if count
126
+ arguments.append("COUNT", count)
127
+ end
128
+
129
+ if store
130
+ arguments.append("STORE", store)
131
+ end
132
+
133
+ if storedist
134
+ arguments.append("STOREDIST", storedist)
135
+ end
136
+
137
+ call("GEORADIUS", *arguments)
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2019, by Mikael Henriksson. <http://www.mhenrixon.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -22,54 +24,103 @@ module Protocol
22
24
  module Redis
23
25
  module Methods
24
26
  module Hashes
27
+ # Get the number of fields in a hash. O(1).
28
+ # @see https://redis.io/commands/hlen
29
+ # @param key [Key]
25
30
  def hlen(key)
26
31
  return call('HLEN', key)
27
32
  end
28
33
 
34
+ # Set the string value of a hash field. O(1) for each field/value pair added, so O(N) to add N field/value pairs when the command is called with multiple field/value pairs.
35
+ # @see https://redis.io/commands/hset
36
+ # @param key [Key]
29
37
  def hset(key, field, value)
30
38
  return call('HSET', key, field, value)
31
39
  end
32
40
 
41
+ # Set the value of a hash field, only if the field does not exist. O(1).
42
+ # @see https://redis.io/commands/hsetnx
43
+ # @param key [Key]
44
+ # @param field [String]
45
+ # @param value [String]
33
46
  def hsetnx(key, field, value)
34
47
  return call('HSETNX', key, field, value)
35
48
  end
36
49
 
50
+ # Set multiple hash fields to multiple values. O(N) where N is the number of fields being set.
51
+ # @see https://redis.io/commands/hmset
52
+ # @param key [Key]
37
53
  def hmset(key, *attrs)
38
54
  return call('HMSET', key, *attrs)
39
55
  end
40
56
 
57
+ # Get the value of a hash field. O(1).
58
+ # @see https://redis.io/commands/hget
59
+ # @param key [Key]
60
+ # @param field [String]
41
61
  def hget(key, field)
42
62
  return call('HGET', key, field)
43
63
  end
44
64
 
65
+ # Get the values of all the given hash fields. O(N) where N is the number of fields being requested.
66
+ # @see https://redis.io/commands/hmget
67
+ # @param key [Key]
68
+ # @param field [String]
45
69
  def hmget(key, *fields, &blk)
46
70
  return call('HMGET', key, *fields, &blk)
47
71
  end
48
72
 
73
+ # Delete one or more hash fields. O(N) where N is the number of fields to be removed.
74
+ # @see https://redis.io/commands/hdel
75
+ # @param key [Key]
76
+ # @param field [String]
49
77
  def hdel(key, *fields)
50
78
  return call('HDEL', key, *fields)
51
79
  end
52
80
 
81
+ # Determine if a hash field exists. O(1).
82
+ # @see https://redis.io/commands/hexists
83
+ # @param key [Key]
84
+ # @param field [String]
53
85
  def hexists(key, field)
54
86
  return call('HEXISTS', key, field)
55
87
  end
56
88
 
89
+ # Increment the integer value of a hash field by the given number. O(1).
90
+ # @see https://redis.io/commands/hincrby
91
+ # @param key [Key]
92
+ # @param field [String]
93
+ # @param increment [Integer]
57
94
  def hincrby(key, field, increment)
58
95
  return call('HINCRBY', key, field, increment)
59
96
  end
60
97
 
98
+ # Increment the float value of a hash field by the given amount. O(1).
99
+ # @see https://redis.io/commands/hincrbyfloat
100
+ # @param key [Key]
101
+ # @param field [String]
102
+ # @param increment [Double]
61
103
  def hincrbyfloat(key, field, increment)
62
104
  return call('HINCRBYFLOAT', key, field, increment)
63
105
  end
64
106
 
107
+ # Get all the fields in a hash. O(N) where N is the size of the hash.
108
+ # @see https://redis.io/commands/hkeys
109
+ # @param key [Key]
65
110
  def hkeys(key)
66
111
  return call('HKEYS', key)
67
112
  end
68
113
 
114
+ # Get all the values in a hash. O(N) where N is the size of the hash.
115
+ # @see https://redis.io/commands/hvals
116
+ # @param key [Key]
69
117
  def hvals(key)
70
118
  return call('HVALS', key)
71
119
  end
72
120
 
121
+ # Get all the fields and values in a hash. O(N) where N is the size of the hash.
122
+ # @see https://redis.io/commands/hgetall
123
+ # @param key [Key]
73
124
  def hgetall(key)
74
125
  return call('HGETALL', key)
75
126
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  # Copyright, 2018, by Huba Nagy.
3
5
  #
@@ -23,22 +25,45 @@ module Protocol
23
25
  module Redis
24
26
  module Methods
25
27
  module Lists
28
+ # Remove and get the first element in a list, or block until one is available. O(1).
29
+ # @see https://redis.io/commands/blpop
30
+ # @param key [Key]
31
+ # @param timeout [Integer]
26
32
  def blpop(*keys, timeout: 0)
27
33
  return call('BLPOP', *keys, timeout)
28
34
  end
29
35
 
36
+ # Remove and get the last element in a list, or block until one is available. O(1).
37
+ # @see https://redis.io/commands/brpop
38
+ # @param key [Key]
39
+ # @param timeout [Integer]
30
40
  def brpop(*keys, timeout: 0)
31
41
  return call('BRPOP', *keys, timeout)
32
42
  end
33
43
 
44
+ # Pop an element from a list, push it to another list and return it; or block until one is available. O(1).
45
+ # @see https://redis.io/commands/brpoplpush
46
+ # @param source [Key]
47
+ # @param destination [Key]
48
+ # @param timeout [Integer]
34
49
  def brpoplpush(source, destination, timeout)
35
50
  return call('BRPOPLPUSH', source, destination, timeout)
36
51
  end
37
52
 
53
+ # Get an element from a list by its index. O(N) where N is the number of elements to traverse to get to the element at index. This makes asking for the first or the last element of the list O(1).
54
+ # @see https://redis.io/commands/lindex
55
+ # @param key [Key]
56
+ # @param index [Integer]
38
57
  def lindex(key, index)
39
58
  return call('LINDEX', key, index)
40
59
  end
41
60
 
61
+ # Insert an element before or after another element in a list. O(N) where N is the number of elements to traverse before seeing the value pivot. This means that inserting somewhere on the left end on the list (head) can be considered O(1) and inserting somewhere on the right end (tail) is O(N).
62
+ # @see https://redis.io/commands/linsert
63
+ # @param key [Key]
64
+ # @param where [Enum]
65
+ # @param pivot [String]
66
+ # @param element [String]
42
67
  def linsert(key, position=:before, index, value)
43
68
  if position == :before
44
69
  offset = 'BEFORE'
@@ -49,14 +74,24 @@ module Protocol
49
74
  return call('LINSERT', key, offset, index, value)
50
75
  end
51
76
 
77
+ # Get the length of a list. O(1).
78
+ # @see https://redis.io/commands/llen
79
+ # @param key [Key]
52
80
  def llen(key)
53
81
  return call('LLEN', key)
54
82
  end
55
83
 
84
+ # Remove and get the first element in a list. O(1).
85
+ # @see https://redis.io/commands/lpop
86
+ # @param key [Key]
56
87
  def lpop(key)
57
88
  return call('LPOP', key)
58
89
  end
59
90
 
91
+ # Prepend one or multiple elements to a list. O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments.
92
+ # @see https://redis.io/commands/lpush
93
+ # @param key [Key]
94
+ # @param element [String]
60
95
  def lpush(key, value, *values)
61
96
  case value
62
97
  when Array
@@ -68,36 +103,71 @@ module Protocol
68
103
  return call('LPUSH', key, *values)
69
104
  end
70
105
 
106
+ # Prepend an element to a list, only if the list exists. O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments.
107
+ # @see https://redis.io/commands/lpushx
108
+ # @param key [Key]
109
+ # @param element [String]
71
110
  def lpushx(key, value)
72
111
  return call('LPUSHX', key, value)
73
112
  end
74
113
 
114
+ # Get a range of elements from a list. O(S+N) where S is the distance of start offset from HEAD for small lists, from nearest end (HEAD or TAIL) for large lists; and N is the number of elements in the specified range.
115
+ # @see https://redis.io/commands/lrange
116
+ # @param key [Key]
117
+ # @param start [Integer]
118
+ # @param stop [Integer]
75
119
  def lrange(key, start, stop)
76
120
  return call('LRANGE', key, start, stop)
77
121
  end
78
122
 
123
+ # Remove elements from a list. O(N+M) where N is the length of the list and M is the number of elements removed.
124
+ # @see https://redis.io/commands/lrem
125
+ # @param key [Key]
126
+ # @param count [Integer]
127
+ # @param element [String]
79
128
  def lrem(key, count, value)
80
129
  return call('LREM', key, count)
81
130
  end
82
131
 
132
+ # Set the value of an element in a list by its index. O(N) where N is the length of the list. Setting either the first or the last element of the list is O(1).
133
+ # @see https://redis.io/commands/lset
134
+ # @param key [Key]
135
+ # @param index [Integer]
136
+ # @param element [String]
83
137
  def lset(key, index, values)
84
138
  return call('LSET', key, index, values)
85
139
  end
86
140
 
141
+ # Trim a list to the specified range. O(N) where N is the number of elements to be removed by the operation.
142
+ # @see https://redis.io/commands/ltrim
143
+ # @param key [Key]
144
+ # @param start [Integer]
145
+ # @param stop [Integer]
87
146
  def ltrim(key, start, stop)
88
147
  return call('LTRIM', key, start, stop)
89
148
  end
90
149
 
150
+ # Remove and get the last element in a list. O(1).
151
+ # @see https://redis.io/commands/rpop
152
+ # @param key [Key]
91
153
  def rpop(key)
92
154
  return call('RPOP', key)
93
155
  end
94
156
 
157
+ # Remove the last element in a list, prepend it to another list and return it. O(1).
158
+ # @see https://redis.io/commands/rpoplpush
159
+ # @param source [Key]
160
+ # @param destination [Key]
95
161
  def rpoplpush(source, destination=nil)
96
162
  destination = source if destination.nil?
97
163
 
98
164
  return call('RPOPLPUSH', source, destination)
99
165
  end
100
166
 
167
+ # Append one or multiple elements to a list. O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments.
168
+ # @see https://redis.io/commands/rpush
169
+ # @param key [Key]
170
+ # @param element [String]
101
171
  def rpush(key, value, *values)
102
172
  case value
103
173
  when Array
@@ -109,6 +179,10 @@ module Protocol
109
179
  return call('RPUSH', key, *values)
110
180
  end
111
181
 
182
+ # Append an element to a list, only if the list exists. O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments.
183
+ # @see https://redis.io/commands/rpushx
184
+ # @param key [Key]
185
+ # @param element [String]
112
186
  def rpushx(key, value)
113
187
  return call('RPUSHX', key, value)
114
188
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  # Copyright, 2018, by Huba Nagy.
3
5
  #
@@ -23,8 +25,9 @@ module Protocol
23
25
  module Redis
24
26
  module Methods
25
27
  module Server
26
- # Get info from server.
27
- # @return [Hash] the server metadata.
28
+ # Get information and statistics about the server.
29
+ # @see https://redis.io/commands/info
30
+ # @param section [String]
28
31
  def info
29
32
  metadata = {}
30
33
 
@@ -39,8 +42,11 @@ module Protocol
39
42
  return metadata
40
43
  end
41
44
 
45
+ # Remove all keys from the current database.
46
+ # @see https://redis.io/commands/flushdb
47
+ # @param async [Enum]
42
48
  def flushdb!
43
- call 'FLUSHDB'
49
+ return call('FLUSHDB')
44
50
  end
45
51
  end
46
52
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  # Copyright, 2018, by Huba Nagy.
3
5
  #
@@ -23,68 +25,127 @@ module Protocol
23
25
  module Redis
24
26
  module Methods
25
27
  module Strings
28
+ # Append a value to a key. O(1). The amortized time complexity is O(1) assuming the appended value is small and the already present value is of any size, since the dynamic string library used by Redis will double the free space available on every reallocation.
29
+ # @see https://redis.io/commands/append
30
+ # @param key [Key]
31
+ # @param value [String]
26
32
  def append(key, value)
27
33
  return call('APPEND', key, value)
28
34
  end
29
35
 
36
+ # Count set bits in a string. O(N).
37
+ # @see https://redis.io/commands/bitcount
38
+ # @param key [Key]
30
39
  def bitcount(key, *range)
31
40
  return call('BITCOUNT', key, *range)
32
41
  end
33
42
 
43
+ # Decrement the integer value of a key by one. O(1).
44
+ # @see https://redis.io/commands/decr
45
+ # @param key [Key]
34
46
  def decr(key)
35
47
  return call('DECR', key)
36
48
  end
37
49
 
50
+ # Decrement the integer value of a key by the given number. O(1).
51
+ # @see https://redis.io/commands/decrby
52
+ # @param key [Key]
53
+ # @param decrement [Integer]
38
54
  def decrby(key, decrement)
39
55
  return call('DECRBY', key, decrement)
40
56
  end
41
57
 
58
+ # Get the value of a key. O(1).
59
+ # @see https://redis.io/commands/get
60
+ # @param key [Key]
42
61
  def get(key)
43
62
  return call('GET', key)
44
63
  end
45
64
 
65
+ # Returns the bit value at offset in the string value stored at key. O(1).
66
+ # @see https://redis.io/commands/getbit
67
+ # @param key [Key]
68
+ # @param offset [Integer]
46
69
  def getbit(key, offset)
47
70
  return call('GETBIT', key, offset)
48
71
  end
49
72
 
73
+ # Get a substring of the string stored at a key. O(N) where N is the length of the returned string. The complexity is ultimately determined by the returned length, but because creating a substring from an existing string is very cheap, it can be considered O(1) for small strings.
74
+ # @see https://redis.io/commands/getrange
75
+ # @param key [Key]
76
+ # @param start [Integer]
77
+ # @param end [Integer]
50
78
  def getrange(key, start_index, end_index)
51
79
  return call('GETRANGE', key, start_index, end_index)
52
80
  end
53
81
 
82
+ # Set the string value of a key and return its old value. O(1).
83
+ # @see https://redis.io/commands/getset
84
+ # @param key [Key]
85
+ # @param value [String]
54
86
  def getset(key, value)
55
87
  return call('GETSET', key, value)
56
88
  end
57
89
 
90
+ # Increment the integer value of a key by one. O(1).
91
+ # @see https://redis.io/commands/incr
92
+ # @param key [Key]
58
93
  def incr(key)
59
94
  return call('INCR', key)
60
95
  end
61
96
 
97
+ # Increment the integer value of a key by the given amount. O(1).
98
+ # @see https://redis.io/commands/incrby
99
+ # @param key [Key]
100
+ # @param increment [Integer]
62
101
  def incrby(key, increment)
63
102
  return call('INCRBY', key, increment)
64
103
  end
65
104
 
105
+ # Increment the float value of a key by the given amount. O(1).
106
+ # @see https://redis.io/commands/incrbyfloat
107
+ # @param key [Key]
108
+ # @param increment [Double]
66
109
  def incrbyfloat(key, increment)
67
110
  return call('INCRBYFLOAT', key, increment)
68
111
  end
69
112
 
113
+ # Get the values of all the given keys. O(N) where N is the number of keys to retrieve.
114
+ # @see https://redis.io/commands/mget
115
+ # @param key [Key]
70
116
  def mget(key, *keys)
71
117
  return call('MGET', key, *keys)
72
118
  end
73
119
 
120
+ # Set multiple keys to multiple values. O(N) where N is the number of keys to set.
121
+ # @see https://redis.io/commands/mset
74
122
  def mset(pairs)
75
123
  flattened_pairs = pairs.keys.zip(pairs.values).flatten
76
124
  return call('MSET', *flattened_pairs)
77
125
  end
78
126
 
127
+ # Set multiple keys to multiple values, only if none of the keys exist. O(N) where N is the number of keys to set.
128
+ # @see https://redis.io/commands/msetnx
79
129
  def msetnx(pairs)
80
130
  flattened_pairs = pairs.keys.zip(pairs.values).flatten
81
131
  return call('MSETNX', *flattened_pairs)
82
132
  end
83
133
 
134
+ # Set the value and expiration in milliseconds of a key. O(1).
135
+ # @see https://redis.io/commands/psetex
136
+ # @param key [Key]
137
+ # @param milliseconds [Integer]
138
+ # @param value [String]
84
139
  def psetex(key, milliseconds, value)
85
140
  return set key, value, milliseconds: milliseconds
86
141
  end
87
142
 
143
+ # Set the string value of a key. O(1).
144
+ # @see https://redis.io/commands/set
145
+ # @param key [Key]
146
+ # @param value [String]
147
+ # @param expiration [Enum]
148
+ # @param condition [Enum]
88
149
  def set(key, value, **options)
89
150
  arguments = []
90
151
 
@@ -107,22 +168,44 @@ module Protocol
107
168
  return call('SET', key, value, *arguments)
108
169
  end
109
170
 
171
+ # Sets or clears the bit at offset in the string value stored at key. O(1).
172
+ # @see https://redis.io/commands/setbit
173
+ # @param key [Key]
174
+ # @param offset [Integer]
175
+ # @param value [Integer]
110
176
  def setbit(key, offset, value)
111
177
  return call('SETBIT', key, offset, value)
112
178
  end
113
179
 
180
+ # Set the value and expiration of a key. O(1).
181
+ # @see https://redis.io/commands/setex
182
+ # @param key [Key]
183
+ # @param seconds [Integer]
184
+ # @param value [String]
114
185
  def setex(key, seconds, value)
115
186
  return set key, value, seconds: seconds
116
187
  end
117
188
 
189
+ # Set the value of a key, only if the key does not exist. O(1).
190
+ # @see https://redis.io/commands/setnx
191
+ # @param key [Key]
192
+ # @param value [String]
118
193
  def setnx(key, value)
119
194
  return set key, value, condition: :nx
120
195
  end
121
196
 
197
+ # Overwrite part of a string at key starting at the specified offset. O(1), not counting the time taken to copy the new string in place. Usually, this string is very small so the amortized complexity is O(1). Otherwise, complexity is O(M) with M being the length of the value argument.
198
+ # @see https://redis.io/commands/setrange
199
+ # @param key [Key]
200
+ # @param offset [Integer]
201
+ # @param value [String]
122
202
  def setrange(key, offset, value)
123
203
  return call('SETRANGE', key, offset, value)
124
204
  end
125
205
 
206
+ # Get the length of the value stored in a key. O(1).
207
+ # @see https://redis.io/commands/strlen
208
+ # @param key [Key]
126
209
  def strlen(key)
127
210
  return call('STRLEN', key)
128
211
  end