oxblood 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +18 -23
- data/lib/oxblood/commands.rb +4 -0
- data/lib/oxblood/commands/geo.rb +169 -0
- data/lib/oxblood/commands/scripting.rb +102 -0
- data/lib/oxblood/commands/server.rb +287 -4
- data/lib/oxblood/pipeline.rb +1 -1
- data/lib/oxblood/pool.rb +1 -1
- data/lib/oxblood/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1233a81cff6072fcb573bdc595b996d499f2a414
|
4
|
+
data.tar.gz: 7b3c679039d0bf18efa45c7e6d01e8de01ba88ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bf913dab69bd847ef4397b40a64b8adab77b4d60a35f6df6b7262f6fd46a3360cf9882cf60e9c8e27415ed29c4710fc977d011336c2c98690f672515f341962
|
7
|
+
data.tar.gz: ceb1eb09ebe2d64fd450dd189edad55e9646cef731829339f62ca27dd11656e0efbc410fd6c768c4013cd7c9057baf7e07accc5f507718bb824e9870bc703075
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 0.3.0 (2017-04-02)
|
2
|
+
* [#26](https://github.com/etehtsea/oxblood/issues/26):
|
3
|
+
Added server commands support - [@etehtsea](https://github.com/etehtsea)
|
4
|
+
* [#21](https://github.com/etehtsea/oxblood/issues/21):
|
5
|
+
Added geo commands support - [@etehtsea](https://github.com/etehtsea)
|
6
|
+
* [#22](https://github.com/etehtsea/oxblood/issues/22):
|
7
|
+
Added scripting commands support - [@etehtsea](https://github.com/etehtsea)
|
8
|
+
|
1
9
|
## 0.2.0 (2017-01-18)
|
2
10
|
* [#13](https://github.com/etehtsea/oxblood/issues/13):
|
3
11
|
Added support for ZRANGEBYLEX/ZREMRANGEBYLEX/ZREVRANGEBYLEX - [@etehtsea](https://github.com/etehtsea)
|
data/README.md
CHANGED
@@ -12,32 +12,33 @@ A straightforward Redis Ruby client.
|
|
12
12
|
- Ruby 2.2.2+
|
13
13
|
- JRuby 9k+
|
14
14
|
|
15
|
-
##
|
15
|
+
## Usage
|
16
|
+
As a starting point please look at [Oxblood::Pool](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Pool) documentation.
|
17
|
+
|
18
|
+
## Documentation
|
19
|
+
Documentation and usage examples are available on [Rubydoc](http://rubydoc.info/github/etehtsea/oxblood/master/frames).
|
16
20
|
|
17
|
-
-
|
18
|
-
|
21
|
+
- [Pipelining](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Pipeline)
|
22
|
+
- [Connection pooling](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Pool)
|
23
|
+
- [Connection resiliency](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/RSocket)
|
24
|
+
- Commands groups:
|
25
|
+
- Cluster
|
19
26
|
- [Connection](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Connection)
|
20
|
-
- Geo
|
27
|
+
- [Geo](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Geo)
|
21
28
|
- [Hashes](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Hashes)
|
22
29
|
- [HyperLogLog](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/HyperLogLog)
|
23
|
-
- [Keys](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Keys)
|
30
|
+
- [Keys](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Keys)
|
24
31
|
- [Lists](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Lists)
|
25
|
-
- Pub/Sub
|
26
|
-
- Scripting
|
27
|
-
- [Server](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Server)
|
32
|
+
- Pub/Sub
|
33
|
+
- [Scripting](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Scripting)
|
34
|
+
- [Server](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Server)
|
28
35
|
- [Sets](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Sets)
|
29
36
|
- [Sorted Sets](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/SortedSets)
|
30
|
-
- [Strings](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Strings)
|
37
|
+
- [Strings](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Strings)
|
31
38
|
- [Transactions](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Commands/Transactions)
|
32
|
-
- [Pipeling](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Pipeline)
|
33
|
-
- [Connection pooling](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Pool)
|
34
|
-
- [Connection resiliency](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/RSocket)
|
35
39
|
|
36
|
-
##
|
37
|
-
|
38
|
-
|
39
|
-
## Documentation
|
40
|
-
Documentation and usage examples are available on [Rubydoc](http://rubydoc.info/github/etehtsea/oxblood/master/frames).
|
40
|
+
## Performance
|
41
|
+
Available benchmark results are available [here](https://github.com/etehtsea/oxblood/wiki/Performance).
|
41
42
|
|
42
43
|
## Continuous Integration
|
43
44
|
You can check CI status at [Travis CI](https://travis-ci.org/etehtsea/oxblood).
|
@@ -47,9 +48,3 @@ Bug reports and pull requests are welcome on [GitHub](https://github.com/etehtse
|
|
47
48
|
|
48
49
|
## License
|
49
50
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
50
|
-
|
51
|
-
[#4]: https://github.com/etehtsea/oxblood/issues/4
|
52
|
-
[#6]: https://github.com/etehtsea/oxblood/issues/6
|
53
|
-
[#7]: https://github.com/etehtsea/oxblood/issues/7
|
54
|
-
[#16]: https://github.com/etehtsea/oxblood/issues/16
|
55
|
-
[#19]: https://github.com/etehtsea/oxblood/issues/19
|
data/lib/oxblood/commands.rb
CHANGED
@@ -2,10 +2,12 @@ require 'oxblood/commands/hashes'
|
|
2
2
|
require 'oxblood/commands/hyper_log_log'
|
3
3
|
require 'oxblood/commands/strings'
|
4
4
|
require 'oxblood/commands/connection'
|
5
|
+
require 'oxblood/commands/geo'
|
5
6
|
require 'oxblood/commands/server'
|
6
7
|
require 'oxblood/commands/keys'
|
7
8
|
require 'oxblood/commands/lists'
|
8
9
|
require 'oxblood/commands/sets'
|
10
|
+
require 'oxblood/commands/scripting'
|
9
11
|
require 'oxblood/commands/sorted_sets'
|
10
12
|
require 'oxblood/commands/transactions'
|
11
13
|
|
@@ -15,10 +17,12 @@ module Oxblood
|
|
15
17
|
include HyperLogLog
|
16
18
|
include Strings
|
17
19
|
include Connection
|
20
|
+
include Geo
|
18
21
|
include Server
|
19
22
|
include Keys
|
20
23
|
include Lists
|
21
24
|
include Sets
|
25
|
+
include Scripting
|
22
26
|
include SortedSets
|
23
27
|
include Transactions
|
24
28
|
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
module Oxblood
|
2
|
+
module Commands
|
3
|
+
module Geo
|
4
|
+
# Add one or more geospatial items in the geospatial index represented
|
5
|
+
# using a sorted set.
|
6
|
+
# @see https://redis.io/commands/geoadd
|
7
|
+
#
|
8
|
+
# @param [String] key
|
9
|
+
# @param [Array<[String, String, String]>] items
|
10
|
+
# Geospatial items (longitude, latitude, member)
|
11
|
+
#
|
12
|
+
# @return [Integer] The number of elements added to the sorted set,
|
13
|
+
# not including elements already existing for which the score was updated.
|
14
|
+
def geoadd(key, *items)
|
15
|
+
run(*items.unshift(:GEOADD, key))
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns members of a geospatial index as standard geohash strings.
|
19
|
+
# @see https://redis.io/commands/geohash
|
20
|
+
#
|
21
|
+
# @param [String] key
|
22
|
+
# @param [String, Array<String>] members
|
23
|
+
#
|
24
|
+
# @return [Array] The command returns an array where each element is
|
25
|
+
# the Geohash corresponding to each member name passed as argument to the command.
|
26
|
+
def geohash(key, *members)
|
27
|
+
run(*members.unshift(:GEOHASH, key))
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns longitude and latitude of members of a geospatial index.
|
31
|
+
# @see https://redis.io/commands/geopos
|
32
|
+
#
|
33
|
+
# @param [String] key
|
34
|
+
# @param [String, Array<String>] members
|
35
|
+
#
|
36
|
+
# @return [Array] an array where each element is a two elements array
|
37
|
+
# representing longitude and latitude (x,y) of each member name passed
|
38
|
+
# as argument to the command.
|
39
|
+
# Non existing elements are reported as `nil` elements of the array.
|
40
|
+
def geopos(key, *members)
|
41
|
+
run(*members.unshift(:GEOPOS, key))
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns the distance between two members of a geospatial index.
|
45
|
+
# @see https://redis.io/commands/geodist
|
46
|
+
#
|
47
|
+
# @param [String] key
|
48
|
+
# @param [String] member1 name of geospatial index member
|
49
|
+
# @param [String] member2 name of geospatial index member
|
50
|
+
# @param [nil, String] unit that could be one of the following and
|
51
|
+
# defaults to meters: m (meters), km (kilometers), mi (miles), ft (feet).
|
52
|
+
#
|
53
|
+
# @return [nil, String] The command returns the distance as a double
|
54
|
+
# (represented as a string) in the specified unit, or nil if one or
|
55
|
+
# both elements are missing.
|
56
|
+
def geodist(key, member1, member2, unit = nil)
|
57
|
+
if unit
|
58
|
+
run(:GEODIST, key, member1, member2, unit)
|
59
|
+
else
|
60
|
+
run(:GEODIST, key, member1, member2)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Query a sorted set representing a geospatial index to fetch members
|
65
|
+
# matching a given maximum distance from a point.
|
66
|
+
# @see https://redis.io/commands/georadius
|
67
|
+
#
|
68
|
+
# @param [String] key
|
69
|
+
# @param [String] longitude
|
70
|
+
# @param [String] latitude
|
71
|
+
# @param [Integer] radius
|
72
|
+
# @param [Symbol] unit that could be one of the following and defaults to
|
73
|
+
# meters: m (meters), km (kilometers), mi (miles), ft (feet).
|
74
|
+
# @param [Hash] opts
|
75
|
+
#
|
76
|
+
# @option opts [Boolean] :withcoord Also return the longitude, latitude
|
77
|
+
# coordinates of the matching items.
|
78
|
+
# @option opts [Boolean] :withdist Also return the distance of
|
79
|
+
# the returned items from the specified center. The distance is returned
|
80
|
+
# in the same unit as the unit specified as the radius argument of
|
81
|
+
# the command.
|
82
|
+
# @option opts [Boolean] :withhash Also return the raw geohash-encoded
|
83
|
+
# sorted set score of the item, in the form of a 52 bit unsigned integer.
|
84
|
+
# This is only useful for low level hacks or debugging and is otherwise
|
85
|
+
# of little interest for the general user.
|
86
|
+
# @option opts [Symbol] :order The command default is to return unsorted
|
87
|
+
# items. Two different sorting methods can be invoked using the following
|
88
|
+
# two options:
|
89
|
+
# - ASC: from the nearest to the farthest, relative to the center.
|
90
|
+
# - DESC: from the farthest to the nearest, relative to the center.
|
91
|
+
# @option opts [Integer] :count limit the results to the first N matching items.
|
92
|
+
# @option opts [String] :store generates a valid geo index and stores
|
93
|
+
# result to key
|
94
|
+
# @option opts [String] :storedist stores calculated distances to key.
|
95
|
+
#
|
96
|
+
# @return [Array] See https://redis.io/commands/georadius#return-value
|
97
|
+
# @return [Integer] if STORE or STOREDIST option was used
|
98
|
+
def georadius(key, longitude, latitude, radius, unit, opts = {})
|
99
|
+
args = [:GEORADIUS, key, longitude, latitude, radius, unit]
|
100
|
+
add_georadius_opts!(args, opts)
|
101
|
+
run(*args)
|
102
|
+
end
|
103
|
+
|
104
|
+
# Query a sorted set representing a geospatial index to fetch members
|
105
|
+
# matching a given maximum distance from a member.
|
106
|
+
# @see https://redis.io/commands/georadiusbymember
|
107
|
+
#
|
108
|
+
# @param [String] key
|
109
|
+
# @param [String] member
|
110
|
+
# @param [Integer] radius
|
111
|
+
# @param [Symbol] unit that could be one of the following and defaults to
|
112
|
+
# meters: m (meters), km (kilometers), mi (miles), ft (feet).
|
113
|
+
# @param [Hash] opts
|
114
|
+
#
|
115
|
+
# @option opts [Boolean] :withcoord Also return the longitude, latitude
|
116
|
+
# coordinates of the matching items.
|
117
|
+
# @option opts [Boolean] :withdist Also return the distance of
|
118
|
+
# the returned items from the specified center. The distance is returned
|
119
|
+
# in the same unit as the unit specified as the radius argument of
|
120
|
+
# the command.
|
121
|
+
# @option opts [Boolean] :withhash Also return the raw geohash-encoded
|
122
|
+
# sorted set score of the item, in the form of a 52 bit unsigned integer.
|
123
|
+
# This is only useful for low level hacks or debugging and is otherwise
|
124
|
+
# of little interest for the general user.
|
125
|
+
# @option opts [Symbol] :order The command default is to return unsorted
|
126
|
+
# items. Two different sorting methods can be invoked using the following
|
127
|
+
# two options:
|
128
|
+
# - ASC: from the nearest to the farthest, relative to the center.
|
129
|
+
# - DESC: from the farthest to the nearest, relative to the center.
|
130
|
+
# @option opts [Integer] :count limit the results to the first N matching items.
|
131
|
+
# @option opts [String] :store generates a valid geo index and stores
|
132
|
+
# result to key
|
133
|
+
# @option opts [String] :storedist stores calculated distances to key.
|
134
|
+
#
|
135
|
+
# @return [Array] See https://redis.io/commands/georadius#return-value
|
136
|
+
# @return [Integer] if STORE or STOREDIST option was used
|
137
|
+
def georadiusbymember(key, member, radius, unit, opts = {})
|
138
|
+
args = [:GEORADIUSBYMEMBER, key, member, radius, unit]
|
139
|
+
add_georadius_opts!(args, opts)
|
140
|
+
run(*args)
|
141
|
+
end
|
142
|
+
|
143
|
+
private
|
144
|
+
|
145
|
+
# @note Mutates args argument!
|
146
|
+
def add_georadius_opts!(args, opts)
|
147
|
+
args << :WITHCOORD if opts[:withcoord]
|
148
|
+
args << :WITHDIST if opts[:withdist]
|
149
|
+
args << :WITHHASH if opts[:withhash]
|
150
|
+
|
151
|
+
if order = opts[:order]
|
152
|
+
args << order
|
153
|
+
end
|
154
|
+
|
155
|
+
if count = opts[:count]
|
156
|
+
args.push(:COUNT, count)
|
157
|
+
end
|
158
|
+
|
159
|
+
if store_key = opts[:store]
|
160
|
+
args.push(:STORE, store_key)
|
161
|
+
end
|
162
|
+
|
163
|
+
if storedist_key = opts[:storedist]
|
164
|
+
args.push(:STOREDIST, storedist_key)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'oxblood/commands/scripting'
|
2
|
+
|
3
|
+
module Oxblood
|
4
|
+
module Commands
|
5
|
+
module Scripting
|
6
|
+
# Execute a Lua script server side
|
7
|
+
# @see https://redis.io/commands/eval
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# session.eval("return redis.call('set','foo','bar')", 0)
|
11
|
+
# # => 'OK'
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# session.eval("return redis.call('set',KEYS[1],'bar')", 1, :foo)
|
15
|
+
# # => 'OK'
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
# session.eval("return 10", 0)
|
19
|
+
# # => 10
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
# session.eval("return {1,2,{3,'Hello World!'}}", 0)
|
23
|
+
# # => [1, 2, [3, 'Hello World!']]
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# session.eval("return redis.call('get','foo')", 0)
|
27
|
+
# # => 'bar'
|
28
|
+
#
|
29
|
+
# @example
|
30
|
+
# session.eval("return {1,2,3.3333,'foo',nil,'bar'}", 0)
|
31
|
+
# # => [1, 2, 3, 'foo']
|
32
|
+
#
|
33
|
+
# @param [String] script
|
34
|
+
# @param [Integer] numkeys
|
35
|
+
# @param [String, Array<String>] keys_and_args
|
36
|
+
def eval(script, numkeys, *keys_and_args)
|
37
|
+
run(:EVAL, script, numkeys, keys_and_args)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Execute a Lua script server side
|
41
|
+
# @see https://redis.io/commands/evalsha
|
42
|
+
#
|
43
|
+
# @param [String] sha1
|
44
|
+
# @param [Integer] numkeys
|
45
|
+
# @param [String, Array<String>] keys_and_args
|
46
|
+
def evalsha(sha1, numkeys, *keys_and_args)
|
47
|
+
run(:EVALSHA, sha1, numkeys, keys_and_args)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Set the debug mode for executed scripts.
|
51
|
+
# @see https://redis.io/commands/script-debug
|
52
|
+
#
|
53
|
+
# @param [Symbol] mode
|
54
|
+
#
|
55
|
+
# @return [String] 'OK'
|
56
|
+
# @return [RError] if wrong mode passed
|
57
|
+
def script_debug(mode)
|
58
|
+
run(:SCRIPT, :DEBUG, mode)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Check existence of scripts in the script cache.
|
62
|
+
# @see https://redis.io/commands/script-exists
|
63
|
+
#
|
64
|
+
# @param [String, Array<String>] sha1_digests
|
65
|
+
#
|
66
|
+
# @return [Array<Integer>] For every corresponding SHA1 digest of a script
|
67
|
+
# that actually exists in the script cache, an 1 is returned,
|
68
|
+
# otherwise 0 is returned.
|
69
|
+
def script_exists(*sha1_digests)
|
70
|
+
run(*sha1_digests.unshift(:SCRIPT, :EXISTS))
|
71
|
+
end
|
72
|
+
|
73
|
+
# Remove all the scripts from the script cache.
|
74
|
+
# @see https://redis.io/commands/script-flush
|
75
|
+
#
|
76
|
+
# @return [String] 'OK'
|
77
|
+
def script_flush
|
78
|
+
run(:SCRIPT, :FLUSH)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Kill the script currently in execution.
|
82
|
+
# @see https://redis.io/commands/script-kill
|
83
|
+
#
|
84
|
+
# @return [String] 'OK'
|
85
|
+
# @return [RError] if there is no script to kill
|
86
|
+
def script_kill
|
87
|
+
run(:SCRIPT, :KILL)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Load the specified Lua script into the script cache.
|
91
|
+
# @see https://redis.io/commands/script-load
|
92
|
+
#
|
93
|
+
# @param [String] script
|
94
|
+
#
|
95
|
+
# @return [String] This command returns the SHA1 digest of the script
|
96
|
+
# added into the script cache
|
97
|
+
def script_load(script)
|
98
|
+
run(:SCRIPT, :LOAD, script)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -1,16 +1,211 @@
|
|
1
1
|
module Oxblood
|
2
2
|
module Commands
|
3
3
|
module Server
|
4
|
-
#
|
4
|
+
# Asynchronously rewrite the append-only file.
|
5
|
+
# @see https://redis.io/commands/bgrewriteaof
|
6
|
+
#
|
7
|
+
# @return [String] always 'OK'
|
8
|
+
def bgrewriteaof
|
9
|
+
run(:BGREWRITEAOF)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Asynchronously save the dataset to disk
|
13
|
+
# @see https://redis.io/commands/bgsave
|
14
|
+
#
|
15
|
+
# @return [String] command status message
|
16
|
+
def bgsave
|
17
|
+
run(:BGSAVE)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Get the current conneciton name.
|
21
|
+
# @see https://redis.io/commands/client-getname
|
22
|
+
#
|
23
|
+
# @return [nil, String] client name
|
24
|
+
def client_getname
|
25
|
+
run(:CLIENT, :GETNAME)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Get the list of client connections.
|
29
|
+
# @see https://redis.io/commands/client-list
|
30
|
+
#
|
31
|
+
# @return [String] client list in the formatted string
|
32
|
+
def client_list
|
33
|
+
run(:CLIENT, :LIST)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Kill the connection of a client.
|
37
|
+
# @see https://redis.io/commands/client-kill
|
38
|
+
#
|
39
|
+
# @param [Hash, String] opts_or_addr hash of options or addr in
|
40
|
+
# an addr:port form.
|
41
|
+
#
|
42
|
+
# @option opts_or_addr [Integer] :id unique client ID.
|
43
|
+
# @option opts_or_addr [Symbol] :type Close connections of all the clients
|
44
|
+
# of specified type (for example: `normal`, `master`, `slave`, `pubsub`).
|
45
|
+
# @option opts_or_addr [String] :addr ip:port which matches a line
|
46
|
+
# returned by CLIENT LIST command (addr field).
|
47
|
+
# @option opts_or_addr [Boolean] :skipme Skip client that is calling this
|
48
|
+
# command (enabled by default).
|
49
|
+
#
|
50
|
+
# @return [String] 'OK'
|
51
|
+
# @return [Integer] the number of clients killed when called with
|
52
|
+
# the filter/value format
|
53
|
+
def client_kill(opts_or_addr = {})
|
54
|
+
if opts_or_addr.is_a?(String)
|
55
|
+
run(:CLIENT, :KILL, opts_or_addr)
|
56
|
+
else
|
57
|
+
args = [:CLIENT, :KILL]
|
58
|
+
|
59
|
+
if v = opts_or_addr[:id]
|
60
|
+
args.push(:ID, v)
|
61
|
+
end
|
62
|
+
|
63
|
+
if v = opts_or_addr[:type]
|
64
|
+
args.push(:TYPE, v)
|
65
|
+
end
|
66
|
+
|
67
|
+
if v = opts_or_addr[:addr]
|
68
|
+
args.push(:ADDR, v)
|
69
|
+
end
|
70
|
+
|
71
|
+
if opts_or_addr.key?(:skipme)
|
72
|
+
case opts_or_addr[:skipme]
|
73
|
+
when false, 'no'.freeze
|
74
|
+
args.push(:SKIPME, 'no'.freeze)
|
75
|
+
when true, 'yes'.freeze
|
76
|
+
args.push(:SKIPME, 'yes'.freeze)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
run(*args)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Set the current connection name.
|
85
|
+
# @see https://redis.io/commands/client-setname
|
86
|
+
#
|
87
|
+
# @param [String] connection_name
|
88
|
+
#
|
89
|
+
# @return [String] 'OK' in case of success.
|
90
|
+
def client_setname(connection_name)
|
91
|
+
run(:CLIENT, :SETNAME, connection_name)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Stop processing commands from clients for some time.
|
95
|
+
# @see https://redis.io/commands/client-pause
|
96
|
+
#
|
97
|
+
# @param [Integer] timeout in milliseconds
|
98
|
+
#
|
99
|
+
# @return [String] 'OK' in case of success.
|
100
|
+
def client_pause(timeout)
|
101
|
+
run(:CLIENT, :PAUSE, timeout)
|
102
|
+
end
|
103
|
+
|
104
|
+
# Get array of Redis command details.
|
105
|
+
# @see https://redis.io/commands/command
|
106
|
+
#
|
107
|
+
# @return [Array] nested list of command details
|
108
|
+
def command
|
109
|
+
run(:COMMAND)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Get total number of Redis commands.
|
113
|
+
# @see https://redis.io/commands/command-count
|
114
|
+
#
|
115
|
+
# @return [Integer] number of commands returned by COMMAND
|
116
|
+
def command_count
|
117
|
+
run(:COMMAND, :COUNT)
|
118
|
+
end
|
119
|
+
|
120
|
+
# Extract keys given a full Redis command
|
121
|
+
# @see https://redis.io/commands/command-getkeys
|
122
|
+
#
|
123
|
+
# @return [Array] list of keys from your command
|
124
|
+
def command_getkeys(*args)
|
125
|
+
run(*args.unshift(:COMMAND, :GETKEYS))
|
126
|
+
end
|
127
|
+
|
128
|
+
# Get array of specific Redis command details.
|
129
|
+
# @see https://redis.io/commands/command-info
|
130
|
+
#
|
131
|
+
# @param [String, Array<String>] command_names
|
132
|
+
#
|
133
|
+
# @return [Array] nested list of command details.
|
134
|
+
def command_info(*command_names)
|
135
|
+
run(*command_names.unshift(:COMMAND, :INFO))
|
136
|
+
end
|
137
|
+
|
138
|
+
# Get the value of a configuration parameter
|
139
|
+
# @see https://redis.io/commands/config-get
|
140
|
+
#
|
141
|
+
# @param [String] parameter
|
142
|
+
#
|
143
|
+
# @return [Array] parameters with values
|
144
|
+
def config_get(parameter)
|
145
|
+
run(:CONFIG, :GET, parameter)
|
146
|
+
end
|
147
|
+
|
148
|
+
# Rewrite the configuration file with the in memory configuration
|
149
|
+
# @see https://redis.io/commands/config-rewrite
|
150
|
+
#
|
151
|
+
# @return [String] 'OK'
|
152
|
+
def config_rewrite
|
153
|
+
run(:CONFIG, :REWRITE)
|
154
|
+
end
|
155
|
+
|
156
|
+
# Set a configuration parameter to the given value
|
157
|
+
# @see https://redis.io/commands/config-set
|
158
|
+
#
|
159
|
+
# @param [String] parameter
|
160
|
+
# @param [String] value
|
161
|
+
#
|
162
|
+
# @return [String] OK if parameter was set properly.
|
163
|
+
def config_set(parameter, value)
|
164
|
+
run(:CONFIG, :SET, parameter, value)
|
165
|
+
end
|
166
|
+
|
167
|
+
# Reset the stats returned by INFO
|
168
|
+
# @see https://redis.io/commands/config-resetstat
|
169
|
+
#
|
170
|
+
# @return [String] 'OK'
|
171
|
+
def config_resetstat
|
172
|
+
run(:CONFIG, :RESETSTAT)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Return the number of keys in the selected database
|
176
|
+
# @see https://redis.io/commands/dbsize
|
177
|
+
#
|
178
|
+
# @return [Integer] selected database size
|
179
|
+
def dbsize
|
180
|
+
run(:DBSIZE)
|
181
|
+
end
|
182
|
+
|
183
|
+
# Remove all keys from all databases.
|
184
|
+
# @see https://redis.io/commands/flushall
|
185
|
+
#
|
186
|
+
# @param [Hash] opts
|
187
|
+
#
|
188
|
+
# @option opts [Boolean] :async
|
189
|
+
#
|
190
|
+
# @return [String] 'OK'
|
191
|
+
def flushall(opts = {})
|
192
|
+
opts[:async] ? run(:FLUSHALL, :ASYNC) : run(:FLUSHALL)
|
193
|
+
end
|
194
|
+
|
195
|
+
# Remove all keys from the current database.
|
5
196
|
# @see http://redis.io/commands/flushdb
|
6
197
|
#
|
198
|
+
# @param [Hash] opts
|
199
|
+
#
|
200
|
+
# @option opts [Boolean] :async
|
201
|
+
#
|
7
202
|
# @return [String] should always return 'OK'
|
8
|
-
def flushdb
|
9
|
-
run(:FLUSHDB)
|
203
|
+
def flushdb(opts = {})
|
204
|
+
opts[:async] ? run(:FLUSHDB, :ASYNC) : run(:FLUSHDB)
|
10
205
|
end
|
11
206
|
|
12
207
|
# Returns information and statistics about the server in a format that is
|
13
|
-
# simple to parse by computers and easy to read by humans
|
208
|
+
# simple to parse by computers and easy to read by humans.
|
14
209
|
# @see http://redis.io/commands/info
|
15
210
|
#
|
16
211
|
# @param [String] section used to select a specific section of information
|
@@ -19,6 +214,94 @@ module Oxblood
|
|
19
214
|
def info(section = nil)
|
20
215
|
section ? run(:INFO, section) : run(:INFO)
|
21
216
|
end
|
217
|
+
|
218
|
+
# Get the UNIX timestamp of the last successful save to disk.
|
219
|
+
# @see https://redis.io/commands/lastsave
|
220
|
+
#
|
221
|
+
# @return [Integer] an UNIX timestamp.
|
222
|
+
def lastsave
|
223
|
+
run(:LASTSAVE)
|
224
|
+
end
|
225
|
+
|
226
|
+
# Return the role of the instance in the context of replication.
|
227
|
+
# @see https://redis.io/commands/role
|
228
|
+
#
|
229
|
+
# @return [Array] where the first element is one of master, slave,
|
230
|
+
# sentinel and the additional elements are role-specific as illustrated
|
231
|
+
# above.
|
232
|
+
def role
|
233
|
+
run(:ROLE)
|
234
|
+
end
|
235
|
+
|
236
|
+
# Synchronously save the dataset to disk.
|
237
|
+
# @see https://redis.io/commands/save
|
238
|
+
#
|
239
|
+
# @return [String] 'OK'
|
240
|
+
def save
|
241
|
+
run(:SAVE)
|
242
|
+
end
|
243
|
+
|
244
|
+
# Synchronously save the dataset to disk and then shutdown the server.
|
245
|
+
# @see https://redis.io/commands/shutdown
|
246
|
+
#
|
247
|
+
# @param [Hash] opts
|
248
|
+
#
|
249
|
+
# @option opts [Boolean] :save truthy value acts as SAVE and explicit
|
250
|
+
# `false` value acts as NOSAVE. `nil` or absence of option don't add anything.
|
251
|
+
#
|
252
|
+
# @return [RError] in case of failure and nothing
|
253
|
+
# @return [nil] in case of success
|
254
|
+
def shutdown(opts = {})
|
255
|
+
case opts[:save]
|
256
|
+
when nil
|
257
|
+
run(:SHUTDOWN)
|
258
|
+
when false
|
259
|
+
run(:SHUTDOWN, :NOSAVE)
|
260
|
+
else
|
261
|
+
run(:SHUTDOWN, :SAVE)
|
262
|
+
end
|
263
|
+
rescue Errno::ECONNRESET
|
264
|
+
nil
|
265
|
+
end
|
266
|
+
|
267
|
+
# Make the server a slave of another instance, or promote it as master.
|
268
|
+
# @see https://redis.io/commands/slaveof
|
269
|
+
#
|
270
|
+
# @example Make server slave
|
271
|
+
# session.slaveof('localhost', 7777)
|
272
|
+
# @example Promote to master
|
273
|
+
# session.slaveof(:NO, :ONE)
|
274
|
+
#
|
275
|
+
# @param [String] host
|
276
|
+
# @param [String] port
|
277
|
+
#
|
278
|
+
# @return [String] 'OK'
|
279
|
+
def slaveof(host, port)
|
280
|
+
run(:SLAVEOF, host, port)
|
281
|
+
end
|
282
|
+
|
283
|
+
# Manages the Redis slow queries log.
|
284
|
+
# @see https://redis.io/commands/slowlog
|
285
|
+
#
|
286
|
+
# @param [Symbol] subcommand For example :len, :reset, :get
|
287
|
+
# @param [String] argument
|
288
|
+
#
|
289
|
+
# @return [Integer] for :len subcommand
|
290
|
+
# @return [String] 'OK' for :reset subcommand
|
291
|
+
# @return [Array] for :get subcommand
|
292
|
+
def slowlog(subcommand, argument = nil)
|
293
|
+
args = [:SLOWLOG, subcommand]
|
294
|
+
args << argument if argument
|
295
|
+
run(*args)
|
296
|
+
end
|
297
|
+
|
298
|
+
# Returns the current server time.
|
299
|
+
# @see https://redis.io/commands/time
|
300
|
+
#
|
301
|
+
# @return [Array<String, String>] unix time in seconds and microseconds.
|
302
|
+
def time
|
303
|
+
run(:TIME)
|
304
|
+
end
|
22
305
|
end
|
23
306
|
end
|
24
307
|
end
|
data/lib/oxblood/pipeline.rb
CHANGED
@@ -3,7 +3,7 @@ require 'oxblood/commands'
|
|
3
3
|
|
4
4
|
module Oxblood
|
5
5
|
# Redis pipeling class. Commands won't be send until {#sync} is called.
|
6
|
-
# Error responses won't be
|
6
|
+
# Error responses won't be raised and should be checked manually in the
|
7
7
|
# responses array.
|
8
8
|
# @see http://redis.io/topics/pipelining#redis-pipelining
|
9
9
|
#
|
data/lib/oxblood/pool.rb
CHANGED
data/lib/oxblood/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oxblood
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Shabanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: connection_pool
|
@@ -118,11 +118,13 @@ files:
|
|
118
118
|
- lib/oxblood.rb
|
119
119
|
- lib/oxblood/commands.rb
|
120
120
|
- lib/oxblood/commands/connection.rb
|
121
|
+
- lib/oxblood/commands/geo.rb
|
121
122
|
- lib/oxblood/commands/hashes.rb
|
122
123
|
- lib/oxblood/commands/hyper_log_log.rb
|
123
124
|
- lib/oxblood/commands/keys.rb
|
124
125
|
- lib/oxblood/commands/lists.rb
|
125
126
|
- lib/oxblood/commands/scan.rb
|
127
|
+
- lib/oxblood/commands/scripting.rb
|
126
128
|
- lib/oxblood/commands/server.rb
|
127
129
|
- lib/oxblood/commands/sets.rb
|
128
130
|
- lib/oxblood/commands/sorted_sets.rb
|
@@ -158,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
160
|
version: '0'
|
159
161
|
requirements: []
|
160
162
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.6.
|
163
|
+
rubygems_version: 2.6.10
|
162
164
|
signing_key:
|
163
165
|
specification_version: 4
|
164
166
|
summary: A Ruby Redis client
|