protocol-redis 0.5.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/redis/connection.rb +2 -19
- data/lib/protocol/redis/error.rb +2 -19
- data/lib/protocol/redis/methods/cluster.rb +30 -0
- data/lib/protocol/redis/methods/connection.rb +6 -22
- data/lib/protocol/redis/methods/counting.rb +2 -19
- data/lib/protocol/redis/methods/generic.rb +11 -20
- data/lib/protocol/redis/methods/geospatial.rb +2 -19
- data/lib/protocol/redis/methods/hashes.rb +74 -27
- data/lib/protocol/redis/methods/lists.rb +3 -20
- data/lib/protocol/redis/methods/pubsub.rb +20 -0
- data/lib/protocol/redis/methods/scripting.rb +10 -51
- data/lib/protocol/redis/methods/server.rb +4 -21
- data/lib/protocol/redis/methods/sets.rb +2 -19
- data/lib/protocol/redis/methods/sorted_sets.rb +2 -19
- data/lib/protocol/redis/methods/streams.rb +2 -19
- data/lib/protocol/redis/methods/strings.rb +2 -20
- data/lib/protocol/redis/methods.rb +18 -20
- data/lib/protocol/redis/version.rb +3 -20
- data/lib/protocol/redis.rb +2 -19
- data/license.md +29 -0
- data/readme.md +50 -0
- data.tar.gz.sig +0 -0
- metadata +55 -124
- metadata.gz.sig +0 -0
- data/.editorconfig +0 -6
- data/.github/workflows/development.yml +0 -34
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/Gemfile +0 -10
- data/README.md +0 -67
- data/Rakefile +0 -10
- data/benchmark/call.rb +0 -55
- data/protocol-redis.gemspec +0 -27
- data/tasks/generate.rake +0 -174
- data/tasks/methods.trenni +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7392dc8cc474911de91a9b0479ebad6a1406c940bed6c23fd6b35f7eff90959
|
4
|
+
data.tar.gz: 8afef4349361c795a119f3560198e71606a2bdda25b6fd9466ab5aef2f52ab8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac74be71761f3341f3a76f035636b8e4d2693d40206c74c25858ee02f6eba2aad5013f0928cc467c16858c349ff1903074df878b764bdb7244fb75933428a3f5
|
7
|
+
data.tar.gz: 944106d0ef3be643b6efbaa14ab94eb1c2a4c337b54809127a798496d624c440ffc648de0de9bd550b7a998435486e8de9fb5c32372e6e6e4af6f82bf61a6ac6
|
checksums.yaml.gz.sig
ADDED
Binary file
|
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
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.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
22
5
|
|
23
6
|
require_relative 'error'
|
24
7
|
|
data/lib/protocol/redis/error.rb
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
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.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
22
5
|
|
23
6
|
module Protocol
|
24
7
|
module Redis
|
@@ -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
|
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
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.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
22
5
|
|
23
6
|
module Protocol
|
24
7
|
module Redis
|
@@ -26,9 +9,10 @@ module Protocol
|
|
26
9
|
module Connection
|
27
10
|
# Authenticate to the server.
|
28
11
|
# @see https://redis.io/commands/auth
|
29
|
-
# @param
|
30
|
-
|
31
|
-
|
12
|
+
# @param username [String] Optional username, if Redis ACLs are used.
|
13
|
+
# @param password [String] Required password.
|
14
|
+
def auth(*arguments)
|
15
|
+
call("AUTH", *arguments)
|
32
16
|
end
|
33
17
|
|
34
18
|
# Echo the given string.
|
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
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.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
22
5
|
|
23
6
|
module Protocol
|
24
7
|
module Redis
|
@@ -1,25 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
# Copyright,
|
5
|
-
#
|
6
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
-
# of this software and associated documentation files (the "Software"), to deal
|
8
|
-
# in the Software without restriction, including without limitation the rights
|
9
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
-
# copies of the Software, and to permit persons to whom the Software is
|
11
|
-
# furnished to do so, subject to the following conditions:
|
12
|
-
#
|
13
|
-
# The above copyright notice and this permission notice shall be included in
|
14
|
-
# all copies or substantial portions of the Software.
|
15
|
-
#
|
16
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
-
# THE SOFTWARE.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
5
|
+
# Copyright, 2021, by Troex Nevelin.
|
23
6
|
|
24
7
|
require 'date'
|
25
8
|
|
@@ -46,10 +29,18 @@ module Protocol
|
|
46
29
|
# Determine if a key exists. O(1).
|
47
30
|
# @see https://redis.io/commands/exists
|
48
31
|
# @param key [Key]
|
32
|
+
# @return [Integer]
|
49
33
|
def exists(key, *keys)
|
50
34
|
call('EXISTS', key, *keys)
|
51
35
|
end
|
52
36
|
|
37
|
+
# Boolean oversion of `exists`
|
38
|
+
# @param key [Key]
|
39
|
+
# @return [Boolean]
|
40
|
+
def exists?(key, *keys)
|
41
|
+
exists(key, *keys) > 0
|
42
|
+
end
|
43
|
+
|
53
44
|
# Set a key's time to live in seconds. O(1).
|
54
45
|
# @see https://redis.io/commands/expire
|
55
46
|
# @param key [Key]
|
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
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.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
22
5
|
|
23
6
|
module Protocol
|
24
7
|
module Redis
|
@@ -1,24 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
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.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
5
|
+
# Copyright, 2023, by Troex Nevelin.
|
6
|
+
# Copyright, 2023, by Nick Burwell.
|
22
7
|
|
23
8
|
module Protocol
|
24
9
|
module Redis
|
@@ -27,6 +12,7 @@ module Protocol
|
|
27
12
|
# Get the number of fields in a hash. O(1).
|
28
13
|
# @see https://redis.io/commands/hlen
|
29
14
|
# @param key [Key]
|
15
|
+
# @return [Integer]
|
30
16
|
def hlen(key)
|
31
17
|
call('HLEN', key)
|
32
18
|
end
|
@@ -34,6 +20,7 @@ module Protocol
|
|
34
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.
|
35
21
|
# @see https://redis.io/commands/hset
|
36
22
|
# @param key [Key]
|
23
|
+
# @return [Integer] if new field added returns "1" otherwise "0"
|
37
24
|
def hset(key, field, value)
|
38
25
|
call('HSET', key, field, value)
|
39
26
|
end
|
@@ -43,21 +30,39 @@ module Protocol
|
|
43
30
|
# @param key [Key]
|
44
31
|
# @param field [String]
|
45
32
|
# @param value [String]
|
33
|
+
# @return [Boolean] "true" if new field added, "false" otherwise
|
46
34
|
def hsetnx(key, field, value)
|
47
|
-
call('HSETNX', key, field, value)
|
35
|
+
call('HSETNX', key, field, value) > 0
|
48
36
|
end
|
49
37
|
|
50
38
|
# Set multiple hash fields to multiple values. O(N) where N is the number of fields being set.
|
51
39
|
# @see https://redis.io/commands/hmset
|
52
40
|
# @param key [Key]
|
41
|
+
# @return [String] default: "OK"
|
53
42
|
def hmset(key, *attrs)
|
54
43
|
call('HMSET', key, *attrs)
|
55
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
|
56
60
|
|
57
61
|
# Get the value of a hash field. O(1).
|
58
62
|
# @see https://redis.io/commands/hget
|
59
63
|
# @param key [Key]
|
60
64
|
# @param field [String]
|
65
|
+
# @return [String, Null]
|
61
66
|
def hget(key, field)
|
62
67
|
call('HGET', key, field)
|
63
68
|
end
|
@@ -65,15 +70,33 @@ module Protocol
|
|
65
70
|
# Get the values of all the given hash fields. O(N) where N is the number of fields being requested.
|
66
71
|
# @see https://redis.io/commands/hmget
|
67
72
|
# @param key [Key]
|
68
|
-
# @param
|
69
|
-
|
70
|
-
|
73
|
+
# @param fields [Array<String>] array of fields
|
74
|
+
# @return [Array]
|
75
|
+
def hmget(key, *fields)
|
76
|
+
call('HMGET', key, *fields)
|
71
77
|
end
|
72
|
-
|
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
|
+
|
73
95
|
# Delete one or more hash fields. O(N) where N is the number of fields to be removed.
|
74
96
|
# @see https://redis.io/commands/hdel
|
75
97
|
# @param key [Key]
|
76
98
|
# @param field [String]
|
99
|
+
# @return [Integer] number of deleted fields
|
77
100
|
def hdel(key, *fields)
|
78
101
|
call('HDEL', key, *fields)
|
79
102
|
end
|
@@ -82,8 +105,9 @@ module Protocol
|
|
82
105
|
# @see https://redis.io/commands/hexists
|
83
106
|
# @param key [Key]
|
84
107
|
# @param field [String]
|
108
|
+
# @return [Boolean]
|
85
109
|
def hexists(key, field)
|
86
|
-
call('HEXISTS', key, field)
|
110
|
+
call('HEXISTS', key, field) > 0
|
87
111
|
end
|
88
112
|
|
89
113
|
# Increment the integer value of a hash field by the given number. O(1).
|
@@ -91,6 +115,7 @@ module Protocol
|
|
91
115
|
# @param key [Key]
|
92
116
|
# @param field [String]
|
93
117
|
# @param increment [Integer]
|
118
|
+
# @return [Integer] field value after increment
|
94
119
|
def hincrby(key, field, increment)
|
95
120
|
call('HINCRBY', key, field, increment)
|
96
121
|
end
|
@@ -100,13 +125,15 @@ module Protocol
|
|
100
125
|
# @param key [Key]
|
101
126
|
# @param field [String]
|
102
127
|
# @param increment [Double]
|
128
|
+
# @return [Float] field value after increment
|
103
129
|
def hincrbyfloat(key, field, increment)
|
104
|
-
call('HINCRBYFLOAT', key, field, increment)
|
130
|
+
Float(call('HINCRBYFLOAT', key, field, increment))
|
105
131
|
end
|
106
132
|
|
107
133
|
# Get all the fields in a hash. O(N) where N is the size of the hash.
|
108
134
|
# @see https://redis.io/commands/hkeys
|
109
135
|
# @param key [Key]
|
136
|
+
# @return [Array]
|
110
137
|
def hkeys(key)
|
111
138
|
call('HKEYS', key)
|
112
139
|
end
|
@@ -114,6 +141,7 @@ module Protocol
|
|
114
141
|
# Get all the values in a hash. O(N) where N is the size of the hash.
|
115
142
|
# @see https://redis.io/commands/hvals
|
116
143
|
# @param key [Key]
|
144
|
+
# @return [Array]
|
117
145
|
def hvals(key)
|
118
146
|
call('HVALS', key)
|
119
147
|
end
|
@@ -121,8 +149,27 @@ module Protocol
|
|
121
149
|
# Get all the fields and values in a hash. O(N) where N is the size of the hash.
|
122
150
|
# @see https://redis.io/commands/hgetall
|
123
151
|
# @param key [Key]
|
152
|
+
# @return [Hash]
|
124
153
|
def hgetall(key)
|
125
|
-
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)
|
126
173
|
end
|
127
174
|
end
|
128
175
|
end
|
@@ -1,25 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
# Copyright,
|
5
|
-
#
|
6
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
-
# of this software and associated documentation files (the "Software"), to deal
|
8
|
-
# in the Software without restriction, including without limitation the rights
|
9
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
-
# copies of the Software, and to permit persons to whom the Software is
|
11
|
-
# furnished to do so, subject to the following conditions:
|
12
|
-
#
|
13
|
-
# The above copyright notice and this permission notice shall be included in
|
14
|
-
# all copies or substantial portions of the Software.
|
15
|
-
#
|
16
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
-
# THE SOFTWARE.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
5
|
+
# Copyright, 2020, by Salim Semaoune.
|
23
6
|
|
24
7
|
module Protocol
|
25
8
|
module Redis
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2020-2023, by Samuel Williams.
|
5
|
+
|
6
|
+
module Protocol
|
7
|
+
module Redis
|
8
|
+
module Methods
|
9
|
+
module Pubsub
|
10
|
+
# Post a message to a channel.
|
11
|
+
# @see https://redis.io/commands/publish
|
12
|
+
# @param channel [String]
|
13
|
+
# @param message [String]
|
14
|
+
def publish(channel, message)
|
15
|
+
call('PUBLISH', channel, message)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,24 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
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.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2020-2023, by Samuel Williams.
|
5
|
+
# Copyright, 2023, by Nick Burwell.
|
22
6
|
|
23
7
|
module Protocol
|
24
8
|
module Redis
|
@@ -28,7 +12,7 @@ module Protocol
|
|
28
12
|
# @see https://redis.io/commands/eval
|
29
13
|
# @param script [String]
|
30
14
|
# @param numkeys [Integer]
|
31
|
-
# @param key [Key]
|
15
|
+
# @param key [Key] Multiple keys are supported, as long as the same number of values are also provided
|
32
16
|
# @param arg [String]
|
33
17
|
def eval(*arguments)
|
34
18
|
call("EVAL", *arguments)
|
@@ -44,37 +28,12 @@ module Protocol
|
|
44
28
|
call("EVALSHA", *arguments)
|
45
29
|
end
|
46
30
|
|
47
|
-
#
|
48
|
-
# @see https://redis.io/commands/script
|
49
|
-
# @param
|
50
|
-
|
51
|
-
|
52
|
-
|
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)
|
31
|
+
# Execute script management commands
|
32
|
+
# @see https://redis.io/commands/script/
|
33
|
+
# @param subcommand [String] e.g. `debug`, `exists`, `flush`, `load`, `kill`
|
34
|
+
# @param [Array<String>] args depends on the subcommand provided
|
35
|
+
def script(subcommand, *arguments)
|
36
|
+
call("SCRIPT", subcommand.to_s, *arguments)
|
78
37
|
end
|
79
38
|
end
|
80
39
|
end
|
@@ -1,25 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
# Copyright,
|
5
|
-
#
|
6
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
-
# of this software and associated documentation files (the "Software"), to deal
|
8
|
-
# in the Software without restriction, including without limitation the rights
|
9
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
-
# copies of the Software, and to permit persons to whom the Software is
|
11
|
-
# furnished to do so, subject to the following conditions:
|
12
|
-
#
|
13
|
-
# The above copyright notice and this permission notice shall be included in
|
14
|
-
# all copies or substantial portions of the Software.
|
15
|
-
#
|
16
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
-
# THE SOFTWARE.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
5
|
+
# Copyright, 2020, by David Ortiz.
|
23
6
|
|
24
7
|
module Protocol
|
25
8
|
module Redis
|
@@ -31,7 +14,7 @@ module Protocol
|
|
31
14
|
def info
|
32
15
|
metadata = {}
|
33
16
|
|
34
|
-
call('INFO').each_line(
|
17
|
+
call('INFO').each_line(Redis::Connection::CRLF) do |line|
|
35
18
|
key, value = line.split(':')
|
36
19
|
|
37
20
|
if value
|
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
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.
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2020-2023, by Samuel Williams.
|
22
5
|
|
23
6
|
module Protocol
|
24
7
|
module Redis
|
@@ -1,25 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
3
|
+
# Released under the MIT License.
|
4
4
|
# Copyright, 2020, by Dimitry Chopey.
|
5
|
-
#
|
6
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
-
# of this software and associated documentation files (the "Software"), to deal
|
8
|
-
# in the Software without restriction, including without limitation the rights
|
9
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
-
# copies of the Software, and to permit persons to whom the Software is
|
11
|
-
# furnished to do so, subject to the following conditions:
|
12
|
-
#
|
13
|
-
# The above copyright notice and this permission notice shall be included in
|
14
|
-
# all copies or substantial portions of the Software.
|
15
|
-
#
|
16
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
-
# THE SOFTWARE.
|
5
|
+
# Copyright, 2020-2023, by Samuel Williams.
|
23
6
|
|
24
7
|
module Protocol
|
25
8
|
module Redis
|