oxblood 0.1.0.dev8 → 0.1.0.dev9

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
  SHA1:
3
- metadata.gz: 5de6f805e09661746b328df9a6654848a4937307
4
- data.tar.gz: 8a6f7be7ff52ec6eeda55d852fbd7809c746224f
3
+ metadata.gz: ef39e93b7bf0f2dc011433a59874028fcc1e49e6
4
+ data.tar.gz: f9c730aac3b62cc6e4cfb3d76bd0fb29d87bcc76
5
5
  SHA512:
6
- metadata.gz: 34d5e0b3b3547205df5d72388b81a24f862f6887d90ff87672304fdebf62bed3eb8c5bf097274df1f5ff13aa84154eeb130f3e4768eaac3c141a2543c6a793c2
7
- data.tar.gz: 74a234ad3c08837d61c6e355188190f6af04f0bb4df7245d6cf8edaecaf5b799fb49f49fdc962a22c71f13cd1e05cd9e1fc8831a53374a45b978fb16d771ab5c
6
+ metadata.gz: e22b6aea29ce947a9f735ab788a29e14d1ada26cdb411cd3970e1b703fa62b3b14d59b83829edecc46f1eec3539b8538313fb3182758096adf7d0d07adbcd7a9
7
+ data.tar.gz: b32802b13c4569f8b7cc164b2a2ee5d0a0932b9320788626e95bc025e557b828b3046798d49a55b302fc1e271c4796dd900358c6cf9213349bb73f2f0f6912c1
data/.travis.yml CHANGED
@@ -6,7 +6,7 @@ rvm:
6
6
  - 2.2.5
7
7
  - 2.3.1
8
8
  - jruby-9.0.5.0
9
- - jruby-9.1.2.0
9
+ - jruby-9.1.5.0
10
10
 
11
11
  services:
12
12
  - redis-server
data/README.md CHANGED
@@ -29,7 +29,7 @@ An experimental Redis Ruby client.
29
29
  - Sets (14/15) (See [#10](https://github.com/etehtsea/oxblood/issues/10))
30
30
  - Sorted Sets (15/21) (See [#12], [#13], [#14], [#15])
31
31
  - Strings (23/24) (See [#16](https://github.com/etehtsea/oxblood/issues/16))
32
- - Transaction (0/5)
32
+ - Transaction (3/5) (See [#19])
33
33
  - [Pipeling](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Pipeline)
34
34
  - [Connection pooling](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/Pool)
35
35
  - [Connection resiliency](http://www.rubydoc.info/github/etehtsea/oxblood/master/Oxblood/RSocket)
@@ -60,3 +60,4 @@ The gem is available as open source under the terms of the [MIT License](http://
60
60
  [#13]: https://github.com/etehtsea/oxblood/issues/13
61
61
  [#14]: https://github.com/etehtsea/oxblood/issues/14
62
62
  [#15]: https://github.com/etehtsea/oxblood/issues/15
63
+ [#19]: https://github.com/etehtsea/oxblood/issues/19
@@ -0,0 +1,59 @@
1
+ module Oxblood
2
+ module Commands
3
+ module Connection
4
+ # Authenticate to the server
5
+ # @see http://redis.io/commands/auth
6
+ #
7
+ # @param [String] password
8
+ #
9
+ # @return [String] 'OK'
10
+ # @return [RError] if wrong password was passed or server does not require
11
+ # password
12
+ def auth(password)
13
+ run(:AUTH, password)
14
+ end
15
+
16
+ # Echo the given string
17
+ # @see http://redis.io/commands/echo
18
+ #
19
+ # @param [String] message
20
+ #
21
+ # @return [String] given string
22
+ def echo(message)
23
+ run(:ECHO, message)
24
+ end
25
+
26
+ # Returns PONG if no argument is provided, otherwise return a copy of
27
+ # the argument as a bulk
28
+ # @see http://redis.io/commands/ping
29
+ #
30
+ # @param [String] message to return
31
+ #
32
+ # @return [String] message passed as argument
33
+ def ping(message = nil)
34
+ message ? run(:PING, message) : run(:PING)
35
+ end
36
+
37
+ # Change the selected database for the current connection
38
+ # @see http://redis.io/commands/select
39
+ #
40
+ # @param [Integer] index database to switch
41
+ #
42
+ # @return [String] 'OK'
43
+ # @return [RError] if wrong index was passed
44
+ def select(index)
45
+ run(:SELECT, index)
46
+ end
47
+
48
+ # Close the connection
49
+ # @see http://redis.io/commands/quit
50
+ #
51
+ # @return [String] 'OK'
52
+ def quit
53
+ run(:QUIT)
54
+ ensure
55
+ connection.socket.close
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,174 @@
1
+ module Oxblood
2
+ module Commands
3
+ module Hashes
4
+ QUEUED = 'QUEUED'.freeze
5
+ private_constant :QUEUED
6
+
7
+ # Removes the specified fields from the hash stored at key
8
+ # @see http://redis.io/commands/hdel
9
+ #
10
+ # @param [String] key under which hash is stored
11
+ # @param [Array<#to_s>] fields to delete
12
+ #
13
+ # @return [Integer] the number of fields that were removed from the hash
14
+ def hdel(key, fields)
15
+ run(:HDEL, key, fields)
16
+ end
17
+
18
+ # Returns if field is an existing field in the hash stored at key
19
+ # @see http://redis.io/commands/hexists
20
+ #
21
+ # @param [String] key under which hash is stored
22
+ # @param [String] field to check for existence
23
+ #
24
+ # @return [Boolean] do hash contains field or not
25
+ def hexists(key, field)
26
+ 1 == run(:HEXISTS, key, field)
27
+ end
28
+
29
+ # Get the value of a hash field
30
+ # @see http://redis.io/commands/hget
31
+ #
32
+ # @param [String] key under which hash is stored
33
+ # @param [String] field name
34
+ #
35
+ # @return [String, nil] the value associated with field
36
+ # or nil when field is not present in the hash or key does not exist.
37
+ def hget(key, field)
38
+ run(:HGET, key, field)
39
+ end
40
+
41
+ # Get all the fields and values in a hash
42
+ # @see http://redis.io/commands/hgetall
43
+ #
44
+ # @param [String] key under which hash is stored
45
+ #
46
+ # @return [Hash] of fields and their values
47
+ def hgetall(key)
48
+ response = run(:HGETALL, key)
49
+ response == 'QUEUED' ? response : Hash[*response]
50
+ end
51
+
52
+ # Increment the integer value of a hash field by the given number
53
+ # @see http://redis.io/commands/hincrby
54
+ #
55
+ # @param [String] key under which hash is stored
56
+ # @param [String] field to increment
57
+ # @param [Integer] increment by value
58
+ #
59
+ # @return [Integer] the value at field after the increment operation
60
+ def hincrby(key, field, increment)
61
+ run(:HINCRBY, key, field, increment)
62
+ end
63
+
64
+ # Increment the float value of a hash field by the given number
65
+ # @see http://redis.io/commands/hincrby
66
+ #
67
+ # @param [String] key under which hash is stored
68
+ # @param [String] field to increment
69
+ # @param [Integer] increment by value
70
+ #
71
+ # @return [String] the value of field after the increment
72
+ # @return [RError] field contains a value of the wrong type (not a string).
73
+ # Or the current field content or the specified increment are not parsable
74
+ # as a double precision floating point number.
75
+ def hincrbyfloat(key, field, increment)
76
+ run(:HINCRBYFLOAT, key, field, increment)
77
+ end
78
+
79
+ # Get all the keys in a hash
80
+ # @see http://redis.io/commands/hkeys
81
+ #
82
+ # @param [String] key
83
+ #
84
+ # @return [Array] list of fields in the hash, or an empty list when
85
+ # key does not exist.
86
+ def hkeys(key)
87
+ run(:HKEYS, key)
88
+ end
89
+
90
+ # Get the number of keys in a hash
91
+ # @see http://redis.io/commands/hlen
92
+ #
93
+ # @param [String] key
94
+ #
95
+ # @return [Integer] number of fields in the hash, or 0 when
96
+ # key does not exist.
97
+ def hlen(key)
98
+ run(:HLEN, key)
99
+ end
100
+
101
+ # Get the field values of all given hash fields
102
+ # @see http://redis.io/commands/hmget
103
+ #
104
+ # @param [String] key under which hash is stored
105
+ # @param [String, Array<String>] fields to get
106
+ #
107
+ # @return [Array] list of values associated with the given fields,
108
+ # in the same order as they are requested.
109
+ def hmget(key, *fields)
110
+ run(*fields.unshift(:HMGET, key))
111
+ end
112
+
113
+ # Set multiple hash fields to multiple values
114
+ # @see http://redis.io/commands/hmset
115
+ #
116
+ # @param [String] key under which store hash
117
+ # @param [[String, String], Array<[String, String]>] args fields and values
118
+ #
119
+ # @return [String] 'OK'
120
+ def hmset(key, *args)
121
+ run(*args.unshift(:HMSET, key))
122
+ end
123
+
124
+ # Set the string value of a hash field
125
+ # @see http://redis.io/commands/hset
126
+ #
127
+ # @param [String] key
128
+ # @param [String] field
129
+ # @param [String] value
130
+ #
131
+ # @return [Integer] 1 if field is a new field in the hash and value was set.
132
+ # 0 if field already exists in the hash and the value was updated.
133
+ def hset(key, field, value)
134
+ run(:HSET, key, field, value)
135
+ end
136
+
137
+ # Set the value of a hash field, only if the field does not exist
138
+ # @see http://redis.io/commands/hsetnx
139
+ #
140
+ # @param [String] key
141
+ # @param [String] field
142
+ # @param [String] value
143
+ #
144
+ # @return [Integer] 1 if field is a new field in the hash and value was set.
145
+ # 0 if field already exists in the hash and no operation was performed.
146
+ def hsetnx(key, field, value)
147
+ run(:HSETNX, key, field, value)
148
+ end
149
+
150
+ # Get the length of the value of a hash field
151
+ # @see http://redis.io/commands/hstrlen
152
+ #
153
+ # @param [String] key
154
+ # @param [String] field
155
+ #
156
+ # @return [Integer] the string length of the value associated with field,
157
+ # or 0 when field is not present in the hash or key does not exist at all.
158
+ def hstrlen(key, field)
159
+ run(:HSTRLEN, key, field)
160
+ end
161
+
162
+ # Get all values in a hash
163
+ # @see http://redis.io/commands/hvals
164
+ #
165
+ # @param [String] key
166
+ #
167
+ # @return [Array] list of values in the hash, or an empty list when
168
+ # key does not exist
169
+ def hvals(key)
170
+ run(:HVALS, key)
171
+ end
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,213 @@
1
+ module Oxblood
2
+ module Commands
3
+ module Keys
4
+ # Delete a key
5
+ # @see http://redis.io/commands/del
6
+ #
7
+ # @param [String, Array<String>] keys to delete
8
+ #
9
+ # @return [Integer] the number of keys that were removed
10
+ def del(*keys)
11
+ run(*keys.unshift(:DEL))
12
+ end
13
+
14
+ # Return a serialized version of the value stored at specified key.
15
+ # @see http://redis.io/commands/dump
16
+ #
17
+ # @param [String] key
18
+ #
19
+ # @return [String] serialized value
20
+ def dump(key)
21
+ run(:DUMP, key)
22
+ end
23
+
24
+ # Determine if a key exists
25
+ # @see http://redis.io/commands/exists
26
+ #
27
+ # @param [String, Array<String>] keys to check
28
+ #
29
+ # @return [Integer] the number of keys existing among the ones specified as
30
+ # arguments. Keys mentioned multiple times and existing are counted
31
+ # multiple times.
32
+ def exists(*keys)
33
+ run(*keys.unshift(:EXISTS))
34
+ end
35
+
36
+ # Set a key's time to live in seconds
37
+ # @see http://redis.io/commands/expire
38
+ #
39
+ # @param [String] key to expire
40
+ # @param [Integer] seconds number of seconds
41
+ #
42
+ # @return [Integer] 1 if the timeout was set. 0 if key does not exist or
43
+ # the timeout could not be set.
44
+ def expire(key, seconds)
45
+ run(:EXPIRE, key, seconds)
46
+ end
47
+
48
+ # Set the expiration for a key as a UNIX timestamp
49
+ # @see http://redis.io/commands/expireat
50
+ #
51
+ # @param [String] key
52
+ # @param [Integer] timestamp in UNIX format
53
+ #
54
+ # @return [Integer] 1 if the timeout was set. 0 if key does not exist or
55
+ # the timeout could not be set.
56
+ def expireat(key, timestamp)
57
+ run(:EXPIREAT, key, timestamp)
58
+ end
59
+
60
+ # Find all keys matching the given pattern
61
+ # @see http://redis.io/commands/keys
62
+ #
63
+ # @param [String] pattern used to match keys
64
+ def keys(pattern)
65
+ run(:KEYS, pattern)
66
+ end
67
+
68
+ # Move a key to another database
69
+ # @see http://redis.io/commands/move
70
+ #
71
+ # @param [String] key
72
+ # @param [Integer] db index
73
+ #
74
+ # @return [Integer] 1 if key was moved and 0 otherwise.
75
+ def move(key, db)
76
+ run(:MOVE, key, db)
77
+ end
78
+
79
+ # Inspect the internals of Redis objects
80
+ # @see http://redis.io/commands/object
81
+ #
82
+ # @param [String] subcommand `REFCOUNT`, `ENCODING`, `IDLETIME`
83
+ # @param [String] key
84
+ #
85
+ # @return [Integer] in case of `REFCOUNT` and `IDLETIME` subcommands
86
+ # @return [String] in case of `ENCODING` subcommand
87
+ # @return [nil] if object you try to inspect is missing
88
+ def object(subcommand, key)
89
+ run(:OBJECT, subcommand, key)
90
+ end
91
+
92
+ # Remove expiration from a key
93
+ # @see http://redis.io/commands/persist
94
+ # @param [String] key
95
+ #
96
+ # @return [Integer] 1 if the timeout was removed and 0 otherwise
97
+ def persist(key)
98
+ run(:PERSIST, key)
99
+ end
100
+
101
+ # Set a key's time to live in milliseconds
102
+ # @see http://redis.io/commands/pexpire
103
+ #
104
+ # @param [String] key
105
+ # @param [Integer] milliseconds
106
+ #
107
+ # @return [Integer] 1 if the timeout was set and 0 otherwise
108
+ def pexpire(key, milliseconds)
109
+ run(:PEXPIRE, key, milliseconds)
110
+ end
111
+
112
+ # Set the expiration for a key as a UNIX timestamp specified in milliseconds
113
+ # @see http://redis.io/commands/pexpireat
114
+ #
115
+ # @param [String] key
116
+ # @param [Integer] timestamp in milliseconds
117
+ #
118
+ # @return [Integer] 1 if the timeout was set and 0 otherwise
119
+ def pexpireat(key, timestamp)
120
+ run(:PEXPIREAT, key, timestamp)
121
+ end
122
+
123
+ # Get the time to live for a key in milliseconds
124
+ # @see http://redis.io/commands/pttl
125
+ #
126
+ # @param [String] key
127
+ #
128
+ # @return [Integer] TTL in milliseconds, or a negative value in order to
129
+ # signal an error
130
+ def pttl(key)
131
+ run(:PTTL, key)
132
+ end
133
+
134
+ # Return a random key from the keyspace
135
+ # @see http://redis.io/commands/randomkey
136
+ #
137
+ # @return [String] the random key
138
+ # @return [nil] if database is empty
139
+ def randomkey
140
+ run(:RANDOMKEY)
141
+ end
142
+
143
+ # Rename a key
144
+ # @see http://redis.io/commands/rename
145
+ #
146
+ # @param [String] key to rename
147
+ # @param [String] newkey
148
+ #
149
+ # @return [String] OK in case of success
150
+ # @return [RError] if key does not exist. Before Redis 3.2.0, an error is
151
+ # returned if source and destination names are the same.
152
+ def rename(key, newkey)
153
+ run(:RENAME, key, newkey)
154
+ end
155
+
156
+ # Rename a key, only if the new key does not exist
157
+ # @see http://redis.io/commands/renamenx
158
+ #
159
+ # @param [String] key to rename
160
+ # @param [String] newkey
161
+ #
162
+ # @return [Integer] 1 if key was renamed to newkey. 0 if newkey already
163
+ # exists.
164
+ # @return [RError] if key does not exist. Before Redis 3.2.0, an error is
165
+ # returned if source and destination names are the same.
166
+ def renamenx(key, newkey)
167
+ run(:RENAMENX, key, newkey)
168
+ end
169
+
170
+ # Create a key using the provided serialized value, previously obtained
171
+ # using DUMP
172
+ # @see http://redis.io/commands/restore
173
+ #
174
+ # @param [String] key
175
+ # @param [Integer] ttl expire time in milliseconds
176
+ # @param [String] serialized_value obtained using DUMP command
177
+ # @param [Hash] opts
178
+ #
179
+ # @option opts [Boolean] :replace (false) Override key if it already exists
180
+ #
181
+ # @return [String] OK on success
182
+ # @return [RError] if replace is false and key already exists or RDB version
183
+ # and data checksum don't match.
184
+ def restore(key, ttl, serialized_value, opts = {})
185
+ args = [:RESTORE, key, ttl, serialized_value]
186
+ args << :REPLACE if opts[:replace]
187
+
188
+ run(*args)
189
+ end
190
+
191
+ # Get the time to live for a key
192
+ # @see http://redis.io/commands/ttl
193
+ #
194
+ # @param [String] key
195
+ #
196
+ # @return [Integer] TTL in seconds, or a negative value in order to signal
197
+ # an error
198
+ def ttl(key)
199
+ run(:TTL, key)
200
+ end
201
+
202
+ # Determine the type stored at key
203
+ # @see http://redis.io/commands/type
204
+ #
205
+ # @param [String] key
206
+ #
207
+ # @return [String] type of key, or none when key does not exist.
208
+ def type(key)
209
+ run(:TYPE, key)
210
+ end
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,169 @@
1
+ module Oxblood
2
+ module Commands
3
+ module Lists
4
+ # Get an element from a list by its index
5
+ # @see http://www.redis.io/commands/lindex
6
+ #
7
+ # @param [String] key
8
+ # @param [Integer] index zero-based of element in the list
9
+ #
10
+ # @return [String] the requested element, or nil when index is out of range.
11
+ def lindex(key, index)
12
+ run(:LINDEX, key, index)
13
+ end
14
+
15
+ # Insert an element before or after another element in a list
16
+ # @see http://www.redis.io/commands/linsert
17
+ #
18
+ # @param [String] key
19
+ # @param [Symbol] place could be :before or :after
20
+ # @param [String] pivot reference value
21
+ # @param [String] value to insert
22
+ #
23
+ # @return [Integer] the length of the list after the insert operation,
24
+ # or -1 when the value pivot was not found
25
+ def linsert(key, place, pivot, value)
26
+ run(:LINSERT, key, place, pivot, value)
27
+ end
28
+
29
+ # Get the length of a list
30
+ # @see http://redis.io/commands/llen
31
+ #
32
+ # @param [String] key
33
+ #
34
+ # @return [Integer] the length of the list at key
35
+ # @return [RError] if the value stored at key is not a list
36
+ def llen(key)
37
+ run(:LLEN, key)
38
+ end
39
+
40
+ # Remove and get the first element in a list
41
+ # @see http://redis.io/commands/lpop
42
+ #
43
+ # @param [String] key
44
+ #
45
+ # @return [String, nil] the value of the first element,
46
+ # or nil when key does not exist.
47
+ def lpop(key)
48
+ run(:LPOP, key)
49
+ end
50
+
51
+ # Prepend one or multiple values to a list
52
+ # @see http://redis.io/commands/lpush
53
+ #
54
+ # @param [String] key
55
+ # @param [Array] values to prepend
56
+ #
57
+ # @return [Integer] the length of the list after the push operations
58
+ def lpush(key, *values)
59
+ run(*values.unshift(:LPUSH, key))
60
+ end
61
+
62
+ # Prepend a value to a list, only if the list exists
63
+ # @see http://www.redis.io/commands/lpushx
64
+ #
65
+ # @param [String] key
66
+ # @param [String] value
67
+ #
68
+ # @return [Integer] the length of the list after the push operation
69
+ def lpushx(key, value)
70
+ run(:LPUSHX, key, value)
71
+ end
72
+
73
+ # Get a range of elements from a list
74
+ # @see http://redis.io/commands/lrange
75
+ #
76
+ # @param [String] key
77
+ # @param [Integer] start index
78
+ # @param [Integer] stop index
79
+ #
80
+ # @return [Array] list of elements in the specified range
81
+ def lrange(key, start, stop)
82
+ run(:LRANGE, key, start, stop)
83
+ end
84
+
85
+ # Remove elements from a list
86
+ # @see http://www.redis.io/commands/lrem
87
+ #
88
+ # @param [String] key
89
+ # @param [Integer] count (please look into official docs for more info)
90
+ # @param [String] value to remove
91
+ #
92
+ # @return [Integer] the number of removed elements
93
+ def lrem(key, count, value)
94
+ run(:LREM, key, count, value)
95
+ end
96
+
97
+ # Set the value of an element in a list by its index
98
+ # @see http://www.redis.io/commands/lset
99
+ #
100
+ # @param [String] key
101
+ # @param [Integer] index
102
+ # @param [String] value
103
+ #
104
+ # @return [String] 'OK'
105
+ # @return [RError] if index is out of range
106
+ def lset(key, index, value)
107
+ run(:LSET, key, index, value)
108
+ end
109
+
110
+ # Trim a list to the specified range
111
+ # @see http://www.redis.io/commands/ltrim
112
+ #
113
+ # @param [String] key
114
+ # @param [Integer] start
115
+ # @param [Integer] stop
116
+ #
117
+ # @return [String] 'OK'
118
+ def ltrim(key, start, stop)
119
+ run(:LTRIM, key, start, stop)
120
+ end
121
+
122
+ # Remove and get the last element in a list
123
+ # @see http://redis.io/commands/rpop
124
+ #
125
+ # @param [String] key
126
+ #
127
+ # @return [String, nil] the value of the last element, or nil when key does
128
+ # not exist
129
+ def rpop(key)
130
+ run(:RPOP, key)
131
+ end
132
+
133
+ # Remove the last element in a list, prepend it to another list and return
134
+ # @see http://www.redis.io/commands/rpoplpush
135
+ #
136
+ # @param [String] source
137
+ # @param [String] destination
138
+ #
139
+ # @return [String, nil] the element being popped and pushed, or nil when
140
+ # source does not exist
141
+ def rpoplpush(source, destination)
142
+ run(:RPOPLPUSH, source, destination)
143
+ end
144
+
145
+ # Append one or multiple values to a list
146
+ # @see http://redis.io/commands/rpush
147
+ #
148
+ # @param [String] key
149
+ # @param [Array] values to add
150
+ #
151
+ # @return [Integer] the length of the list after the push operation
152
+ # @return [RError] if key holds a value that is not a list
153
+ def rpush(key, *values)
154
+ run(*values.unshift(:RPUSH, key))
155
+ end
156
+
157
+ # Append a value to a list, only if the list exists
158
+ # @see http://www.redis.io/commands/rpushx
159
+ #
160
+ # @param [String] key
161
+ # @param [String] value
162
+ #
163
+ # @return [Integer] the length of the list after the push operation
164
+ def rpushx(key, value)
165
+ run(:RPUSHX, key, value)
166
+ end
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,24 @@
1
+ module Oxblood
2
+ module Commands
3
+ module Server
4
+ # Remove all keys from the current database
5
+ # @see http://redis.io/commands/flushdb
6
+ #
7
+ # @return [String] should always return 'OK'
8
+ def flushdb
9
+ run(:FLUSHDB)
10
+ end
11
+
12
+ # Returns information and statistics about the server in a format that is
13
+ # simple to parse by computers and easy to read by humans
14
+ # @see http://redis.io/commands/info
15
+ #
16
+ # @param [String] section used to select a specific section of information
17
+ #
18
+ # @return [String] raw redis server response as a collection of text lines.
19
+ def info(section = nil)
20
+ section ? run(:INFO, section) : run(:INFO)
21
+ end
22
+ end
23
+ end
24
+ end