protocol-redis 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44522d19a4786415ce88e26cecde27b950b5f3b225f632fd0f64a0a2a40e6a88
4
- data.tar.gz: 5a79d64a263f6b3f154a490977634b5b3501a2dc43d9a9c726ef7006e11cb155
3
+ metadata.gz: d7392dc8cc474911de91a9b0479ebad6a1406c940bed6c23fd6b35f7eff90959
4
+ data.tar.gz: 8afef4349361c795a119f3560198e71606a2bdda25b6fd9466ab5aef2f52ab8b
5
5
  SHA512:
6
- metadata.gz: 967a4135662b57b39799adb7632d0152e390453e6d3420c52cb873da89e602fde78e5f45ba81ae4e855491d8fe85b006c6bfdd0ad51bf9b16c3ff85e89e5f217
7
- data.tar.gz: a3333ff49a37c7d64462de1c8d712e9e9d7ef49c2e1ae470fec329337ca29de46a57bc3d18e6641d264fbe401561cf4dcafbc3d3282e39136b66a9df969c36b5
6
+ metadata.gz: ac74be71761f3341f3a76f035636b8e4d2693d40206c74c25858ee02f6eba2aad5013f0928cc467c16858c349ff1903074df878b764bdb7244fb75933428a3f5
7
+ data.tar.gz: 944106d0ef3be643b6efbaa14ab94eb1c2a4c337b54809127a798496d624c440ffc648de0de9bd550b7a998435486e8de9fb5c32372e6e6e4af6f82bf61a6ac6
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2023, by Nick Burwell.
5
+
6
+ module Protocol
7
+ module Redis
8
+ module Methods
9
+ module Cluster
10
+ # Sends the `CLUSTER *` command to random node and returns its reply.
11
+ # @see https://redis.io/commands/cluster-addslots/
12
+ # @param subcommand [String, Symbol] the subcommand of cluster command
13
+ # e.g. `:addslots`, `:delslots`, `:nodes`, `:replicas`, `:info`
14
+ #
15
+ # @return [Object] depends on the subcommand provided
16
+ def cluster(subcommand, *args)
17
+ call("CLUSTER", subcommand.to_s, *args)
18
+ end
19
+
20
+ # Sends `ASKING` command to random node and returns its reply.
21
+ # @see https://redis.io/commands/asking/
22
+ #
23
+ # @return [String] `'OK'`
24
+ def asking
25
+ call("ASKING")
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -2,6 +2,8 @@
2
2
 
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2019-2023, by Samuel Williams.
5
+ # Copyright, 2023, by Troex Nevelin.
6
+ # Copyright, 2023, by Nick Burwell.
5
7
 
6
8
  module Protocol
7
9
  module Redis
@@ -10,6 +12,7 @@ module Protocol
10
12
  # Get the number of fields in a hash. O(1).
11
13
  # @see https://redis.io/commands/hlen
12
14
  # @param key [Key]
15
+ # @return [Integer]
13
16
  def hlen(key)
14
17
  call('HLEN', key)
15
18
  end
@@ -17,6 +20,7 @@ module Protocol
17
20
  # 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.
18
21
  # @see https://redis.io/commands/hset
19
22
  # @param key [Key]
23
+ # @return [Integer] if new field added returns "1" otherwise "0"
20
24
  def hset(key, field, value)
21
25
  call('HSET', key, field, value)
22
26
  end
@@ -26,21 +30,39 @@ module Protocol
26
30
  # @param key [Key]
27
31
  # @param field [String]
28
32
  # @param value [String]
33
+ # @return [Boolean] "true" if new field added, "false" otherwise
29
34
  def hsetnx(key, field, value)
30
- call('HSETNX', key, field, value)
35
+ call('HSETNX', key, field, value) > 0
31
36
  end
32
37
 
33
38
  # Set multiple hash fields to multiple values. O(N) where N is the number of fields being set.
34
39
  # @see https://redis.io/commands/hmset
35
40
  # @param key [Key]
41
+ # @return [String] default: "OK"
36
42
  def hmset(key, *attrs)
37
43
  call('HMSET', key, *attrs)
38
44
  end
45
+
46
+ # Set multiple hash fields to multiple values, by providing a hash
47
+ #
48
+ # @example
49
+ # redis.mapped_hmset("hash", { "f1" => "v1", "f2" => "v2" })
50
+ # # => "OK"
51
+ #
52
+ # @param key [Key]
53
+ # @param hash [Hash] a non-empty hash with fields mapping to values
54
+ # @return [String] default: "OK"
55
+ #
56
+ # @see #hmset
57
+ def mapped_hmset(key, hash)
58
+ hmset(key, *hash.flatten)
59
+ end
39
60
 
40
61
  # Get the value of a hash field. O(1).
41
62
  # @see https://redis.io/commands/hget
42
63
  # @param key [Key]
43
64
  # @param field [String]
65
+ # @return [String, Null]
44
66
  def hget(key, field)
45
67
  call('HGET', key, field)
46
68
  end
@@ -48,15 +70,33 @@ module Protocol
48
70
  # Get the values of all the given hash fields. O(N) where N is the number of fields being requested.
49
71
  # @see https://redis.io/commands/hmget
50
72
  # @param key [Key]
51
- # @param field [String]
52
- def hmget(key, *fields, &blk)
53
- call('HMGET', key, *fields, &blk)
73
+ # @param fields [Array<String>] array of fields
74
+ # @return [Array]
75
+ def hmget(key, *fields)
76
+ call('HMGET', key, *fields)
54
77
  end
55
-
78
+
79
+ # Get the values of all the given hash fields and return as array
80
+ #
81
+ # @example
82
+ # redis.mapped_hmget("hash", "f1", "f2")
83
+ # # => { "f1" => "v1", "f2" => "v2" }
84
+ #
85
+ # @param key [Key]
86
+ # @param fields [Array<String>] array of fields
87
+ # @return [Hash] a hash mapping the specified fields to their values
88
+ #
89
+ # @see #hmget
90
+ def mapped_hmget(key, *fields)
91
+ reply = hmget(key, *fields)
92
+ Hash[fields.zip(reply)]
93
+ end
94
+
56
95
  # Delete one or more hash fields. O(N) where N is the number of fields to be removed.
57
96
  # @see https://redis.io/commands/hdel
58
97
  # @param key [Key]
59
98
  # @param field [String]
99
+ # @return [Integer] number of deleted fields
60
100
  def hdel(key, *fields)
61
101
  call('HDEL', key, *fields)
62
102
  end
@@ -65,8 +105,9 @@ module Protocol
65
105
  # @see https://redis.io/commands/hexists
66
106
  # @param key [Key]
67
107
  # @param field [String]
108
+ # @return [Boolean]
68
109
  def hexists(key, field)
69
- call('HEXISTS', key, field)
110
+ call('HEXISTS', key, field) > 0
70
111
  end
71
112
 
72
113
  # Increment the integer value of a hash field by the given number. O(1).
@@ -74,6 +115,7 @@ module Protocol
74
115
  # @param key [Key]
75
116
  # @param field [String]
76
117
  # @param increment [Integer]
118
+ # @return [Integer] field value after increment
77
119
  def hincrby(key, field, increment)
78
120
  call('HINCRBY', key, field, increment)
79
121
  end
@@ -83,13 +125,15 @@ module Protocol
83
125
  # @param key [Key]
84
126
  # @param field [String]
85
127
  # @param increment [Double]
128
+ # @return [Float] field value after increment
86
129
  def hincrbyfloat(key, field, increment)
87
- call('HINCRBYFLOAT', key, field, increment)
130
+ Float(call('HINCRBYFLOAT', key, field, increment))
88
131
  end
89
132
 
90
133
  # Get all the fields in a hash. O(N) where N is the size of the hash.
91
134
  # @see https://redis.io/commands/hkeys
92
135
  # @param key [Key]
136
+ # @return [Array]
93
137
  def hkeys(key)
94
138
  call('HKEYS', key)
95
139
  end
@@ -97,6 +141,7 @@ module Protocol
97
141
  # Get all the values in a hash. O(N) where N is the size of the hash.
98
142
  # @see https://redis.io/commands/hvals
99
143
  # @param key [Key]
144
+ # @return [Array]
100
145
  def hvals(key)
101
146
  call('HVALS', key)
102
147
  end
@@ -104,8 +149,27 @@ module Protocol
104
149
  # Get all the fields and values in a hash. O(N) where N is the size of the hash.
105
150
  # @see https://redis.io/commands/hgetall
106
151
  # @param key [Key]
152
+ # @return [Hash]
107
153
  def hgetall(key)
108
- call('HGETALL', key)
154
+ call('HGETALL', key).each_slice(2).to_h
155
+ end
156
+
157
+ # 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
+ # @see https://redis.io/commands/hscan/
159
+ # @param cursor [Cursor]
160
+ # @return [Hash]
161
+ def hscan(cursor, match: nil, count: nil)
162
+ arguments = [cursor]
163
+
164
+ if match
165
+ arguments.append("MATCH", match)
166
+ end
167
+
168
+ if count
169
+ arguments.append("COUNT", count)
170
+ end
171
+
172
+ call("HSCAN", *arguments)
109
173
  end
110
174
  end
111
175
  end
@@ -9,6 +9,7 @@
9
9
  require_relative 'methods/generic'
10
10
  require_relative 'methods/connection'
11
11
  require_relative 'methods/server'
12
+ require_relative 'methods/cluster'
12
13
  require_relative 'methods/geospatial'
13
14
 
14
15
  require_relative 'methods/counting'
@@ -30,6 +31,7 @@ module Protocol
30
31
  klass.include Methods::Generic
31
32
  klass.include Methods::Connection
32
33
  klass.include Methods::Server
34
+ klass.include Methods::Cluster
33
35
  klass.include Methods::Geospatial
34
36
 
35
37
  klass.include Methods::Counting
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module Redis
8
- VERSION = "0.7.0"
8
+ VERSION = "0.8.0"
9
9
  end
10
10
  end
data/license.md CHANGED
@@ -6,7 +6,7 @@ Copyright, 2020, by Salim Semaoune.
6
6
  Copyright, 2020, by Dimitry Chopey.
7
7
  Copyright, 2020, by Nakul Warrier.
8
8
  Copyright, 2020, by David Ortiz.
9
- Copyright, 2021, by Troex Nevelin.
9
+ Copyright, 2021-2023, by Troex Nevelin.
10
10
  Copyright, 2021, by Daniel Evans.
11
11
  Copyright, 2023, by Nick Burwell.
12
12
 
data/readme.md CHANGED
@@ -33,6 +33,12 @@ puts server.read_object
33
33
  # => "Hello World!"
34
34
  ```
35
35
 
36
+ ## Development
37
+
38
+ Run tests:
39
+
40
+ bundle exec bake test
41
+
36
42
  ## Contributing
37
43
 
38
44
  We welcome contributions to this project.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  - Dimitry Chopey
9
+ - Nick Burwell
9
10
  - David Ortiz
10
11
  - Nakul Warrier
12
+ - Troex Nevelin
11
13
  - Daniel Evans
12
- - Nick Burwell
13
14
  - Olle Jonsson
14
15
  - Salim Semaoune
15
- - Troex Nevelin
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain:
@@ -45,134 +45,8 @@ cert_chain:
45
45
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
46
46
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
47
47
  -----END CERTIFICATE-----
48
- date: 2023-06-03 00:00:00.000000000 Z
49
- dependencies:
50
- - !ruby/object:Gem::Dependency
51
- name: async-http
52
- requirement: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: '0'
57
- type: :development
58
- prerelease: false
59
- version_requirements: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: '0'
64
- - !ruby/object:Gem::Dependency
65
- name: bake
66
- requirement: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- version: '0'
71
- type: :development
72
- prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: bake-bundler
80
- requirement: !ruby/object:Gem::Requirement
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- version: '0'
85
- type: :development
86
- prerelease: false
87
- version_requirements: !ruby/object:Gem::Requirement
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: '0'
92
- - !ruby/object:Gem::Dependency
93
- name: bake-modernize
94
- requirement: !ruby/object:Gem::Requirement
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- version: '0'
99
- type: :development
100
- prerelease: false
101
- version_requirements: !ruby/object:Gem::Requirement
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- version: '0'
106
- - !ruby/object:Gem::Dependency
107
- name: benchmark-ips
108
- requirement: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: '0'
113
- type: :development
114
- prerelease: false
115
- version_requirements: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- version: '0'
120
- - !ruby/object:Gem::Dependency
121
- name: bundler
122
- requirement: !ruby/object:Gem::Requirement
123
- requirements:
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- version: '0'
127
- type: :development
128
- prerelease: false
129
- version_requirements: !ruby/object:Gem::Requirement
130
- requirements:
131
- - - ">="
132
- - !ruby/object:Gem::Version
133
- version: '0'
134
- - !ruby/object:Gem::Dependency
135
- name: covered
136
- requirement: !ruby/object:Gem::Requirement
137
- requirements:
138
- - - ">="
139
- - !ruby/object:Gem::Version
140
- version: '0'
141
- type: :development
142
- prerelease: false
143
- version_requirements: !ruby/object:Gem::Requirement
144
- requirements:
145
- - - ">="
146
- - !ruby/object:Gem::Version
147
- version: '0'
148
- - !ruby/object:Gem::Dependency
149
- name: sus
150
- requirement: !ruby/object:Gem::Requirement
151
- requirements:
152
- - - ">="
153
- - !ruby/object:Gem::Version
154
- version: '0'
155
- type: :development
156
- prerelease: false
157
- version_requirements: !ruby/object:Gem::Requirement
158
- requirements:
159
- - - ">="
160
- - !ruby/object:Gem::Version
161
- version: '0'
162
- - !ruby/object:Gem::Dependency
163
- name: trenni
164
- requirement: !ruby/object:Gem::Requirement
165
- requirements:
166
- - - ">="
167
- - !ruby/object:Gem::Version
168
- version: '0'
169
- type: :development
170
- prerelease: false
171
- version_requirements: !ruby/object:Gem::Requirement
172
- requirements:
173
- - - ">="
174
- - !ruby/object:Gem::Version
175
- version: '0'
48
+ date: 2023-06-13 00:00:00.000000000 Z
49
+ dependencies: []
176
50
  description:
177
51
  email:
178
52
  executables: []
@@ -183,6 +57,7 @@ files:
183
57
  - lib/protocol/redis/connection.rb
184
58
  - lib/protocol/redis/error.rb
185
59
  - lib/protocol/redis/methods.rb
60
+ - lib/protocol/redis/methods/cluster.rb
186
61
  - lib/protocol/redis/methods/connection.rb
187
62
  - lib/protocol/redis/methods/counting.rb
188
63
  - lib/protocol/redis/methods/generic.rb
@@ -212,14 +87,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
212
87
  requirements:
213
88
  - - ">="
214
89
  - !ruby/object:Gem::Version
215
- version: '2.5'
90
+ version: '2.7'
216
91
  required_rubygems_version: !ruby/object:Gem::Requirement
217
92
  requirements:
218
93
  - - ">="
219
94
  - !ruby/object:Gem::Version
220
95
  version: '0'
221
96
  requirements: []
222
- rubygems_version: 3.4.7
97
+ rubygems_version: 3.2.33
223
98
  signing_key:
224
99
  specification_version: 4
225
100
  summary: A transport agnostic RESP protocol client/server.
metadata.gz.sig CHANGED
Binary file