protocol-redis 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +1 -2
- data/context/getting-started.md +55 -0
- data/context/index.yaml +13 -0
- data/lib/protocol/redis/cluster/methods/generic.rb +94 -0
- data/lib/protocol/redis/cluster/methods/pubsub.rb +27 -0
- data/lib/protocol/redis/cluster/methods/scripting.rb +93 -0
- data/lib/protocol/redis/cluster/methods/streams.rb +204 -0
- data/lib/protocol/redis/cluster/methods/strings.rb +304 -0
- data/lib/protocol/redis/cluster/methods.rb +27 -0
- data/lib/protocol/redis/connection.rb +41 -12
- data/lib/protocol/redis/error.rb +6 -0
- data/lib/protocol/redis/methods/cluster.rb +9 -7
- data/lib/protocol/redis/methods/connection.rb +9 -8
- data/lib/protocol/redis/methods/counting.rb +9 -8
- data/lib/protocol/redis/methods/generic.rb +100 -99
- data/lib/protocol/redis/methods/geospatial.rb +42 -49
- data/lib/protocol/redis/methods/hashes.rb +84 -83
- data/lib/protocol/redis/methods/lists.rb +75 -74
- data/lib/protocol/redis/methods/pubsub.rb +5 -4
- data/lib/protocol/redis/methods/scripting.rb +19 -20
- data/lib/protocol/redis/methods/server.rb +13 -9
- data/lib/protocol/redis/methods/sets.rb +42 -41
- data/lib/protocol/redis/methods/sorted_sets.rb +110 -109
- data/lib/protocol/redis/methods/streams.rb +48 -47
- data/lib/protocol/redis/methods/strings.rb +112 -109
- data/lib/protocol/redis/methods.rb +16 -14
- data/lib/protocol/redis/version.rb +1 -1
- data/lib/protocol/redis.rb +9 -2
- data/readme.md +49 -21
- data/releases.md +98 -0
- data.tar.gz.sig +0 -0
- metadata +13 -9
- metadata.gz.sig +0 -0
@@ -8,179 +8,180 @@
|
|
8
8
|
module Protocol
|
9
9
|
module Redis
|
10
10
|
module Methods
|
11
|
+
# Methods for managing Redis hashes.
|
11
12
|
module Hashes
|
12
13
|
# Get the number of fields in a hash. O(1).
|
13
|
-
#
|
14
|
-
# @
|
15
|
-
# @
|
14
|
+
# See <https://redis.io/commands/hlen> for more details.
|
15
|
+
# @parameter key [Key]
|
16
|
+
# @returns [Integer]
|
16
17
|
def hlen(key)
|
17
|
-
call(
|
18
|
+
call("HLEN", key)
|
18
19
|
end
|
19
20
|
|
20
21
|
# 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.
|
21
|
-
#
|
22
|
-
# @
|
23
|
-
# @
|
22
|
+
# See <https://redis.io/commands/hset> for more details.
|
23
|
+
# @parameter key [Key]
|
24
|
+
# @returns [Integer] if new field added returns "1" otherwise "0"
|
24
25
|
def hset(key, field, value)
|
25
|
-
call(
|
26
|
+
call("HSET", key, field, value)
|
26
27
|
end
|
27
28
|
|
28
29
|
# Set the value of a hash field, only if the field does not exist. O(1).
|
29
|
-
#
|
30
|
-
# @
|
31
|
-
# @
|
32
|
-
# @
|
33
|
-
# @
|
30
|
+
# See <https://redis.io/commands/hsetnx> for more details.
|
31
|
+
# @parameter key [Key]
|
32
|
+
# @parameter field [String]
|
33
|
+
# @parameter value [String]
|
34
|
+
# @returns [Boolean] "true" if new field added, "false" otherwise
|
34
35
|
def hsetnx(key, field, value)
|
35
|
-
call(
|
36
|
+
call("HSETNX", key, field, value) > 0
|
36
37
|
end
|
37
38
|
|
38
39
|
# Set multiple hash fields to multiple values. O(N) where N is the number of fields being set.
|
39
|
-
#
|
40
|
-
# @
|
41
|
-
# @
|
40
|
+
# See <https://redis.io/commands/hmset> for more details.
|
41
|
+
# @parameter key [Key]
|
42
|
+
# @returns [String] default: "OK"
|
42
43
|
def hmset(key, *attrs)
|
43
|
-
call(
|
44
|
+
call("HMSET", key, *attrs)
|
44
45
|
end
|
45
|
-
|
46
|
+
|
46
47
|
# Set multiple hash fields to multiple values, by providing a hash
|
47
48
|
#
|
48
49
|
# @example
|
49
50
|
# redis.mapped_hmset("hash", { "f1" => "v1", "f2" => "v2" })
|
50
51
|
# # => "OK"
|
51
52
|
#
|
52
|
-
# @
|
53
|
-
# @
|
54
|
-
# @
|
53
|
+
# @parameter key [Key]
|
54
|
+
# @parameter hash [Hash] a non-empty hash with fields mapping to values
|
55
|
+
# @returns [String] default: "OK"
|
55
56
|
#
|
56
|
-
#
|
57
|
+
# See <#hmset> for more details.
|
57
58
|
def mapped_hmset(key, hash)
|
58
59
|
hmset(key, *hash.flatten)
|
59
60
|
end
|
60
61
|
|
61
62
|
# Get the value of a hash field. O(1).
|
62
|
-
#
|
63
|
-
# @
|
64
|
-
# @
|
65
|
-
# @
|
63
|
+
# See <https://redis.io/commands/hget> for more details.
|
64
|
+
# @parameter key [Key]
|
65
|
+
# @parameter field [String]
|
66
|
+
# @returns [String, Null]
|
66
67
|
def hget(key, field)
|
67
|
-
call(
|
68
|
+
call("HGET", key, field)
|
68
69
|
end
|
69
70
|
|
70
71
|
# Get the values of all the given hash fields. O(N) where N is the number of fields being requested.
|
71
|
-
#
|
72
|
-
# @
|
73
|
-
# @
|
74
|
-
# @
|
72
|
+
# See <https://redis.io/commands/hmget> for more details.
|
73
|
+
# @parameter key [Key]
|
74
|
+
# @parameter fields [Array(String)] array of fields
|
75
|
+
# @returns [Array]
|
75
76
|
def hmget(key, *fields)
|
76
|
-
call(
|
77
|
+
call("HMGET", key, *fields)
|
77
78
|
end
|
78
|
-
|
79
|
+
|
79
80
|
# Get the values of all the given hash fields and return as array
|
80
81
|
#
|
81
82
|
# @example
|
82
83
|
# redis.mapped_hmget("hash", "f1", "f2")
|
83
84
|
# # => { "f1" => "v1", "f2" => "v2" }
|
84
85
|
#
|
85
|
-
# @
|
86
|
-
# @
|
87
|
-
# @
|
86
|
+
# @parameter key [Key]
|
87
|
+
# @parameter fields [Array(String)] array of fields
|
88
|
+
# @returns [Hash] a hash mapping the specified fields to their values
|
88
89
|
#
|
89
|
-
#
|
90
|
+
# See <#hmget> for more details.
|
90
91
|
def mapped_hmget(key, *fields)
|
91
92
|
reply = hmget(key, *fields)
|
92
93
|
Hash[fields.zip(reply)]
|
93
94
|
end
|
94
|
-
|
95
|
+
|
95
96
|
# Delete one or more hash fields. O(N) where N is the number of fields to be removed.
|
96
|
-
#
|
97
|
-
# @
|
98
|
-
# @
|
99
|
-
# @
|
97
|
+
# See <https://redis.io/commands/hdel> for more details.
|
98
|
+
# @parameter key [Key]
|
99
|
+
# @parameter field [String]
|
100
|
+
# @returns [Integer] number of deleted fields
|
100
101
|
def hdel(key, *fields)
|
101
|
-
call(
|
102
|
+
call("HDEL", key, *fields)
|
102
103
|
end
|
103
104
|
|
104
105
|
# Determine if a hash field exists. O(1).
|
105
|
-
#
|
106
|
-
# @
|
107
|
-
# @
|
108
|
-
# @
|
106
|
+
# See <https://redis.io/commands/hexists> for more details.
|
107
|
+
# @parameter key [Key]
|
108
|
+
# @parameter field [String]
|
109
|
+
# @returns [Boolean]
|
109
110
|
def hexists(key, field)
|
110
|
-
call(
|
111
|
+
call("HEXISTS", key, field) > 0
|
111
112
|
end
|
112
113
|
|
113
114
|
# Increment the integer value of a hash field by the given number. O(1).
|
114
|
-
#
|
115
|
-
# @
|
116
|
-
# @
|
117
|
-
# @
|
118
|
-
# @
|
115
|
+
# See <https://redis.io/commands/hincrby> for more details.
|
116
|
+
# @parameter key [Key]
|
117
|
+
# @parameter field [String]
|
118
|
+
# @parameter increment [Integer]
|
119
|
+
# @returns [Integer] field value after increment
|
119
120
|
def hincrby(key, field, increment)
|
120
|
-
call(
|
121
|
+
call("HINCRBY", key, field, increment)
|
121
122
|
end
|
122
123
|
|
123
124
|
# Increment the float value of a hash field by the given amount. O(1).
|
124
|
-
#
|
125
|
-
# @
|
126
|
-
# @
|
127
|
-
# @
|
128
|
-
# @
|
125
|
+
# See <https://redis.io/commands/hincrbyfloat> for more details.
|
126
|
+
# @parameter key [Key]
|
127
|
+
# @parameter field [String]
|
128
|
+
# @parameter increment [Double]
|
129
|
+
# @returns [Float] field value after increment
|
129
130
|
def hincrbyfloat(key, field, increment)
|
130
|
-
Float(call(
|
131
|
+
Float(call("HINCRBYFLOAT", key, field, increment))
|
131
132
|
end
|
132
133
|
|
133
134
|
# Get all the fields in a hash. O(N) where N is the size of the hash.
|
134
|
-
#
|
135
|
-
# @
|
136
|
-
# @
|
135
|
+
# See <https://redis.io/commands/hkeys> for more details.
|
136
|
+
# @parameter key [Key]
|
137
|
+
# @returns [Array]
|
137
138
|
def hkeys(key)
|
138
|
-
call(
|
139
|
+
call("HKEYS", key)
|
139
140
|
end
|
140
141
|
|
141
142
|
# Get all the values in a hash. O(N) where N is the size of the hash.
|
142
|
-
#
|
143
|
-
# @
|
144
|
-
# @
|
143
|
+
# See <https://redis.io/commands/hvals> for more details.
|
144
|
+
# @parameter key [Key]
|
145
|
+
# @returns [Array]
|
145
146
|
def hvals(key)
|
146
|
-
call(
|
147
|
+
call("HVALS", key)
|
147
148
|
end
|
148
149
|
|
149
150
|
# Get all the fields and values in a hash. O(N) where N is the size of the hash.
|
150
|
-
#
|
151
|
-
# @
|
152
|
-
# @
|
151
|
+
# See <https://redis.io/commands/hgetall> for more details.
|
152
|
+
# @parameter key [Key]
|
153
|
+
# @returns [Hash]
|
153
154
|
def hgetall(key)
|
154
|
-
call(
|
155
|
+
call("HGETALL", key).each_slice(2).to_h
|
155
156
|
end
|
156
|
-
|
157
|
+
|
157
158
|
# Iterates fields of Hash types and their associated values. O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection.
|
158
|
-
#
|
159
|
-
# @
|
160
|
-
# @
|
159
|
+
# See <https://redis.io/commands/hscan/> for more details.
|
160
|
+
# @parameter cursor [Cursor]
|
161
|
+
# @returns [Hash]
|
161
162
|
def hscan(key, cursor = "0", match: nil, count: nil)
|
162
163
|
arguments = [key, cursor]
|
163
|
-
|
164
|
+
|
164
165
|
if match
|
165
166
|
arguments.append("MATCH", match)
|
166
167
|
end
|
167
|
-
|
168
|
+
|
168
169
|
if count
|
169
170
|
arguments.append("COUNT", count)
|
170
171
|
end
|
171
|
-
|
172
|
+
|
172
173
|
call("HSCAN", *arguments)
|
173
174
|
end
|
174
175
|
|
175
176
|
# Iterate over each field and the value of the hash, using HSCAN.
|
176
177
|
def hscan_each(key, cursor = "0", match: nil, count: nil, &block)
|
177
178
|
return enum_for(:hscan_each, key, cursor, match: match, count: count) unless block_given?
|
178
|
-
|
179
|
+
|
179
180
|
while true
|
180
181
|
cursor, data = hscan(key, cursor, match: match, count: count)
|
181
|
-
|
182
|
+
|
182
183
|
data.each_slice(2, &block)
|
183
|
-
|
184
|
+
|
184
185
|
break if cursor == "0"
|
185
186
|
end
|
186
187
|
end
|
@@ -7,74 +7,75 @@
|
|
7
7
|
module Protocol
|
8
8
|
module Redis
|
9
9
|
module Methods
|
10
|
+
# Methods for managing Redis lists.
|
10
11
|
module Lists
|
11
12
|
# Remove and get the first element in a list, or block until one is available. O(1).
|
12
|
-
#
|
13
|
-
# @
|
14
|
-
# @
|
13
|
+
# See <https://redis.io/commands/blpop> for more details.
|
14
|
+
# @parameter key [Key]
|
15
|
+
# @parameter timeout [Integer]
|
15
16
|
def blpop(*keys, timeout: 0)
|
16
|
-
call(
|
17
|
+
call("BLPOP", *keys, timeout)
|
17
18
|
end
|
18
19
|
|
19
20
|
# Remove and get the last element in a list, or block until one is available. O(1).
|
20
|
-
#
|
21
|
-
# @
|
22
|
-
# @
|
21
|
+
# See <https://redis.io/commands/brpop> for more details.
|
22
|
+
# @parameter key [Key]
|
23
|
+
# @parameter timeout [Integer]
|
23
24
|
def brpop(*keys, timeout: 0)
|
24
|
-
call(
|
25
|
+
call("BRPOP", *keys, timeout)
|
25
26
|
end
|
26
27
|
|
27
28
|
# Pop an element from a list, push it to another list and return it; or block until one is available. O(1).
|
28
|
-
#
|
29
|
-
# @
|
30
|
-
# @
|
31
|
-
# @
|
29
|
+
# See <https://redis.io/commands/brpoplpush> for more details.
|
30
|
+
# @parameter source [Key]
|
31
|
+
# @parameter destination [Key]
|
32
|
+
# @parameter timeout [Integer]
|
32
33
|
def brpoplpush(source, destination, timeout)
|
33
|
-
call(
|
34
|
+
call("BRPOPLPUSH", source, destination, timeout)
|
34
35
|
end
|
35
36
|
|
36
37
|
# 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).
|
37
|
-
#
|
38
|
-
# @
|
39
|
-
# @
|
38
|
+
# See <https://redis.io/commands/lindex> for more details.
|
39
|
+
# @parameter key [Key]
|
40
|
+
# @parameter index [Integer]
|
40
41
|
def lindex(key, index)
|
41
|
-
call(
|
42
|
+
call("LINDEX", key, index)
|
42
43
|
end
|
43
44
|
|
44
45
|
# 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).
|
45
|
-
#
|
46
|
-
# @
|
47
|
-
# @
|
48
|
-
# @
|
49
|
-
# @
|
46
|
+
# See <https://redis.io/commands/linsert> for more details.
|
47
|
+
# @parameter key [Key]
|
48
|
+
# @parameter where [Enum]
|
49
|
+
# @parameter pivot [String]
|
50
|
+
# @parameter element [String]
|
50
51
|
def linsert(key, position=:before, index, value)
|
51
52
|
if position == :before
|
52
|
-
offset =
|
53
|
+
offset = "BEFORE"
|
53
54
|
else
|
54
|
-
offset =
|
55
|
+
offset = "AFTER"
|
55
56
|
end
|
56
57
|
|
57
|
-
call(
|
58
|
+
call("LINSERT", key, offset, index, value)
|
58
59
|
end
|
59
60
|
|
60
61
|
# Get the length of a list. O(1).
|
61
|
-
#
|
62
|
-
# @
|
62
|
+
# See <https://redis.io/commands/llen> for more details.
|
63
|
+
# @parameter key [Key]
|
63
64
|
def llen(key)
|
64
|
-
call(
|
65
|
+
call("LLEN", key)
|
65
66
|
end
|
66
67
|
|
67
68
|
# Remove and get the first element in a list. O(1).
|
68
|
-
#
|
69
|
-
# @
|
69
|
+
# See <https://redis.io/commands/lpop> for more details.
|
70
|
+
# @parameter key [Key]
|
70
71
|
def lpop(key)
|
71
|
-
call(
|
72
|
+
call("LPOP", key)
|
72
73
|
end
|
73
74
|
|
74
75
|
# 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.
|
75
|
-
#
|
76
|
-
# @
|
77
|
-
# @
|
76
|
+
# See <https://redis.io/commands/lpush> for more details.
|
77
|
+
# @parameter key [Key]
|
78
|
+
# @parameter element [String]
|
78
79
|
def lpush(key, value, *values)
|
79
80
|
case value
|
80
81
|
when Array
|
@@ -83,74 +84,74 @@ module Protocol
|
|
83
84
|
values = [value] + values
|
84
85
|
end
|
85
86
|
|
86
|
-
call(
|
87
|
+
call("LPUSH", key, *values)
|
87
88
|
end
|
88
89
|
|
89
90
|
# 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.
|
90
|
-
#
|
91
|
-
# @
|
92
|
-
# @
|
91
|
+
# See <https://redis.io/commands/lpushx> for more details.
|
92
|
+
# @parameter key [Key]
|
93
|
+
# @parameter element [String]
|
93
94
|
def lpushx(key, value)
|
94
|
-
call(
|
95
|
+
call("LPUSHX", key, value)
|
95
96
|
end
|
96
97
|
|
97
98
|
# 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.
|
98
|
-
#
|
99
|
-
# @
|
100
|
-
# @
|
101
|
-
# @
|
99
|
+
# See <https://redis.io/commands/lrange> for more details.
|
100
|
+
# @parameter key [Key]
|
101
|
+
# @parameter start [Integer]
|
102
|
+
# @parameter stop [Integer]
|
102
103
|
def lrange(key, start, stop)
|
103
|
-
call(
|
104
|
+
call("LRANGE", key, start, stop)
|
104
105
|
end
|
105
106
|
|
106
107
|
# Remove elements from a list. O(N+M) where N is the length of the list and M is the number of elements removed.
|
107
|
-
#
|
108
|
-
# @
|
109
|
-
# @
|
110
|
-
# @
|
108
|
+
# See <https://redis.io/commands/lrem> for more details.
|
109
|
+
# @parameter key [Key]
|
110
|
+
# @parameter count [Integer]
|
111
|
+
# @parameter element [String]
|
111
112
|
def lrem(key, count, value)
|
112
|
-
call(
|
113
|
+
call("LREM", key, count, value)
|
113
114
|
end
|
114
115
|
|
115
116
|
# 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).
|
116
|
-
#
|
117
|
-
# @
|
118
|
-
# @
|
119
|
-
# @
|
117
|
+
# See <https://redis.io/commands/lset> for more details.
|
118
|
+
# @parameter key [Key]
|
119
|
+
# @parameter index [Integer]
|
120
|
+
# @parameter element [String]
|
120
121
|
def lset(key, index, values)
|
121
|
-
call(
|
122
|
+
call("LSET", key, index, values)
|
122
123
|
end
|
123
124
|
|
124
125
|
# Trim a list to the specified range. O(N) where N is the number of elements to be removed by the operation.
|
125
|
-
#
|
126
|
-
# @
|
127
|
-
# @
|
128
|
-
# @
|
126
|
+
# See <https://redis.io/commands/ltrim> for more details.
|
127
|
+
# @parameter key [Key]
|
128
|
+
# @parameter start [Integer]
|
129
|
+
# @parameter stop [Integer]
|
129
130
|
def ltrim(key, start, stop)
|
130
|
-
call(
|
131
|
+
call("LTRIM", key, start, stop)
|
131
132
|
end
|
132
133
|
|
133
134
|
# Remove and get the last element in a list. O(1).
|
134
|
-
#
|
135
|
-
# @
|
135
|
+
# See <https://redis.io/commands/rpop> for more details.
|
136
|
+
# @parameter key [Key]
|
136
137
|
def rpop(key)
|
137
|
-
call(
|
138
|
+
call("RPOP", key)
|
138
139
|
end
|
139
140
|
|
140
141
|
# Remove the last element in a list, prepend it to another list and return it. O(1).
|
141
|
-
#
|
142
|
-
# @
|
143
|
-
# @
|
142
|
+
# See <https://redis.io/commands/rpoplpush> for more details.
|
143
|
+
# @parameter source [Key]
|
144
|
+
# @parameter destination [Key]
|
144
145
|
def rpoplpush(source, destination=nil)
|
145
146
|
destination = source if destination.nil?
|
146
147
|
|
147
|
-
call(
|
148
|
+
call("RPOPLPUSH", source, destination)
|
148
149
|
end
|
149
150
|
|
150
151
|
# 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.
|
151
|
-
#
|
152
|
-
# @
|
153
|
-
# @
|
152
|
+
# See <https://redis.io/commands/rpush> for more details.
|
153
|
+
# @parameter key [Key]
|
154
|
+
# @parameter element [String]
|
154
155
|
def rpush(key, value, *values)
|
155
156
|
case value
|
156
157
|
when Array
|
@@ -159,15 +160,15 @@ module Protocol
|
|
159
160
|
values = [value] + values
|
160
161
|
end
|
161
162
|
|
162
|
-
call(
|
163
|
+
call("RPUSH", key, *values)
|
163
164
|
end
|
164
165
|
|
165
166
|
# 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.
|
166
|
-
#
|
167
|
-
# @
|
168
|
-
# @
|
167
|
+
# See <https://redis.io/commands/rpushx> for more details.
|
168
|
+
# @parameter key [Key]
|
169
|
+
# @parameter element [String]
|
169
170
|
def rpushx(key, value)
|
170
|
-
call(
|
171
|
+
call("RPUSHX", key, value)
|
171
172
|
end
|
172
173
|
end
|
173
174
|
end
|
@@ -6,13 +6,14 @@
|
|
6
6
|
module Protocol
|
7
7
|
module Redis
|
8
8
|
module Methods
|
9
|
+
# Methods for managing Redis Pub/Sub.
|
9
10
|
module Pubsub
|
10
11
|
# Post a message to a channel.
|
11
|
-
#
|
12
|
-
# @
|
13
|
-
# @
|
12
|
+
# See <https://redis.io/commands/publish> for more details.
|
13
|
+
# @parameter channel [String]
|
14
|
+
# @parameter message [String]
|
14
15
|
def publish(channel, message)
|
15
|
-
call(
|
16
|
+
call("PUBLISH", channel, message)
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
@@ -7,31 +7,30 @@
|
|
7
7
|
module Protocol
|
8
8
|
module Redis
|
9
9
|
module Methods
|
10
|
+
# Methods for managing Redis scripting.
|
10
11
|
module Scripting
|
11
|
-
# Execute a Lua script server side.
|
12
|
-
# @
|
13
|
-
# @
|
14
|
-
# @
|
15
|
-
# @
|
16
|
-
|
17
|
-
|
18
|
-
call("EVAL", *arguments)
|
12
|
+
# Execute a Lua script server side.
|
13
|
+
# @parameter script [String] The Lua script to execute.
|
14
|
+
# @parameter key_count [Integer] Number of keys that follow.
|
15
|
+
# @parameter keys_and_args [Array] Keys followed by arguments to the script.
|
16
|
+
# @returns [Object] The result of the script execution.
|
17
|
+
def eval(script, key_count = 0, *keys_and_args)
|
18
|
+
call("EVAL", script, key_count, *keys_and_args)
|
19
19
|
end
|
20
20
|
|
21
|
-
# Execute a Lua script
|
22
|
-
# @
|
23
|
-
# @
|
24
|
-
# @
|
25
|
-
# @
|
26
|
-
|
27
|
-
|
28
|
-
call("EVALSHA", *arguments)
|
21
|
+
# Execute a cached Lua script by SHA1 digest.
|
22
|
+
# @parameter sha1 [String] The SHA1 digest of the script to execute.
|
23
|
+
# @parameter key_count [Integer] Number of keys that follow.
|
24
|
+
# @parameter keys_and_args [Array] Keys followed by arguments to the script.
|
25
|
+
# @returns [Object] The result of the script execution.
|
26
|
+
def evalsha(sha1, key_count = 0, *keys_and_args)
|
27
|
+
call("EVALSHA", sha1, key_count, *keys_and_args)
|
29
28
|
end
|
30
29
|
|
31
|
-
# Execute script management commands
|
32
|
-
# @
|
33
|
-
# @
|
34
|
-
# @
|
30
|
+
# Execute script management commands.
|
31
|
+
# @parameter subcommand [String|Symbol] The script subcommand (debug, exists, flush, load, kill).
|
32
|
+
# @parameter arguments [Array] Additional arguments for the subcommand.
|
33
|
+
# @returns [Object] The result of the script command.
|
35
34
|
def script(subcommand, *arguments)
|
36
35
|
call("SCRIPT", subcommand.to_s, *arguments)
|
37
36
|
end
|
@@ -7,15 +7,16 @@
|
|
7
7
|
module Protocol
|
8
8
|
module Redis
|
9
9
|
module Methods
|
10
|
+
# Methods for managing Redis servers.
|
10
11
|
module Server
|
11
12
|
# Get information and statistics about the server.
|
12
|
-
#
|
13
|
-
# @
|
13
|
+
# See <https://redis.io/commands/info> for more details.
|
14
|
+
# @parameter section [String]
|
14
15
|
def info
|
15
16
|
metadata = {}
|
16
17
|
|
17
|
-
call(
|
18
|
-
key, value = line.split(
|
18
|
+
call("INFO").each_line(Redis::Connection::CRLF) do |line|
|
19
|
+
key, value = line.split(":")
|
19
20
|
|
20
21
|
if value
|
21
22
|
metadata[key.to_sym] = value.chomp!
|
@@ -25,11 +26,14 @@ module Protocol
|
|
25
26
|
return metadata
|
26
27
|
end
|
27
28
|
|
29
|
+
# Get the client information for the current connection.
|
30
|
+
# See <https://redis.io/commands/client-info> for more details.
|
31
|
+
# @returns [Hash] A hash containing client metadata.
|
28
32
|
def client_info
|
29
33
|
metadata = {}
|
30
34
|
|
31
|
-
call(
|
32
|
-
key, value = pair.split(
|
35
|
+
call("CLIENT", "INFO").split(/\s+/).each do |pair|
|
36
|
+
key, value = pair.split("=")
|
33
37
|
|
34
38
|
if value
|
35
39
|
metadata[key.to_sym] = value
|
@@ -42,10 +46,10 @@ module Protocol
|
|
42
46
|
end
|
43
47
|
|
44
48
|
# Remove all keys from the current database.
|
45
|
-
#
|
46
|
-
# @
|
49
|
+
# See <https://redis.io/commands/flushdb> for more details.
|
50
|
+
# @parameter async [Enum]
|
47
51
|
def flushdb!
|
48
|
-
call(
|
52
|
+
call("FLUSHDB")
|
49
53
|
end
|
50
54
|
end
|
51
55
|
end
|