protocol-redis 0.4.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,141 @@
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 Streams
27
+ # Get information on streams and consumer groups. O(N) with N being the number of returned items for the subcommands CONSUMERS and GROUPS. The STREAM subcommand is O(log N) with N being the number of items in the stream.
28
+ # @see https://redis.io/commands/xinfo
29
+ # @param help [Enum]
30
+ def xinfo(*arguments)
31
+ call("XINFO", *arguments)
32
+ end
33
+
34
+ # Appends a new entry to a stream. O(1).
35
+ # @see https://redis.io/commands/xadd
36
+ # @param key [Key]
37
+ # @param ID [String]
38
+ def xadd(*arguments)
39
+ call("XADD", *arguments)
40
+ end
41
+
42
+ # Trims the stream to (approximately if '~' is passed) a certain size. O(N), with N being the number of evicted entries. Constant times are very small however, since entries are organized in macro nodes containing multiple entries that can be released with a single deallocation.
43
+ # @see https://redis.io/commands/xtrim
44
+ # @param key [Key]
45
+ # @param strategy [Enum]
46
+ # @param approx [Enum]
47
+ # @param count [Integer]
48
+ def xtrim(*arguments)
49
+ call("XTRIM", *arguments)
50
+ end
51
+
52
+ # Removes the specified entries from the stream. Returns the number of items actually deleted, that may be different from the number of IDs passed in case certain IDs do not exist. O(1) for each single item to delete in the stream, regardless of the stream size.
53
+ # @see https://redis.io/commands/xdel
54
+ # @param key [Key]
55
+ # @param ID [String]
56
+ def xdel(*arguments)
57
+ call("XDEL", *arguments)
58
+ end
59
+
60
+ # Return a range of elements in a stream, with IDs matching the specified IDs interval. O(N) with N being the number of elements being returned. If N is constant (e.g. always asking for the first 10 elements with COUNT), you can consider it O(1).
61
+ # @see https://redis.io/commands/xrange
62
+ # @param key [Key]
63
+ # @param start [String]
64
+ # @param end [String]
65
+ def xrange(*arguments)
66
+ call("XRANGE", *arguments)
67
+ end
68
+
69
+ # Return a range of elements in a stream, with IDs matching the specified IDs interval, in reverse order (from greater to smaller IDs) compared to XRANGE. O(N) with N being the number of elements returned. If N is constant (e.g. always asking for the first 10 elements with COUNT), you can consider it O(1).
70
+ # @see https://redis.io/commands/xrevrange
71
+ # @param key [Key]
72
+ # @param end [String]
73
+ # @param start [String]
74
+ def xrevrange(*arguments)
75
+ call("XREVRANGE", *arguments)
76
+ end
77
+
78
+ # Return the number of entires in a stream. O(1).
79
+ # @see https://redis.io/commands/xlen
80
+ # @param key [Key]
81
+ def xlen(*arguments)
82
+ call("XLEN", *arguments)
83
+ end
84
+
85
+ # Return never seen elements in multiple streams, with IDs greater than the ones reported by the caller for each stream. Can block. For each stream mentioned: O(N) with N being the number of elements being returned, it means that XREAD-ing with a fixed COUNT is O(1). Note that when the BLOCK option is used, XADD will pay O(M) time in order to serve the M clients blocked on the stream getting new data.
86
+ # @see https://redis.io/commands/xread
87
+ # @param streams [Enum]
88
+ # @param key [Key]
89
+ # @param id [String]
90
+ def xread(*arguments)
91
+ call("XREAD", *arguments)
92
+ end
93
+
94
+ # Create, destroy, and manage consumer groups. O(1) for all the subcommands, with the exception of the DESTROY subcommand which takes an additional O(M) time in order to delete the M entries inside the consumer group pending entries list (PEL).
95
+ # @see https://redis.io/commands/xgroup
96
+ def xgroup(*arguments)
97
+ call("XGROUP", *arguments)
98
+ end
99
+
100
+ # Return new entries from a stream using a consumer group, or access the history of the pending entries for a given consumer. Can block. For each stream mentioned: O(M) with M being the number of elements returned. If M is constant (e.g. always asking for the first 10 elements with COUNT), you can consider it O(1). On the other side when XREADGROUP blocks, XADD will pay the O(N) time in order to serve the N clients blocked on the stream getting new data.
101
+ # @see https://redis.io/commands/xreadgroup
102
+ # @param noack [Enum]
103
+ # @param streams [Enum]
104
+ # @param key [Key]
105
+ # @param ID [String]
106
+ def xreadgroup(*arguments)
107
+ call("XREADGROUP", *arguments)
108
+ end
109
+
110
+ # Marks a pending message as correctly processed, effectively removing it from the pending entries list of the consumer group. Return value of the command is the number of messages successfully acknowledged, that is, the IDs we were actually able to resolve in the PEL. O(1) for each message ID processed.
111
+ # @see https://redis.io/commands/xack
112
+ # @param key [Key]
113
+ # @param group [String]
114
+ # @param ID [String]
115
+ def xack(*arguments)
116
+ call("XACK", *arguments)
117
+ end
118
+
119
+ # Changes (or acquires) ownership of a message in a consumer group, as if the message was delivered to the specified consumer. O(log N) with N being the number of messages in the PEL of the consumer group.
120
+ # @see https://redis.io/commands/xclaim
121
+ # @param key [Key]
122
+ # @param group [String]
123
+ # @param consumer [String]
124
+ # @param min-idle-time [String]
125
+ # @param ID [String]
126
+ def xclaim(*arguments)
127
+ call("XCLAIM", *arguments)
128
+ end
129
+
130
+ # Return information and entries from a stream consumer group pending entries list, that are messages fetched but never acknowledged. O(N) with N being the number of elements returned, so asking for a small fixed number of entries per call is O(1). When the command returns just the summary it runs in O(1) time assuming the list of consumers is small, otherwise there is additional O(N) time needed to iterate every consumer.
131
+ # @see https://redis.io/commands/xpending
132
+ # @param key [Key]
133
+ # @param group [String]
134
+ # @param consumer [String]
135
+ def xpending(*arguments)
136
+ call("XPENDING", *arguments)
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
@@ -30,21 +30,21 @@ module Protocol
30
30
  # @param key [Key]
31
31
  # @param value [String]
32
32
  def append(key, value)
33
- return call('APPEND', key, value)
33
+ call('APPEND', key, value)
34
34
  end
35
35
 
36
36
  # Count set bits in a string. O(N).
37
37
  # @see https://redis.io/commands/bitcount
38
38
  # @param key [Key]
39
39
  def bitcount(key, *range)
40
- return call('BITCOUNT', key, *range)
40
+ call('BITCOUNT', key, *range)
41
41
  end
42
42
 
43
43
  # Decrement the integer value of a key by one. O(1).
44
44
  # @see https://redis.io/commands/decr
45
45
  # @param key [Key]
46
46
  def decr(key)
47
- return call('DECR', key)
47
+ call('DECR', key)
48
48
  end
49
49
 
50
50
  # Decrement the integer value of a key by the given number. O(1).
@@ -52,14 +52,14 @@ module Protocol
52
52
  # @param key [Key]
53
53
  # @param decrement [Integer]
54
54
  def decrby(key, decrement)
55
- return call('DECRBY', key, decrement)
55
+ call('DECRBY', key, decrement)
56
56
  end
57
57
 
58
58
  # Get the value of a key. O(1).
59
59
  # @see https://redis.io/commands/get
60
60
  # @param key [Key]
61
61
  def get(key)
62
- return call('GET', key)
62
+ call('GET', key)
63
63
  end
64
64
 
65
65
  # Returns the bit value at offset in the string value stored at key. O(1).
@@ -67,7 +67,7 @@ module Protocol
67
67
  # @param key [Key]
68
68
  # @param offset [Integer]
69
69
  def getbit(key, offset)
70
- return call('GETBIT', key, offset)
70
+ call('GETBIT', key, offset)
71
71
  end
72
72
 
73
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.
@@ -76,7 +76,7 @@ module Protocol
76
76
  # @param start [Integer]
77
77
  # @param end [Integer]
78
78
  def getrange(key, start_index, end_index)
79
- return call('GETRANGE', key, start_index, end_index)
79
+ call('GETRANGE', key, start_index, end_index)
80
80
  end
81
81
 
82
82
  # Set the string value of a key and return its old value. O(1).
@@ -84,14 +84,14 @@ module Protocol
84
84
  # @param key [Key]
85
85
  # @param value [String]
86
86
  def getset(key, value)
87
- return call('GETSET', key, value)
87
+ call('GETSET', key, value)
88
88
  end
89
89
 
90
90
  # Increment the integer value of a key by one. O(1).
91
91
  # @see https://redis.io/commands/incr
92
92
  # @param key [Key]
93
93
  def incr(key)
94
- return call('INCR', key)
94
+ call('INCR', key)
95
95
  end
96
96
 
97
97
  # Increment the integer value of a key by the given amount. O(1).
@@ -99,7 +99,7 @@ module Protocol
99
99
  # @param key [Key]
100
100
  # @param increment [Integer]
101
101
  def incrby(key, increment)
102
- return call('INCRBY', key, increment)
102
+ call('INCRBY', key, increment)
103
103
  end
104
104
 
105
105
  # Increment the float value of a key by the given amount. O(1).
@@ -107,28 +107,30 @@ module Protocol
107
107
  # @param key [Key]
108
108
  # @param increment [Double]
109
109
  def incrbyfloat(key, increment)
110
- return call('INCRBYFLOAT', key, increment)
110
+ call('INCRBYFLOAT', key, increment)
111
111
  end
112
112
 
113
113
  # Get the values of all the given keys. O(N) where N is the number of keys to retrieve.
114
114
  # @see https://redis.io/commands/mget
115
115
  # @param key [Key]
116
116
  def mget(key, *keys)
117
- return call('MGET', key, *keys)
117
+ call('MGET', key, *keys)
118
118
  end
119
119
 
120
120
  # Set multiple keys to multiple values. O(N) where N is the number of keys to set.
121
121
  # @see https://redis.io/commands/mset
122
122
  def mset(pairs)
123
123
  flattened_pairs = pairs.keys.zip(pairs.values).flatten
124
- return call('MSET', *flattened_pairs)
124
+
125
+ call('MSET', *flattened_pairs)
125
126
  end
126
127
 
127
128
  # 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
129
  # @see https://redis.io/commands/msetnx
129
130
  def msetnx(pairs)
130
131
  flattened_pairs = pairs.keys.zip(pairs.values).flatten
131
- return call('MSETNX', *flattened_pairs)
132
+
133
+ call('MSETNX', *flattened_pairs)
132
134
  end
133
135
 
134
136
  # Set the value and expiration in milliseconds of a key. O(1).
@@ -137,7 +139,7 @@ module Protocol
137
139
  # @param milliseconds [Integer]
138
140
  # @param value [String]
139
141
  def psetex(key, milliseconds, value)
140
- return set key, value, milliseconds: milliseconds
142
+ call('PSETEX', key, milliseconds, value)
141
143
  end
142
144
 
143
145
  # Set the string value of a key. O(1).
@@ -163,7 +165,7 @@ module Protocol
163
165
  arguments << "NX"
164
166
  end
165
167
 
166
- return call('SET', key, value, *arguments)
168
+ call('SET', key, value, *arguments)
167
169
  end
168
170
 
169
171
  # Sets or clears the bit at offset in the string value stored at key. O(1).
@@ -172,7 +174,7 @@ module Protocol
172
174
  # @param offset [Integer]
173
175
  # @param value [Integer]
174
176
  def setbit(key, offset, value)
175
- return call('SETBIT', key, offset, value)
177
+ call('SETBIT', key, offset, value)
176
178
  end
177
179
 
178
180
  # Set the value and expiration of a key. O(1).
@@ -181,15 +183,16 @@ module Protocol
181
183
  # @param seconds [Integer]
182
184
  # @param value [String]
183
185
  def setex(key, seconds, value)
184
- return set key, value, seconds: seconds
186
+ call('SETEX', key, seconds, value)
185
187
  end
186
188
 
187
189
  # Set the value of a key, only if the key does not exist. O(1).
190
+ # @return [Boolean] if the key was set.
188
191
  # @see https://redis.io/commands/setnx
189
192
  # @param key [Key]
190
193
  # @param value [String]
191
194
  def setnx(key, value)
192
- return set key, value, condition: :nx
195
+ call('SETNX', key, value) == 1
193
196
  end
194
197
 
195
198
  # 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,14 +201,14 @@ module Protocol
198
201
  # @param offset [Integer]
199
202
  # @param value [String]
200
203
  def setrange(key, offset, value)
201
- return call('SETRANGE', key, offset, value)
204
+ call('SETRANGE', key, offset, value)
202
205
  end
203
206
 
204
207
  # Get the length of the value stored in a key. O(1).
205
208
  # @see https://redis.io/commands/strlen
206
209
  # @param key [Key]
207
210
  def strlen(key)
208
- return call('STRLEN', key)
211
+ call('STRLEN', key)
209
212
  end
210
213
  end
211
214
  end
@@ -22,6 +22,6 @@
22
22
 
23
23
  module Protocol
24
24
  module Redis
25
- VERSION = "0.4.0"
25
+ VERSION = "0.6.0"
26
26
  end
27
27
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  - Huba Nagy
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-02-11 00:00:00.000000000 Z
12
+ date: 2020-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: async-http
@@ -26,7 +26,7 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: trenni
29
+ name: bake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
@@ -40,7 +40,7 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: benchmark-ips
43
+ name: bake-bundler
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
@@ -54,7 +54,21 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: covered
57
+ name: bake-modernize
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: benchmark-ips
58
72
  requirement: !ruby/object:Gem::Requirement
59
73
  requirements:
60
74
  - - ">="
@@ -81,6 +95,20 @@ dependencies:
81
95
  - - ">="
82
96
  - !ruby/object:Gem::Version
83
97
  version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: covered
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
84
112
  - !ruby/object:Gem::Dependency
85
113
  name: rspec
86
114
  requirement: !ruby/object:Gem::Requirement
@@ -96,7 +124,7 @@ dependencies:
96
124
  - !ruby/object:Gem::Version
97
125
  version: '3.6'
98
126
  - !ruby/object:Gem::Dependency
99
- name: rake
127
+ name: trenni
100
128
  requirement: !ruby/object:Gem::Requirement
101
129
  requirements:
102
130
  - - ">="
@@ -109,22 +137,12 @@ dependencies:
109
137
  - - ">="
110
138
  - !ruby/object:Gem::Version
111
139
  version: '0'
112
- description:
140
+ description:
113
141
  email:
114
- - samuel.williams@oriontransfer.co.nz
115
- - 12huba@gmail.com
116
142
  executables: []
117
143
  extensions: []
118
144
  extra_rdoc_files: []
119
145
  files:
120
- - ".editorconfig"
121
- - ".gitignore"
122
- - ".rspec"
123
- - ".travis.yml"
124
- - Gemfile
125
- - README.md
126
- - Rakefile
127
- - benchmark/call.rb
128
146
  - lib/protocol/redis.rb
129
147
  - lib/protocol/redis/connection.rb
130
148
  - lib/protocol/redis/error.rb
@@ -135,17 +153,20 @@ files:
135
153
  - lib/protocol/redis/methods/geospatial.rb
136
154
  - lib/protocol/redis/methods/hashes.rb
137
155
  - lib/protocol/redis/methods/lists.rb
156
+ - lib/protocol/redis/methods/pubsub.rb
157
+ - lib/protocol/redis/methods/scripting.rb
138
158
  - lib/protocol/redis/methods/server.rb
159
+ - lib/protocol/redis/methods/sets.rb
139
160
  - lib/protocol/redis/methods/sorted_sets.rb
161
+ - lib/protocol/redis/methods/streams.rb
140
162
  - lib/protocol/redis/methods/strings.rb
141
163
  - lib/protocol/redis/version.rb
142
- - protocol-redis.gemspec
143
- - tasks/generate.rake
144
- - tasks/methods.trenni
145
164
  homepage: https://github.com/socketry/protocol-redis
146
- licenses: []
147
- metadata: {}
148
- post_install_message:
165
+ licenses:
166
+ - MIT
167
+ metadata:
168
+ funding_uri: https://github.com/sponsors/ioquatix
169
+ post_install_message:
149
170
  rdoc_options: []
150
171
  require_paths:
151
172
  - lib
@@ -153,15 +174,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
174
  requirements:
154
175
  - - ">="
155
176
  - !ruby/object:Gem::Version
156
- version: '0'
177
+ version: '2.5'
157
178
  required_rubygems_version: !ruby/object:Gem::Requirement
158
179
  requirements:
159
180
  - - ">="
160
181
  - !ruby/object:Gem::Version
161
182
  version: '0'
162
183
  requirements: []
163
- rubygems_version: 3.0.6
164
- signing_key:
184
+ rubygems_version: 3.1.2
185
+ signing_key:
165
186
  specification_version: 4
166
- summary: A RESP protocol client/server parser.
187
+ summary: A transport agnostic RESP protocol client/server.
167
188
  test_files: []