protocol-redis 0.4.0 → 0.6.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
- data/lib/protocol/redis/methods.rb +4 -0
- data/lib/protocol/redis/methods/generic.rb +23 -23
- data/lib/protocol/redis/methods/hashes.rb +13 -13
- data/lib/protocol/redis/methods/lists.rb +17 -17
- data/{tasks/methods.trenni → lib/protocol/redis/methods/pubsub.rb} +8 -16
- data/lib/protocol/redis/methods/scripting.rb +82 -0
- data/lib/protocol/redis/methods/server.rb +2 -2
- data/lib/protocol/redis/methods/sets.rb +145 -0
- data/lib/protocol/redis/methods/sorted_sets.rb +253 -9
- data/lib/protocol/redis/methods/streams.rb +141 -0
- data/lib/protocol/redis/methods/strings.rb +24 -21
- data/lib/protocol/redis/version.rb +1 -1
- metadata +49 -28
- data/.editorconfig +0 -6
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/.travis.yml +0 -22
- data/Gemfile +0 -10
- data/README.md +0 -67
- data/Rakefile +0 -10
- data/benchmark/call.rb +0 -55
- data/protocol-redis.gemspec +0 -28
- data/tasks/generate.rake +0 -174
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
+
# Copyright, 2018, by Huba Nagy.
|
4
5
|
#
|
5
6
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
7
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -23,23 +24,14 @@
|
|
23
24
|
module Protocol
|
24
25
|
module Redis
|
25
26
|
module Methods
|
26
|
-
module
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
?>
|
34
|
-
|
35
|
-
<?r end ?>
|
36
|
-
def #{method_name}(*arguments)
|
37
|
-
call(#{command.to_s.dump}, *arguments)
|
27
|
+
module Pubsub
|
28
|
+
# Post a message to a channel.
|
29
|
+
# @see https://redis.io/commands/publish
|
30
|
+
# @param channel [String]
|
31
|
+
# @param message [String]
|
32
|
+
def publish(channel, message)
|
33
|
+
call('PUBLISH', channel, message)
|
38
34
|
end
|
39
|
-
<?r
|
40
|
-
first = false
|
41
|
-
end
|
42
|
-
?>
|
43
35
|
end
|
44
36
|
end
|
45
37
|
end
|
@@ -0,0 +1,82 @@
|
|
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 Scripting
|
27
|
+
# Execute a Lua script server side. Depends on the script that is executed.
|
28
|
+
# @see https://redis.io/commands/eval
|
29
|
+
# @param script [String]
|
30
|
+
# @param numkeys [Integer]
|
31
|
+
# @param key [Key]
|
32
|
+
# @param arg [String]
|
33
|
+
def eval(*arguments)
|
34
|
+
call("EVAL", *arguments)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Execute a Lua script server side. Depends on the script that is executed.
|
38
|
+
# @see https://redis.io/commands/evalsha
|
39
|
+
# @param sha1 [String]
|
40
|
+
# @param numkeys [Integer]
|
41
|
+
# @param key [Key]
|
42
|
+
# @param arg [String]
|
43
|
+
def evalsha(*arguments)
|
44
|
+
call("EVALSHA", *arguments)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Set the debug mode for executed scripts. O(1).
|
48
|
+
# @see https://redis.io/commands/script debug
|
49
|
+
# @param mode [Enum]
|
50
|
+
def script_debug(*arguments)
|
51
|
+
call("SCRIPT DEBUG", *arguments)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Check existence of scripts in the script cache. O(N) with N being the number of scripts to check (so checking a single script is an O(1) operation).
|
55
|
+
# @see https://redis.io/commands/script exists
|
56
|
+
# @param sha1 [String]
|
57
|
+
def script_exists(*arguments)
|
58
|
+
call("SCRIPT EXISTS", *arguments)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Remove all the scripts from the script cache. O(N) with N being the number of scripts in cache.
|
62
|
+
# @see https://redis.io/commands/script flush
|
63
|
+
def script_flush(*arguments)
|
64
|
+
call("SCRIPT FLUSH", *arguments)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Kill the script currently in execution. O(1).
|
68
|
+
# @see https://redis.io/commands/script kill
|
69
|
+
def script_kill(*arguments)
|
70
|
+
call("SCRIPT KILL", *arguments)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Load the specified Lua script into the script cache. O(N) with N being the length in bytes of the script body.
|
74
|
+
# @see https://redis.io/commands/script load
|
75
|
+
# @param script [String]
|
76
|
+
def script_load(*arguments)
|
77
|
+
call("SCRIPT LOAD", *arguments)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -31,7 +31,7 @@ module Protocol
|
|
31
31
|
def info
|
32
32
|
metadata = {}
|
33
33
|
|
34
|
-
call('INFO').each_line(
|
34
|
+
call('INFO').each_line(Redis::Connection::CRLF) do |line|
|
35
35
|
key, value = line.split(':')
|
36
36
|
|
37
37
|
if value
|
@@ -46,7 +46,7 @@ module Protocol
|
|
46
46
|
# @see https://redis.io/commands/flushdb
|
47
47
|
# @param async [Enum]
|
48
48
|
def flushdb!
|
49
|
-
|
49
|
+
call('FLUSHDB')
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -0,0 +1,145 @@
|
|
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 Sets
|
27
|
+
# Add one or more members to a set. O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments.
|
28
|
+
# @see https://redis.io/commands/sadd
|
29
|
+
# @param key [Key]
|
30
|
+
# @param member [String]
|
31
|
+
def sadd(*arguments)
|
32
|
+
call("SADD", *arguments)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Get the number of members in a set. O(1).
|
36
|
+
# @see https://redis.io/commands/scard
|
37
|
+
# @param key [Key]
|
38
|
+
def scard(*arguments)
|
39
|
+
call("SCARD", *arguments)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Subtract multiple sets. O(N) where N is the total number of elements in all given sets.
|
43
|
+
# @see https://redis.io/commands/sdiff
|
44
|
+
# @param key [Key]
|
45
|
+
def sdiff(*arguments)
|
46
|
+
call("SDIFF", *arguments)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Subtract multiple sets and store the resulting set in a key. O(N) where N is the total number of elements in all given sets.
|
50
|
+
# @see https://redis.io/commands/sdiffstore
|
51
|
+
# @param destination [Key]
|
52
|
+
# @param key [Key]
|
53
|
+
def sdiffstore(*arguments)
|
54
|
+
call("SDIFFSTORE", *arguments)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Intersect multiple sets. O(N*M) worst case where N is the cardinality of the smallest set and M is the number of sets.
|
58
|
+
# @see https://redis.io/commands/sinter
|
59
|
+
# @param key [Key]
|
60
|
+
def sinter(*arguments)
|
61
|
+
call("SINTER", *arguments)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Intersect multiple sets and store the resulting set in a key. O(N*M) worst case where N is the cardinality of the smallest set and M is the number of sets.
|
65
|
+
# @see https://redis.io/commands/sinterstore
|
66
|
+
# @param destination [Key]
|
67
|
+
# @param key [Key]
|
68
|
+
def sinterstore(*arguments)
|
69
|
+
call("SINTERSTORE", *arguments)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Determine if a given value is a member of a set. O(1).
|
73
|
+
# @see https://redis.io/commands/sismember
|
74
|
+
# @param key [Key]
|
75
|
+
# @param member [String]
|
76
|
+
def sismember(*arguments)
|
77
|
+
call("SISMEMBER", *arguments)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Get all the members in a set. O(N) where N is the set cardinality.
|
81
|
+
# @see https://redis.io/commands/smembers
|
82
|
+
# @param key [Key]
|
83
|
+
def smembers(*arguments)
|
84
|
+
call("SMEMBERS", *arguments)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Move a member from one set to another. O(1).
|
88
|
+
# @see https://redis.io/commands/smove
|
89
|
+
# @param source [Key]
|
90
|
+
# @param destination [Key]
|
91
|
+
# @param member [String]
|
92
|
+
def smove(*arguments)
|
93
|
+
call("SMOVE", *arguments)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Remove and return one or multiple random members from a set. O(1).
|
97
|
+
# @see https://redis.io/commands/spop
|
98
|
+
# @param key [Key]
|
99
|
+
# @param count [Integer]
|
100
|
+
def spop(*arguments)
|
101
|
+
call("SPOP", *arguments)
|
102
|
+
end
|
103
|
+
|
104
|
+
# Get one or multiple random members from a set. Without the count argument O(1), otherwise O(N) where N is the absolute value of the passed count.
|
105
|
+
# @see https://redis.io/commands/srandmember
|
106
|
+
# @param key [Key]
|
107
|
+
# @param count [Integer]
|
108
|
+
def srandmember(*arguments)
|
109
|
+
call("SRANDMEMBER", *arguments)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Remove one or more members from a set. O(N) where N is the number of members to be removed.
|
113
|
+
# @see https://redis.io/commands/srem
|
114
|
+
# @param key [Key]
|
115
|
+
# @param member [String]
|
116
|
+
def srem(*arguments)
|
117
|
+
call("SREM", *arguments)
|
118
|
+
end
|
119
|
+
|
120
|
+
# Add multiple sets. O(N) where N is the total number of elements in all given sets.
|
121
|
+
# @see https://redis.io/commands/sunion
|
122
|
+
# @param key [Key]
|
123
|
+
def sunion(*arguments)
|
124
|
+
call("SUNION", *arguments)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Add multiple sets and store the resulting set in a key. O(N) where N is the total number of elements in all given sets.
|
128
|
+
# @see https://redis.io/commands/sunionstore
|
129
|
+
# @param destination [Key]
|
130
|
+
# @param key [Key]
|
131
|
+
def sunionstore(*arguments)
|
132
|
+
call("SUNIONSTORE", *arguments)
|
133
|
+
end
|
134
|
+
|
135
|
+
# Incrementally iterate Set elements. 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..
|
136
|
+
# @see https://redis.io/commands/sscan
|
137
|
+
# @param key [Key]
|
138
|
+
# @param cursor [Integer]
|
139
|
+
def sscan(*arguments)
|
140
|
+
call("SSCAN", *arguments)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
3
4
|
# Copyright, 2020, by Dimitry Chopey.
|
4
|
-
# Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
5
5
|
#
|
6
6
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
7
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -25,6 +25,22 @@ module Protocol
|
|
25
25
|
module Redis
|
26
26
|
module Methods
|
27
27
|
module SortedSets
|
28
|
+
# Remove and return the member with the lowest score from one or more sorted sets, or block until one is available. O(log(N)) with N being the number of elements in the sorted set.
|
29
|
+
# @see https://redis.io/commands/bzpopmin
|
30
|
+
# @param key [Key]
|
31
|
+
# @param timeout [Integer]
|
32
|
+
def bzpopmin(*keys, timeout: 0)
|
33
|
+
call("BZPOPMIN", *keys, timeout)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Remove and return the member with the highest score from one or more sorted sets, or block until one is available. O(log(N)) with N being the number of elements in the sorted set.
|
37
|
+
# @see https://redis.io/commands/bzpopmax
|
38
|
+
# @param key [Key]
|
39
|
+
# @param timeout [Integer]
|
40
|
+
def bzpopmax(*keys, timeout: 0)
|
41
|
+
call("BZPOPMAX", *keys, timeout: 0)
|
42
|
+
end
|
43
|
+
|
28
44
|
# Add one or more members to a sorted set, or update its score if it already exists. O(log(N)) for each item added, where N is the number of elements in the sorted set.
|
29
45
|
# @see https://redis.io/commands/zadd
|
30
46
|
# @param key [Key]
|
@@ -41,20 +57,95 @@ module Protocol
|
|
41
57
|
arguments = ["ZADD", key]
|
42
58
|
|
43
59
|
if update == true
|
44
|
-
arguments
|
60
|
+
arguments.push("XX")
|
45
61
|
elsif update == false
|
46
|
-
arguments
|
62
|
+
arguments.push("NX")
|
47
63
|
end
|
48
64
|
|
49
|
-
arguments
|
50
|
-
arguments
|
65
|
+
arguments.push("CH") if change
|
66
|
+
arguments.push("INCR") if increment
|
51
67
|
|
52
|
-
arguments
|
53
|
-
arguments.
|
68
|
+
arguments.push(score, member)
|
69
|
+
arguments.push(*others)
|
54
70
|
|
55
71
|
call(*arguments)
|
56
72
|
end
|
57
|
-
|
73
|
+
|
74
|
+
# Get the number of members in a sorted set. O(1).
|
75
|
+
# @see https://redis.io/commands/zcard
|
76
|
+
# @param key [Key]
|
77
|
+
def zcard(key)
|
78
|
+
call("ZCARD", key)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Count the members in a sorted set with scores within the given values. O(log(N)) with N being the number of elements in the sorted set.
|
82
|
+
# @see https://redis.io/commands/zcount
|
83
|
+
# @param key [Key]
|
84
|
+
# @param min [Double]
|
85
|
+
# @param max [Double]
|
86
|
+
def zcount(key, min, max)
|
87
|
+
call("ZCOUNT", key, min, max)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Increment the score of a member in a sorted set. O(log(N)) where N is the number of elements in the sorted set.
|
91
|
+
# @see https://redis.io/commands/zincrby
|
92
|
+
# @param key [Key]
|
93
|
+
# @param increment [Integer]
|
94
|
+
# @param member [String]
|
95
|
+
def zincrby(key, increment, member)
|
96
|
+
call("ZINCRBY", key, amount, member)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Intersect multiple sorted sets and store the resulting sorted set in a new key. O(N*K)+O(M*log(M)) worst case with N being the smallest input sorted set, K being the number of input sorted sets and M being the number of elements in the resulting sorted set.
|
100
|
+
# @see https://redis.io/commands/zinterstore
|
101
|
+
# @param destination [Key]
|
102
|
+
# @param keys [Array<Key>]
|
103
|
+
# @param weights [Array<Integer>]
|
104
|
+
# @param aggregate [Enum] one of sum, min, max.
|
105
|
+
def zinterstore(destination, keys, weights = nil, aggregate: nil)
|
106
|
+
arguments = []
|
107
|
+
|
108
|
+
if weights
|
109
|
+
if weights.size != keys.size
|
110
|
+
raise ArgumentError, "#{weights.size} weights given for #{keys.size} keys!"
|
111
|
+
end
|
112
|
+
|
113
|
+
arguments.push("WEIGHTS")
|
114
|
+
arguments.concat(weights)
|
115
|
+
end
|
116
|
+
|
117
|
+
if aggregate
|
118
|
+
arguments.push("AGGREGATE", aggregate)
|
119
|
+
end
|
120
|
+
|
121
|
+
call("ZINTERSTORE", destination, keys.size, *keys, *arguments)
|
122
|
+
end
|
123
|
+
|
124
|
+
# Count the number of members in a sorted set between a given lexicographical range. O(log(N)) with N being the number of elements in the sorted set.
|
125
|
+
# @see https://redis.io/commands/zlexcount
|
126
|
+
# @param key [Key]
|
127
|
+
# @param min [String]
|
128
|
+
# @param max [String]
|
129
|
+
def zlexcount(key, min, max)
|
130
|
+
call("ZLEXCOUNT", key, min, max)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Remove and return members with the highest scores in a sorted set. O(log(N)*M) with N being the number of elements in the sorted set, and M being the number of elements popped.
|
134
|
+
# @see https://redis.io/commands/zpopmax
|
135
|
+
# @param key [Key]
|
136
|
+
# @param count [Integer]
|
137
|
+
def zpopmax(key, count = 1)
|
138
|
+
call("ZPOPMAX", key, count)
|
139
|
+
end
|
140
|
+
|
141
|
+
# Remove and return members with the lowest scores in a sorted set. O(log(N)*M) with N being the number of elements in the sorted set, and M being the number of elements popped.
|
142
|
+
# @see https://redis.io/commands/zpopmin
|
143
|
+
# @param key [Key]
|
144
|
+
# @param count [Integer]
|
145
|
+
def zpopmin(key, count = 1)
|
146
|
+
call("ZPOPMIN", key, count = 1)
|
147
|
+
end
|
148
|
+
|
58
149
|
# Return a range of members in a sorted set, by index. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned.
|
59
150
|
# @see https://redis.io/commands/zrange
|
60
151
|
# @param key [Key]
|
@@ -64,11 +155,65 @@ module Protocol
|
|
64
155
|
def zrange(key, start, stop, with_scores: false)
|
65
156
|
arguments = [start, stop]
|
66
157
|
|
67
|
-
arguments
|
158
|
+
arguments.push("WITHSCORES") if with_scores
|
68
159
|
|
69
160
|
call("ZRANGE", key, *arguments)
|
70
161
|
end
|
71
162
|
|
163
|
+
# Return a range of members in a sorted set, by lexicographical range. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned. If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).
|
164
|
+
# @see https://redis.io/commands/zrangebylex
|
165
|
+
# @param key [Key]
|
166
|
+
# @param min [String]
|
167
|
+
# @param max [String]
|
168
|
+
# @param limit [Tuple<offset, count>] Limit the results to the specified `offset` and `count` items.
|
169
|
+
def zrangebylex(key, min, max, limit: nil)
|
170
|
+
if limit
|
171
|
+
arguments = ["LIMIT", *limit]
|
172
|
+
end
|
173
|
+
|
174
|
+
call("ZRANGEBYLEX", key, min, max, *arguments)
|
175
|
+
end
|
176
|
+
|
177
|
+
# Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned. If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).
|
178
|
+
# @see https://redis.io/commands/zrevrangebylex
|
179
|
+
# @param key [Key]
|
180
|
+
# @param max [String]
|
181
|
+
# @param min [String]
|
182
|
+
def zrevrangebylex(key, min, max, limit: nil)
|
183
|
+
if limit
|
184
|
+
arguments = ["LIMIT", *limit]
|
185
|
+
end
|
186
|
+
|
187
|
+
call("ZREVRANGEBYLEX", key, min, max, *arguments)
|
188
|
+
end
|
189
|
+
|
190
|
+
# Return a range of members in a sorted set, by score. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned. If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).
|
191
|
+
# @see https://redis.io/commands/zrangebyscore
|
192
|
+
# @param key [Key]
|
193
|
+
# @param min [Integer]
|
194
|
+
# @param max [Integer]
|
195
|
+
# @param with_scores [Boolean] Return the scores of the elements together with the elements.
|
196
|
+
# @param limit [Tuple<offset, count>] Limit the results to the specified `offset` and `count` items.
|
197
|
+
#
|
198
|
+
# @example Retrieve the first 10 members with score `>= 0` and `<= 100`
|
199
|
+
# redis.zrangebyscore("zset", "0", "100", limit: [0, 10])
|
200
|
+
def zrangebyscore(key, min, max, with_scores: false, limit: nil)
|
201
|
+
arguments = [min, max]
|
202
|
+
|
203
|
+
arguments.push('WITHSCORES') if with_scores
|
204
|
+
arguments.push('LIMIT', *limit) if limit
|
205
|
+
|
206
|
+
call('ZRANGEBYSCORE', key, *arguments)
|
207
|
+
end
|
208
|
+
|
209
|
+
# Determine the index of a member in a sorted set. O(log(N)).
|
210
|
+
# @see https://redis.io/commands/zrank
|
211
|
+
# @param key [Key]
|
212
|
+
# @param member [String]
|
213
|
+
def zrank(key, member)
|
214
|
+
call("ZRANK", key, member)
|
215
|
+
end
|
216
|
+
|
72
217
|
# Remove one or more members from a sorted set. O(M*log(N)) with N being the number of elements in the sorted set and M the number of elements to be removed.
|
73
218
|
# @see https://redis.io/commands/zrem
|
74
219
|
# @param key [Key]
|
@@ -76,6 +221,105 @@ module Protocol
|
|
76
221
|
def zrem(key, member)
|
77
222
|
call("ZREM", key, member)
|
78
223
|
end
|
224
|
+
|
225
|
+
# Remove all members in a sorted set between the given lexicographical range. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.
|
226
|
+
# @see https://redis.io/commands/zremrangebylex
|
227
|
+
# @param key [Key]
|
228
|
+
# @param min [String]
|
229
|
+
# @param max [String]
|
230
|
+
def zremrangebylex(key, min, max)
|
231
|
+
call("ZREMRANGEBYLEX", key, min, max)
|
232
|
+
end
|
233
|
+
|
234
|
+
# Remove all members in a sorted set within the given indexes. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.
|
235
|
+
# @see https://redis.io/commands/zremrangebyrank
|
236
|
+
# @param key [Key]
|
237
|
+
# @param start [Integer]
|
238
|
+
# @param stop [Integer]
|
239
|
+
def zremrangebyrank(key, start, stop)
|
240
|
+
call("ZREMRANGEBYRANK", key, start, stop)
|
241
|
+
end
|
242
|
+
|
243
|
+
# Remove all members in a sorted set within the given scores. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.
|
244
|
+
# @see https://redis.io/commands/zremrangebyscore
|
245
|
+
# @param key [Key]
|
246
|
+
# @param min [Double]
|
247
|
+
# @param max [Double]
|
248
|
+
def zremrangebyscore(key, min, max)
|
249
|
+
call("ZREMRANGEBYSCORE", key, min, max)
|
250
|
+
end
|
251
|
+
|
252
|
+
# Return a range of members in a sorted set, by index, with scores ordered from high to low. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned.
|
253
|
+
# @see https://redis.io/commands/zrevrange
|
254
|
+
# @param key [Key]
|
255
|
+
# @param start [Integer]
|
256
|
+
# @param stop [Integer]
|
257
|
+
# @param withscores [Enum]
|
258
|
+
def zrevrange(key, min, max, with_scores: false)
|
259
|
+
arguments = [min, max]
|
260
|
+
|
261
|
+
arguments.push('WITHSCORES') if with_scores
|
262
|
+
|
263
|
+
call("ZREVRANGE", key, *arguments)
|
264
|
+
end
|
265
|
+
|
266
|
+
# Return a range of members in a sorted set, by score, with scores ordered from high to low. O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned. If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).
|
267
|
+
# @see https://redis.io/commands/zrevrangebyscore
|
268
|
+
# @param key [Key]
|
269
|
+
# @param max [Double]
|
270
|
+
# @param min [Double]
|
271
|
+
# @param withscores [Enum]
|
272
|
+
def zrevrangebyscore(key, min, max, with_scores: false, limit: nil)
|
273
|
+
arguments = [min, max]
|
274
|
+
|
275
|
+
arguments.push('WITHSCORES') if with_scores
|
276
|
+
arguments.push('LIMIT', *limit) if limit
|
277
|
+
|
278
|
+
call("ZREVRANGEBYSCORE", key, *arguments)
|
279
|
+
end
|
280
|
+
|
281
|
+
# Determine the index of a member in a sorted set, with scores ordered from high to low. O(log(N)).
|
282
|
+
# @see https://redis.io/commands/zrevrank
|
283
|
+
# @param key [Key]
|
284
|
+
# @param member [String]
|
285
|
+
def zrevrank(key, member)
|
286
|
+
call("ZREVRANK", key, member)
|
287
|
+
end
|
288
|
+
|
289
|
+
# Get the score associated with the given member in a sorted set. O(1).
|
290
|
+
# @see https://redis.io/commands/zscore
|
291
|
+
# @param key [Key]
|
292
|
+
# @param member [String]
|
293
|
+
def zscore(key, member)
|
294
|
+
call("ZSCORE", key, member)
|
295
|
+
end
|
296
|
+
|
297
|
+
# Add multiple sorted sets and store the resulting sorted set in a new key. O(N)+O(M log(M)) with N being the sum of the sizes of the input sorted sets, and M being the number of elements in the resulting sorted set.
|
298
|
+
# @see https://redis.io/commands/zunionstore
|
299
|
+
# @param destination [Key]
|
300
|
+
# @param numkeys [Integer]
|
301
|
+
# @param key [Key]
|
302
|
+
def zunionstore(*arguments)
|
303
|
+
call("ZUNIONSTORE", *arguments)
|
304
|
+
end
|
305
|
+
|
306
|
+
# Incrementally iterate sorted sets elements and associated scores. 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..
|
307
|
+
# @see https://redis.io/commands/zscan
|
308
|
+
# @param key [Key]
|
309
|
+
# @param cursor [Integer]
|
310
|
+
def zscan(key, cursor = 0, match: nil, count: nil)
|
311
|
+
arguments = [key, cursor]
|
312
|
+
|
313
|
+
if match
|
314
|
+
arguments.push("MATCH", match)
|
315
|
+
end
|
316
|
+
|
317
|
+
if count
|
318
|
+
arguments.push("COUNT", count)
|
319
|
+
end
|
320
|
+
|
321
|
+
call("ZSCAN", *arguments)
|
322
|
+
end
|
79
323
|
end
|
80
324
|
end
|
81
325
|
end
|