protocol-redis 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/lib/protocol/redis.rb +1 -1
- data/lib/protocol/redis/connection.rb +4 -3
- data/lib/protocol/redis/methods.rb +39 -0
- data/lib/protocol/redis/methods/hashes.rb +79 -0
- data/lib/protocol/redis/methods/keys.rb +140 -0
- data/lib/protocol/redis/methods/lists.rb +118 -0
- data/lib/protocol/redis/methods/server.rb +48 -0
- data/lib/protocol/redis/methods/strings.rb +132 -0
- data/lib/protocol/redis/version.rb +1 -1
- data/protocol-redis.gemspec +0 -1
- metadata +8 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eaec89c45931d2380b65c26b642dc53cc65b0c2b93251c57fa9831fa8aa654a6
|
4
|
+
data.tar.gz: 87be2b36ea8deeb9eef4ed56f2e833120a8641fa4256feb0decb4f8ee73b4f64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c4bf2da40ab8a0090e08428a26f2bdf1b02c1c210a805945d8ff001c5836d6bc3710e1889cd192f0f862bd17dfeb1a6c83dec2cae55ee407b216a96edfd9666
|
7
|
+
data.tar.gz: 4a737e454c0fcdd0c2469f9770caa1e6c4bbe309c2a80a15b5a4937462c5628d175ab59390c075b4d2edd07497ff6bd6947396d0239b11859a89c95fb3962f03
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Protocol::Redis
|
2
2
|
|
3
|
-
Implements the RESP2 and
|
3
|
+
Implements the RESP2 and [RESP3](https://github.com/antirez/RESP3) Redis protocols.
|
4
4
|
|
5
5
|
[![Build Status](https://travis-ci.com/socketry/protocol-redis.svg?branch=master)](https://travis-ci.com/socketry/protocol-redis)
|
6
6
|
|
@@ -22,7 +22,16 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
```ruby
|
26
|
+
sockets = Socket.pair(Socket::PF_UNIX, Socket::SOCK_STREAM)
|
27
|
+
|
28
|
+
client = Protocol::Redis::Connection.new(sockets.first)
|
29
|
+
server = Protocol::Redis::Connection.new(sockets.last)
|
30
|
+
|
31
|
+
client.write_object("Hello World!")
|
32
|
+
puts server.read_object
|
33
|
+
# => "Hello World!"
|
34
|
+
```
|
26
35
|
|
27
36
|
## Contributing
|
28
37
|
|
data/lib/protocol/redis.rb
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
|
-
|
21
|
+
require_relative 'error'
|
22
22
|
|
23
23
|
module Protocol
|
24
24
|
module Redis
|
@@ -49,7 +49,7 @@ module Protocol
|
|
49
49
|
|
50
50
|
# The redis server doesn't want actual objects (e.g. integers) but only bulk strings. So, we inline it for performance.
|
51
51
|
def write_request(arguments)
|
52
|
-
write_lines("*#{arguments.
|
52
|
+
write_lines("*#{arguments.size}")
|
53
53
|
|
54
54
|
arguments.each do |argument|
|
55
55
|
string = argument.to_s
|
@@ -81,7 +81,8 @@ module Protocol
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def read_object
|
84
|
-
line = read_line
|
84
|
+
line = read_line or raise EOFError
|
85
|
+
|
85
86
|
token = line.slice!(0, 1)
|
86
87
|
|
87
88
|
case token
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Copyright, 2019, by Mikael Henriksson. <http://www.mhenrixon.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require_relative 'methods/hashes'
|
22
|
+
require_relative 'methods/keys'
|
23
|
+
require_relative 'methods/lists'
|
24
|
+
require_relative 'methods/server'
|
25
|
+
require_relative 'methods/strings'
|
26
|
+
|
27
|
+
module Protocol
|
28
|
+
module Redis
|
29
|
+
module Methods
|
30
|
+
def self.included(klass)
|
31
|
+
klass.include Methods::Hashes
|
32
|
+
klass.include Methods::Keys
|
33
|
+
klass.include Methods::Lists
|
34
|
+
klass.include Methods::Server
|
35
|
+
klass.include Methods::Strings
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Copyright, 2019, by Mikael Henriksson. <http://www.mhenrixon.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module Protocol
|
22
|
+
module Redis
|
23
|
+
module Methods
|
24
|
+
module Hashes
|
25
|
+
def hlen(key)
|
26
|
+
return call('HLEN', key)
|
27
|
+
end
|
28
|
+
|
29
|
+
def hset(key, field, value)
|
30
|
+
return call('HSET', key, field, value)
|
31
|
+
end
|
32
|
+
|
33
|
+
def hsetnx(key, field, value)
|
34
|
+
return call('HSETNX', key, field, value)
|
35
|
+
end
|
36
|
+
|
37
|
+
def hmset(key, *attrs)
|
38
|
+
return call('HMSET', key, *attrs)
|
39
|
+
end
|
40
|
+
|
41
|
+
def hget(key, field)
|
42
|
+
return call('HGET', key, field)
|
43
|
+
end
|
44
|
+
|
45
|
+
def hmget(key, *fields, &blk)
|
46
|
+
return call('HMGET', key, *fields, &blk)
|
47
|
+
end
|
48
|
+
|
49
|
+
def hdel(key, *fields)
|
50
|
+
return call('HDEL', key, *fields)
|
51
|
+
end
|
52
|
+
|
53
|
+
def hexists(key, field)
|
54
|
+
return call('HEXISTS', key, field)
|
55
|
+
end
|
56
|
+
|
57
|
+
def hincrby(key, field, increment)
|
58
|
+
return call('HINCRBY', key, field, increment)
|
59
|
+
end
|
60
|
+
|
61
|
+
def hincrbyfloat(key, field, increment)
|
62
|
+
return call('HINCRBYFLOAT', key, field, increment)
|
63
|
+
end
|
64
|
+
|
65
|
+
def hkeys(key)
|
66
|
+
return call('HKEYS', key)
|
67
|
+
end
|
68
|
+
|
69
|
+
def hvals(key)
|
70
|
+
return call('HVALS', key)
|
71
|
+
end
|
72
|
+
|
73
|
+
def hgetall(key)
|
74
|
+
return call('HGETALL', key)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
# Copyright, 2018, by Huba Nagy.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'date'
|
23
|
+
|
24
|
+
module Protocol
|
25
|
+
module Redis
|
26
|
+
module Methods
|
27
|
+
module Keys
|
28
|
+
def del(key, *keys)
|
29
|
+
return call('DEL', key, *keys)
|
30
|
+
end
|
31
|
+
|
32
|
+
def dump(key)
|
33
|
+
return call('DUMP', key)
|
34
|
+
end
|
35
|
+
|
36
|
+
def exists(key, *keys)
|
37
|
+
return call('EXISTS', key, *keys)
|
38
|
+
end
|
39
|
+
|
40
|
+
def expire(key, seconds)
|
41
|
+
return call('EXPIRE', key, seconds)
|
42
|
+
end
|
43
|
+
|
44
|
+
def expireat(key, time)
|
45
|
+
case time
|
46
|
+
when DateTime, Time, Date
|
47
|
+
timestamp = time.strftime('%s').to_i
|
48
|
+
else
|
49
|
+
timestamp = time
|
50
|
+
end
|
51
|
+
|
52
|
+
return call('EXPIREAT', key, timestamp)
|
53
|
+
end
|
54
|
+
|
55
|
+
def keys(pattern)
|
56
|
+
return call('KEYS', pattern)
|
57
|
+
end
|
58
|
+
|
59
|
+
def migrate
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
def move(key, db)
|
64
|
+
return call('MOVE', key, db)
|
65
|
+
end
|
66
|
+
|
67
|
+
def object
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
def persist(key)
|
72
|
+
return call('PERSIST', key)
|
73
|
+
end
|
74
|
+
|
75
|
+
def pexpire(key, milliseconds)
|
76
|
+
return call('PEXPIRE', milliseconds)
|
77
|
+
end
|
78
|
+
|
79
|
+
def pexpireat(key, time)
|
80
|
+
case time.class
|
81
|
+
when DateTime, Time, Date
|
82
|
+
timestamp = time.strftime('%Q').to_i
|
83
|
+
else
|
84
|
+
timestamp = time
|
85
|
+
end
|
86
|
+
|
87
|
+
return call('PEXPIREAT', key, timestamp)
|
88
|
+
end
|
89
|
+
|
90
|
+
def pttl(key)
|
91
|
+
return call('PTTL', key)
|
92
|
+
end
|
93
|
+
|
94
|
+
def randomkey
|
95
|
+
return call('RANDOMKEY')
|
96
|
+
end
|
97
|
+
|
98
|
+
def rename(key, new_key)
|
99
|
+
return call('RENAME', key, new_key)
|
100
|
+
end
|
101
|
+
|
102
|
+
def renamenx(key, new_key)
|
103
|
+
return call('RENAMENX', key, new_key)
|
104
|
+
end
|
105
|
+
|
106
|
+
def restore(key, serialized_value, ttl=0)
|
107
|
+
return call('RESTORE', key, ttl, serialized_value)
|
108
|
+
end
|
109
|
+
|
110
|
+
def sort
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
def touch(key, *keys)
|
115
|
+
return call('TOUCH', key, *keys)
|
116
|
+
end
|
117
|
+
|
118
|
+
def ttl(key)
|
119
|
+
return call('TTL', key)
|
120
|
+
end
|
121
|
+
|
122
|
+
def type(key)
|
123
|
+
return call('TYPE', key)
|
124
|
+
end
|
125
|
+
|
126
|
+
def unlink(key)
|
127
|
+
return call('UNLINK', key)
|
128
|
+
end
|
129
|
+
|
130
|
+
def wait(newreplicas, timeout)
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
def scan
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
# Copyright, 2018, by Huba Nagy.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
|
22
|
+
module Protocol
|
23
|
+
module Redis
|
24
|
+
module Methods
|
25
|
+
module Lists
|
26
|
+
def blpop(*keys, timeout: 0)
|
27
|
+
return call('BLPOP', *keys, timeout)
|
28
|
+
end
|
29
|
+
|
30
|
+
def brpop(*keys, timeout: 0)
|
31
|
+
return call('BRPOP', *keys, timeout)
|
32
|
+
end
|
33
|
+
|
34
|
+
def brpoplpush(source, destination, timeout)
|
35
|
+
return call('BRPOPLPUSH', source, destination, timeout)
|
36
|
+
end
|
37
|
+
|
38
|
+
def lindex(key, index)
|
39
|
+
return call('LINDEX', key, index)
|
40
|
+
end
|
41
|
+
|
42
|
+
def linsert(key, position=:before, index, value)
|
43
|
+
if position == :before
|
44
|
+
offset = 'BEFORE'
|
45
|
+
else
|
46
|
+
offset = 'AFTER'
|
47
|
+
end
|
48
|
+
|
49
|
+
return call('LINSERT', key, offset, index, value)
|
50
|
+
end
|
51
|
+
|
52
|
+
def llen(key)
|
53
|
+
return call('LLEN', key)
|
54
|
+
end
|
55
|
+
|
56
|
+
def lpop(key)
|
57
|
+
return call('LPOP', key)
|
58
|
+
end
|
59
|
+
|
60
|
+
def lpush(key, value, *values)
|
61
|
+
case value
|
62
|
+
when Array
|
63
|
+
values = value
|
64
|
+
else
|
65
|
+
values = [value] + values
|
66
|
+
end
|
67
|
+
|
68
|
+
return call('LPUSH', key, *values)
|
69
|
+
end
|
70
|
+
|
71
|
+
def lpushx(key, value)
|
72
|
+
return call('LPUSHX', key, value)
|
73
|
+
end
|
74
|
+
|
75
|
+
def lrange(key, start, stop)
|
76
|
+
return call('LRANGE', key, start, stop)
|
77
|
+
end
|
78
|
+
|
79
|
+
def lrem(key, count, value)
|
80
|
+
return call('LREM', key, count)
|
81
|
+
end
|
82
|
+
|
83
|
+
def lset(key, index, values)
|
84
|
+
return call('LSET', key, index, values)
|
85
|
+
end
|
86
|
+
|
87
|
+
def ltrim(key, start, stop)
|
88
|
+
return call('LTRIM', key, start, stop)
|
89
|
+
end
|
90
|
+
|
91
|
+
def rpop(key)
|
92
|
+
return call('RPOP', key)
|
93
|
+
end
|
94
|
+
|
95
|
+
def rpoplpush(source, destination=nil)
|
96
|
+
destination = source if destination.nil?
|
97
|
+
|
98
|
+
return call('RPOPLPUSH', source, destination)
|
99
|
+
end
|
100
|
+
|
101
|
+
def rpush(key, value, *values)
|
102
|
+
case value
|
103
|
+
when Array
|
104
|
+
values = value
|
105
|
+
else
|
106
|
+
values = [value] + values
|
107
|
+
end
|
108
|
+
|
109
|
+
return call('RPUSH', key, *values)
|
110
|
+
end
|
111
|
+
|
112
|
+
def rpushx(key, value)
|
113
|
+
return call('RPUSHX', key, value)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
# Copyright, 2018, by Huba Nagy.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
|
22
|
+
module Protocol
|
23
|
+
module Redis
|
24
|
+
module Methods
|
25
|
+
module Server
|
26
|
+
# Get info from server.
|
27
|
+
# @return [Hash] the server metadata.
|
28
|
+
def info
|
29
|
+
metadata = {}
|
30
|
+
|
31
|
+
call('INFO').each_line(Protocol::CRLF) do |line|
|
32
|
+
key, value = line.split(':')
|
33
|
+
|
34
|
+
if value
|
35
|
+
metadata[key.to_sym] = value.chomp!
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
return metadata
|
40
|
+
end
|
41
|
+
|
42
|
+
def flushdb!
|
43
|
+
call 'FLUSHDB'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
# Copyright, 2018, by Huba Nagy.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
|
22
|
+
module Protocol
|
23
|
+
module Redis
|
24
|
+
module Methods
|
25
|
+
module Strings
|
26
|
+
def append(key, value)
|
27
|
+
return call('APPEND', key, value)
|
28
|
+
end
|
29
|
+
|
30
|
+
def bitcount(key, *range)
|
31
|
+
return call('BITCOUNT', key, *range)
|
32
|
+
end
|
33
|
+
|
34
|
+
def decr(key)
|
35
|
+
return call('DECR', key)
|
36
|
+
end
|
37
|
+
|
38
|
+
def decrby(key, decrement)
|
39
|
+
return call('DECRBY', key, decrement)
|
40
|
+
end
|
41
|
+
|
42
|
+
def get(key)
|
43
|
+
return call('GET', key)
|
44
|
+
end
|
45
|
+
|
46
|
+
def getbit(key, offset)
|
47
|
+
return call('GETBIT', key, offset)
|
48
|
+
end
|
49
|
+
|
50
|
+
def getrange(key, start_index, end_index)
|
51
|
+
return call('GETRANGE', key, start_index, end_index)
|
52
|
+
end
|
53
|
+
|
54
|
+
def getset(key, value)
|
55
|
+
return call('GETSET', key, value)
|
56
|
+
end
|
57
|
+
|
58
|
+
def incr(key)
|
59
|
+
return call('INCR', key)
|
60
|
+
end
|
61
|
+
|
62
|
+
def incrby(key, increment)
|
63
|
+
return call('INCRBY', key, increment)
|
64
|
+
end
|
65
|
+
|
66
|
+
def incrbyfloat(key, increment)
|
67
|
+
return call('INCRBYFLOAT', key, increment)
|
68
|
+
end
|
69
|
+
|
70
|
+
def mget(key, *keys)
|
71
|
+
return call('MGET', key, *keys)
|
72
|
+
end
|
73
|
+
|
74
|
+
def mset(pairs)
|
75
|
+
flattened_pairs = pairs.keys.zip(pairs.values).flatten
|
76
|
+
return call('MSET', *flattened_pairs)
|
77
|
+
end
|
78
|
+
|
79
|
+
def msetnx(pairs)
|
80
|
+
flattened_pairs = pairs.keys.zip(pairs.values).flatten
|
81
|
+
return call('MSETNX', *flattened_pairs)
|
82
|
+
end
|
83
|
+
|
84
|
+
def psetex(key, milliseconds, value)
|
85
|
+
return set key, value, milliseconds: milliseconds
|
86
|
+
end
|
87
|
+
|
88
|
+
def set(key, value, **options)
|
89
|
+
arguments = []
|
90
|
+
|
91
|
+
if options.has_key? :seconds
|
92
|
+
arguments << 'EX'
|
93
|
+
arguments << options[:seconds]
|
94
|
+
end
|
95
|
+
|
96
|
+
if options.has_key? :milliseconds
|
97
|
+
arguments << 'PX'
|
98
|
+
arguments << options[:milliseconds]
|
99
|
+
end
|
100
|
+
|
101
|
+
if options[:condition] == :nx
|
102
|
+
arguments << 'NX'
|
103
|
+
elsif options[:condition] == :xx
|
104
|
+
arguments << 'XX'
|
105
|
+
end
|
106
|
+
|
107
|
+
return call('SET', key, value, *arguments)
|
108
|
+
end
|
109
|
+
|
110
|
+
def setbit(key, offset, value)
|
111
|
+
return call('SETBIT', key, offset, value)
|
112
|
+
end
|
113
|
+
|
114
|
+
def setex(key, seconds, value)
|
115
|
+
return set key, value, seconds: seconds
|
116
|
+
end
|
117
|
+
|
118
|
+
def setnx(key, value)
|
119
|
+
return set key, value, condition: :nx
|
120
|
+
end
|
121
|
+
|
122
|
+
def setrange(key, offset, value)
|
123
|
+
return call('SETRANGE', key, offset, value)
|
124
|
+
end
|
125
|
+
|
126
|
+
def strlen(key)
|
127
|
+
return call('STRLEN', key)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
data/protocol-redis.gemspec
CHANGED
@@ -17,7 +17,6 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_development_dependency "async-rspec", "~> 1.1"
|
21
20
|
spec.add_development_dependency "benchmark-ips"
|
22
21
|
|
23
22
|
spec.add_development_dependency "covered"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protocol-redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -9,22 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-08-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: async-rspec
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '1.1'
|
21
|
-
type: :development
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - "~>"
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: '1.1'
|
28
14
|
- !ruby/object:Gem::Dependency
|
29
15
|
name: benchmark-ips
|
30
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,6 +99,12 @@ files:
|
|
113
99
|
- lib/protocol/redis.rb
|
114
100
|
- lib/protocol/redis/connection.rb
|
115
101
|
- lib/protocol/redis/error.rb
|
102
|
+
- lib/protocol/redis/methods.rb
|
103
|
+
- lib/protocol/redis/methods/hashes.rb
|
104
|
+
- lib/protocol/redis/methods/keys.rb
|
105
|
+
- lib/protocol/redis/methods/lists.rb
|
106
|
+
- lib/protocol/redis/methods/server.rb
|
107
|
+
- lib/protocol/redis/methods/strings.rb
|
116
108
|
- lib/protocol/redis/version.rb
|
117
109
|
- protocol-redis.gemspec
|
118
110
|
homepage: https://github.com/socketry/protocol-redis
|