redis 3.3.5 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +36 -52
  3. data/.travis/Gemfile +3 -1
  4. data/CHANGELOG.md +8 -6
  5. data/Gemfile +0 -1
  6. data/README.md +31 -75
  7. data/benchmarking/logging.rb +1 -1
  8. data/bors.toml +14 -0
  9. data/lib/redis.rb +68 -41
  10. data/lib/redis/client.rb +12 -8
  11. data/lib/redis/connection.rb +2 -2
  12. data/lib/redis/connection/command_helper.rb +2 -8
  13. data/lib/redis/connection/hiredis.rb +2 -2
  14. data/lib/redis/connection/ruby.rb +8 -28
  15. data/lib/redis/connection/synchrony.rb +12 -4
  16. data/lib/redis/distributed.rb +3 -3
  17. data/lib/redis/hash_ring.rb +20 -64
  18. data/lib/redis/pipeline.rb +0 -6
  19. data/lib/redis/version.rb +1 -1
  20. data/makefile +42 -0
  21. data/redis.gemspec +7 -9
  22. data/test/bitpos_test.rb +13 -19
  23. data/test/blocking_commands_test.rb +3 -5
  24. data/test/client_test.rb +1 -1
  25. data/test/command_map_test.rb +3 -5
  26. data/test/commands_on_hashes_test.rb +2 -4
  27. data/test/commands_on_hyper_log_log_test.rb +3 -5
  28. data/test/commands_on_lists_test.rb +2 -4
  29. data/test/commands_on_sets_test.rb +2 -4
  30. data/test/commands_on_sorted_sets_test.rb +17 -4
  31. data/test/commands_on_strings_test.rb +3 -5
  32. data/test/commands_on_value_types_test.rb +4 -6
  33. data/test/connection_handling_test.rb +5 -7
  34. data/test/distributed_blocking_commands_test.rb +2 -4
  35. data/test/distributed_commands_on_hashes_test.rb +2 -4
  36. data/test/distributed_commands_on_hyper_log_log_test.rb +2 -4
  37. data/test/distributed_commands_on_lists_test.rb +2 -4
  38. data/test/distributed_commands_on_sets_test.rb +2 -4
  39. data/test/distributed_commands_on_sorted_sets_test.rb +2 -4
  40. data/test/distributed_commands_on_strings_test.rb +2 -4
  41. data/test/distributed_commands_on_value_types_test.rb +2 -4
  42. data/test/distributed_commands_requiring_clustering_test.rb +1 -3
  43. data/test/distributed_connection_handling_test.rb +1 -3
  44. data/test/distributed_internals_test.rb +8 -19
  45. data/test/distributed_key_tags_test.rb +4 -6
  46. data/test/distributed_persistence_control_commands_test.rb +1 -3
  47. data/test/distributed_publish_subscribe_test.rb +1 -3
  48. data/test/distributed_remote_server_control_commands_test.rb +1 -3
  49. data/test/distributed_scripting_test.rb +1 -3
  50. data/test/distributed_sorting_test.rb +1 -3
  51. data/test/distributed_test.rb +12 -14
  52. data/test/distributed_transactions_test.rb +1 -3
  53. data/test/encoding_test.rb +4 -8
  54. data/test/error_replies_test.rb +2 -4
  55. data/test/fork_safety_test.rb +1 -6
  56. data/test/helper.rb +10 -41
  57. data/test/helper_test.rb +1 -3
  58. data/test/internals_test.rb +67 -55
  59. data/test/lint/strings.rb +6 -20
  60. data/test/lint/value_types.rb +8 -0
  61. data/test/persistence_control_commands_test.rb +1 -3
  62. data/test/pipelining_commands_test.rb +4 -8
  63. data/test/publish_subscribe_test.rb +1 -3
  64. data/test/remote_server_control_commands_test.rb +60 -3
  65. data/test/scanning_test.rb +1 -7
  66. data/test/scripting_test.rb +1 -3
  67. data/test/sentinel_command_test.rb +1 -3
  68. data/test/sentinel_test.rb +1 -3
  69. data/test/sorting_test.rb +1 -3
  70. data/test/ssl_test.rb +45 -49
  71. data/test/support/connection/hiredis.rb +1 -1
  72. data/test/support/connection/ruby.rb +1 -1
  73. data/test/support/connection/synchrony.rb +1 -1
  74. data/test/synchrony_driver.rb +6 -9
  75. data/test/thread_safety_test.rb +1 -3
  76. data/test/transactions_test.rb +1 -3
  77. data/test/unknown_commands_test.rb +1 -3
  78. data/test/url_param_test.rb +44 -46
  79. metadata +30 -18
  80. data/Rakefile +0 -87
  81. data/test/connection_test.rb +0 -57
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 729f56810aa501065e2fc203050363713c80ee37
4
- data.tar.gz: e7e13fb75618f794a2c742d73d6c8a72699d5e92
3
+ metadata.gz: 0f10522316b60319f14cbbf00cf0c82f13092997
4
+ data.tar.gz: 1aab75c09b750f2f2f5038cc14366b3c79e0e01c
5
5
  SHA512:
6
- metadata.gz: f87e76c751760b7f1feb7c859ea373c41ebf805c104c27e85177cb20a60d42b11c50db2d5a916fb7bfc78b82b13141770a851568aea922ccc1970f4e30ba1dea
7
- data.tar.gz: ac4cb236c9c9897d73ead9421e161cf1c7aac2a3c1f77c088b5c52c324cddccda6ab749441093cbcc94ea812e70232f9f9ac1c160a96fd1fbd46d87586d1d7fb
6
+ metadata.gz: 78b8a72a6bc475aa55543abf515b3758af1a696a3f1adcaa9019898bf99acf0162383964880b1e6d07113205d0129ed84563de44a4680f9f15cc5893c44efae0
7
+ data.tar.gz: ad7ed9b0a0afb0a6c85bf5cd9cada2081c64b3b25856e0343bef61a62e2f4c7f376f42c32013092ec4dde55ed4182c6b11d1f0ace54167f49a597181abdbcf29
data/.travis.yml CHANGED
@@ -1,87 +1,71 @@
1
1
  language: ruby
2
2
 
3
+ script: make test
4
+
3
5
  rvm:
4
- - 1.8.7
5
- - 1.9.3
6
- - 2.0
7
- - 2.1
8
- - 2.2
9
- - 2.3.0
10
- - jruby-18mode
11
- - jruby-19mode
12
- - jruby-9.0.5.0
13
- - rbx-2
6
+ - 2.2.2
7
+ - 2.3.3
8
+ - 2.4.1
9
+ - jruby-9
10
+ - rbx-3
14
11
 
15
12
  gemfile: ".travis/Gemfile"
16
13
 
17
14
  sudo: false
18
15
 
16
+ before_script:
17
+ - if (ruby -e "exit RUBY_VERSION.to_f >= 2.4"); then export RUBYOPT="--enable-frozen-string-literal"; fi; echo $RUBYOPT
18
+
19
19
  env:
20
20
  global:
21
21
  - VERBOSE=true
22
22
  - TIMEOUT=1
23
23
  matrix:
24
- - conn=ruby REDIS_BRANCH=3.0
25
- - conn=ruby REDIS_BRANCH=3.2
26
- - conn=hiredis REDIS_BRANCH=3.0
27
- - conn=hiredis REDIS_BRANCH=3.2
28
- - conn=synchrony REDIS_BRANCH=3.0
29
- - conn=synchrony REDIS_BRANCH=3.2
30
- - conn=ruby REDIS_BRANCH=unstable
24
+ - DRIVER=ruby REDIS_BRANCH=3.0
25
+ - DRIVER=ruby REDIS_BRANCH=3.2
26
+ - DRIVER=hiredis REDIS_BRANCH=3.0
27
+ - DRIVER=hiredis REDIS_BRANCH=3.2
28
+ - DRIVER=synchrony REDIS_BRANCH=3.0
29
+ - DRIVER=synchrony REDIS_BRANCH=3.2
30
+ - DRIVER=ruby REDIS_BRANCH=unstable
31
31
 
32
32
  branches:
33
33
  only:
34
+ - staging
35
+ - trying
34
36
  - master
35
37
 
36
38
  matrix:
37
39
  exclude:
38
40
  # hiredis
39
- - rvm: jruby-18mode
40
- gemfile: .travis/Gemfile
41
- env: conn=hiredis REDIS_BRANCH=3.0
42
- - rvm: jruby-18mode
43
- gemfile: .travis/Gemfile
44
- env: conn=hiredis REDIS_BRANCH=3.2
45
- - rvm: jruby-19mode
41
+ - rvm: jruby-9
46
42
  gemfile: .travis/Gemfile
47
- env: conn=hiredis REDIS_BRANCH=3.0
48
- - rvm: jruby-19mode
43
+ env: DRIVER=hiredis REDIS_BRANCH=3.0
44
+ - rvm: jruby-9
49
45
  gemfile: .travis/Gemfile
50
- env: conn=hiredis REDIS_BRANCH=3.2
51
- - rvm: jruby-9.0.5.0
46
+ env: DRIVER=hiredis REDIS_BRANCH=3.2
47
+ - rvm: jruby-9
52
48
  gemfile: .travis/Gemfile
53
- env: conn=hiredis REDIS_BRANCH=3.0
54
- - rvm: jruby-9.0.5.0
49
+ env: DRIVER=hiredis REDIS_BRANCH=3.0
50
+ - rvm: jruby-9
55
51
  gemfile: .travis/Gemfile
56
- env: conn=hiredis REDIS_BRANCH=3.2
52
+ env: DRIVER=hiredis REDIS_BRANCH=3.2
57
53
 
58
54
  # synchrony
59
- - rvm: 1.8.7
60
- gemfile: .travis/Gemfile
61
- env: conn=synchrony REDIS_BRANCH=3.0
62
- - rvm: 1.8.7
63
- gemfile: .travis/Gemfile
64
- env: conn=synchrony REDIS_BRANCH=3.2
65
- - rvm: jruby-18mode
66
- gemfile: .travis/Gemfile
67
- env: conn=synchrony REDIS_BRANCH=3.0
68
- - rvm: jruby-18mode
69
- gemfile: .travis/Gemfile
70
- env: conn=synchrony REDIS_BRANCH=3.2
71
- - rvm: jruby-19mode
55
+ - rvm: jruby-9
72
56
  gemfile: .travis/Gemfile
73
- env: conn=synchrony REDIS_BRANCH=3.0
74
- - rvm: jruby-19mode
57
+ env: DRIVER=synchrony REDIS_BRANCH=3.0
58
+ - rvm: jruby-9
75
59
  gemfile: .travis/Gemfile
76
- env: conn=synchrony REDIS_BRANCH=3.2
77
- - rvm: jruby-9.0.5.0
60
+ env: DRIVER=synchrony REDIS_BRANCH=3.2
61
+ - rvm: jruby-9
78
62
  gemfile: .travis/Gemfile
79
- env: conn=synchrony REDIS_BRANCH=3.0
80
- - rvm: jruby-9.0.5.0
63
+ env: DRIVER=synchrony REDIS_BRANCH=3.0
64
+ - rvm: jruby-9
81
65
  gemfile: .travis/Gemfile
82
- env: conn=synchrony REDIS_BRANCH=3.2
66
+ env: DRIVER=synchrony REDIS_BRANCH=3.2
83
67
  allow_failures:
84
- - rvm: rbx-2
68
+ - rvm: rbx-3
85
69
 
86
70
  notifications:
87
71
  irc:
data/.travis/Gemfile CHANGED
@@ -2,10 +2,12 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec :path => "../"
4
4
 
5
- case ENV["conn"]
5
+ case ENV["DRIVER"]
6
6
  when "hiredis"
7
7
  gem "hiredis"
8
8
  when "synchrony"
9
9
  gem "hiredis"
10
10
  gem "em-synchrony"
11
11
  end
12
+
13
+ gem 'test-unit', '>= 3.2.5'
data/CHANGELOG.md CHANGED
@@ -1,11 +1,13 @@
1
- # 3.3.5
1
+ # 4.0 (unreleased)
2
2
 
3
- * Fixed Ruby 1.8 compatibility after backporting `Redis#connection`. See #719.
3
+ * Removed `Redis.connect`. Use `Redis.new`.
4
4
 
5
- # 3.3.4
5
+ * Removed `Redis#[]` and `Redis#[]=` aliases.
6
6
 
7
- * `Redis#connection` returns a hash with connection information.
8
- You shouldn't need to call `Redis#_client`, ever.
7
+ * Added support for `CLIENT` commands. The lower-level client can be
8
+ accessed via `Redis#_client`.
9
+
10
+ * Dropped official support for Ruby < 2.2.2.
9
11
 
10
12
  # 3.3.3
11
13
 
@@ -13,7 +15,7 @@
13
15
 
14
16
  # 3.3.2
15
17
 
16
- * Added support for SPOP with COUNT. See #628.
18
+ * Added support for `SPOP` with COUNT. See #628.
17
19
 
18
20
  * Fixed connection glitches when using SSL. See #644.
19
21
 
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  source 'https://rubygems.org'
3
2
 
4
3
  gemspec
data/README.md CHANGED
@@ -1,46 +1,17 @@
1
1
  # redis-rb [![Build Status][travis-image]][travis-link] [![Inline docs][inchpages-image]][inchpages-link]
2
2
 
3
- [travis-image]: https://secure.travis-ci.org/redis/redis-rb.png?branch=master
4
- [travis-link]: http://travis-ci.org/redis/redis-rb
5
- [travis-home]: http://travis-ci.org/
6
- [inchpages-image]: http://inch-ci.org/github/redis/redis-rb.png
7
- [inchpages-link]: http://inch-ci.org/github/redis/redis-rb
3
+ A Ruby client that tries to match [Redis][redis-home]' API one-to-one, while still
4
+ providing an idiomatic interface.
8
5
 
9
- A Ruby client library for [Redis][redis-home].
10
-
11
- [redis-home]: http://redis.io
12
-
13
- A Ruby client that tries to match Redis' API one-to-one, while still
14
- providing an idiomatic interface. It features thread-safety, client-side
15
- sharding, pipelining, and an obsession for performance.
16
-
17
- ## Upgrading from 2.x to 3.0
18
-
19
- Please refer to the [CHANGELOG][changelog-3.0.0] for a summary of the
20
- most important changes, as well as a full list of changes.
21
-
22
- [changelog-3.0.0]: https://github.com/redis/redis-rb/blob/master/CHANGELOG.md#300
23
6
 
24
7
  ## Getting started
25
8
 
26
- To install **redis-rb**, run the following command:
27
-
28
- ```
29
- gem install redis
30
- ```
31
-
32
- Or if you are using **bundler**, add
9
+ Install with:
33
10
 
34
11
  ```
35
- gem 'redis', '~>3.2'
12
+ $ gem install redis
36
13
  ```
37
14
 
38
- to your `Gemfile`, and run `bundle install`
39
-
40
- As of version 2.0 this client only targets Redis version 2.0 and higher.
41
- You can use an older version of this client if you need to interface
42
- with a Redis instance older than 2.0, but this is no longer supported.
43
-
44
15
  You can connect to Redis by instantiating the `Redis` class:
45
16
 
46
17
  ```ruby
@@ -54,17 +25,15 @@ listening on `localhost`, port 6379. If you need to connect to a remote
54
25
  server or a different port, try:
55
26
 
56
27
  ```ruby
57
- redis = Redis.new(:host => "10.0.1.1", :port => 6380, :db => 15)
28
+ redis = Redis.new(host: "10.0.1.1", port: 6380, db: 15)
58
29
  ```
59
30
 
60
31
  You can also specify connection options as a [`redis://` URL][redis-url]:
61
32
 
62
33
  ```ruby
63
- redis = Redis.new(:url => "redis://:p4ssw0rd@10.0.1.1:6380/15")
34
+ redis = Redis.new(url: "redis://:p4ssw0rd@10.0.1.1:6380/15")
64
35
  ```
65
36
 
66
- [redis-url]: http://www.iana.org/assignments/uri-schemes/prov/redis
67
-
68
37
  By default, the client will try to read the `REDIS_URL` environment variable
69
38
  and use that as URL to connect to. The above statement is therefore equivalent
70
39
  to setting this environment variable and calling `Redis.new` without arguments.
@@ -72,13 +41,13 @@ to setting this environment variable and calling `Redis.new` without arguments.
72
41
  To connect to Redis listening on a Unix socket, try:
73
42
 
74
43
  ```ruby
75
- redis = Redis.new(:path => "/tmp/redis.sock")
44
+ redis = Redis.new(path: "/tmp/redis.sock")
76
45
  ```
77
46
 
78
47
  To connect to a password protected Redis instance, use:
79
48
 
80
49
  ```ruby
81
- redis = Redis.new(:password => "mysecret")
50
+ redis = Redis.new(password: "mysecret")
82
51
  ```
83
52
 
84
53
  The Redis class exports methods that are named identical to the commands
@@ -86,8 +55,6 @@ they execute. The arguments these methods accept are often identical to
86
55
  the arguments specified on the [Redis website][redis-commands]. For
87
56
  instance, the `SET` and `GET` commands can be called like this:
88
57
 
89
- [redis-commands]: http://redis.io/commands
90
-
91
58
  ```ruby
92
59
  redis.set("mykey", "hello world")
93
60
  # => "OK"
@@ -96,24 +63,22 @@ redis.get("mykey")
96
63
  # => "hello world"
97
64
  ```
98
65
 
99
- All commands, their arguments and return values are documented, and
100
- available on [rdoc.info][rdoc].
101
-
102
- [rdoc]: http://rdoc.info/github/redis/redis-rb/
66
+ All commands, their arguments, and return values are documented and
67
+ available on [RubyDoc.info][rubydoc].
103
68
 
104
69
  ## Sentinel support
105
70
 
106
- The client is able to perform automatic failovers by using [Redis
71
+ The client is able to perform automatic failover by using [Redis
107
72
  Sentinel](http://redis.io/topics/sentinel). Make sure to run Redis 2.8+
108
73
  if you want to use this feature.
109
74
 
110
75
  To connect using Sentinel, use:
111
76
 
112
77
  ```ruby
113
- SENTINELS = [{:host => "127.0.0.1", :port => 26380},
114
- {:host => "127.0.0.1", :port => 26381}]
78
+ SENTINELS = [{ host: "127.0.0.1", port: 26380 },
79
+ { host: "127.0.0.1", port: 26381 }]
115
80
 
116
- redis = Redis.new(:url => "redis://mymaster", :sentinels => SENTINELS, :role => :master)
81
+ redis = Redis.new(url: "redis://mymaster", sentinels: SENTINELS, role: :master)
117
82
  ```
118
83
 
119
84
  * The master name identifies a group of Redis instances composed of a master
@@ -374,37 +339,28 @@ redis = Redis.new(:driver => :synchrony)
374
339
 
375
340
  ## Testing
376
341
 
377
- This library is tested using [Travis][travis-home], where it is tested
378
- against the following interpreters and drivers:
379
-
380
- * MRI 1.8.7 (drivers: ruby, hiredis)
381
- * MRI 1.9.3 (drivers: ruby, hiredis, synchrony)
382
- * MRI 2.0 (drivers: ruby, hiredis, synchrony)
383
- * MRI 2.1 (drivers: ruby, hiredis, synchrony)
384
- * MRI 2.2 (drivers: ruby, hiredis, synchrony)
385
- * MRI 2.3 (drivers: ruby, hiredis, synchrony)
386
- * JRuby 1.7 (1.8 mode) (drivers: ruby)
387
- * JRuby 1.7 (1.9 mode) (drivers: ruby)
342
+ This library is tested against recent Ruby and Redis versions.
343
+ Check [Travis][travis-link] for the exact versions supported.
388
344
 
389
345
  ## Contributors
390
346
 
391
- (ordered chronologically with more than 5 commits, see `git shortlog -sn` for
392
- all contributors)
393
-
394
- * Ezra Zygmuntowicz
395
- * Taylor Weibley
396
- * Matthew Clark
397
- * Brian McKinney
398
- * Luca Guidi
399
- * Salvatore Sanfilippo
400
- * Chris Wanstrath
401
- * Damian Janowski
402
- * Michel Martens
403
- * Nick Quaranto
404
- * Pieter Noordhuis
405
- * Ilya Grigorik
347
+ Several people contributed to redis-rb, but we would like to especially
348
+ mention Ezra Zygmuntowicz. Ezra introduced the Ruby community to many
349
+ new cool technologies, like Redis. He wrote the first version of this
350
+ client and evangelized Redis in Rubyland. Thank you, Ezra.
406
351
 
407
352
  ## Contributing
408
353
 
409
354
  [Fork the project](https://github.com/redis/redis-rb) and send pull
410
355
  requests. You can also ask for help at `#redis-rb` on Freenode.
356
+
357
+
358
+ [inchpages-image]: https://inch-ci.org/github/redis/redis-rb.svg
359
+ [inchpages-link]: https://inch-ci.org/github/redis/redis-rb
360
+ [redis-commands]: https://redis.io/commands
361
+ [redis-home]: https://redis.io
362
+ [redis-url]: http://www.iana.org/assignments/uri-schemes/prov/redis
363
+ [travis-home]: https://travis-ci.org/
364
+ [travis-image]: https://secure.travis-ci.org/redis/redis-rb.svg?branch=master
365
+ [travis-link]: https://travis-ci.org/redis/redis-rb
366
+ [rubydoc]: https://www.rubydoc.info/gems/redis
@@ -54,7 +54,7 @@ benchmark "Default options (no logger)" do
54
54
  end
55
55
 
56
56
  logging_redises.each do |redis|
57
- logger = redis.client.logger
57
+ logger = redis._client.logger
58
58
 
59
59
  case logger
60
60
  when Logger
data/bors.toml ADDED
@@ -0,0 +1,14 @@
1
+ # Gate on Travis CI
2
+ status = ["continuous-integration/travis-ci/push"]
3
+
4
+ # Set bors's timeout to 6 hours
5
+ #
6
+ # bors's timeout should always be twice a long as the test suite takes.
7
+ # This is to allow Travis to fast-fail a test; if one of the builders
8
+ # immediately reports a failure, then bors will move on to the next batch,
9
+ # leaving the slower builders to work through the already-doomed run and
10
+ # the next one.
11
+ #
12
+ # At the time it was written, a run had taken 3 hours.
13
+ # bors's default timeout is 4 hours.
14
+ timeout_sec = 14400
data/lib/redis.rb CHANGED
@@ -1,21 +1,8 @@
1
1
  require "monitor"
2
- require "redis/errors"
2
+ require_relative "redis/errors"
3
3
 
4
4
  class Redis
5
5
 
6
- def self.deprecate(message, trace = caller[0])
7
- $stderr.puts "\n#{message} (in #{trace})"
8
- end
9
-
10
- attr :client
11
-
12
- # @deprecated The preferred way to create a new client object is using `#new`.
13
- # This method does not actually establish a connection to Redis,
14
- # in contrary to what you might expect.
15
- def self.connect(options = {})
16
- new(options)
17
- end
18
-
19
6
  def self.current
20
7
  @current ||= Redis.new
21
8
  end
@@ -119,6 +106,10 @@ class Redis
119
106
  end
120
107
  end
121
108
 
109
+ def _client
110
+ @client
111
+ end
112
+
122
113
  # Authenticate to the server.
123
114
  #
124
115
  # @param [String] password must match the password specified in the
@@ -143,10 +134,11 @@ class Redis
143
134
 
144
135
  # Ping the server.
145
136
  #
137
+ # @param [optional, String] message
146
138
  # @return [String] `PONG`
147
- def ping
139
+ def ping(message = nil)
148
140
  synchronize do |client|
149
- client.call([:ping])
141
+ client.call([:ping, message].compact)
150
142
  end
151
143
  end
152
144
 
@@ -209,6 +201,25 @@ class Redis
209
201
  end
210
202
  end
211
203
 
204
+ # Manage client connections.
205
+ #
206
+ # @param [String, Symbol] subcommand e.g. `kill`, `list`, `getname`, `setname`
207
+ # @return [String, Hash] depends on subcommand
208
+ def client(subcommand = nil, *args)
209
+ synchronize do |client|
210
+ client.call([:client, subcommand] + args) do |reply|
211
+ if subcommand.to_s == "list"
212
+ reply.lines.map do |line|
213
+ entries = line.chomp.split(/[ =]/)
214
+ Hash[entries.each_slice(2).to_a]
215
+ end
216
+ else
217
+ reply
218
+ end
219
+ end
220
+ end
221
+ end
222
+
212
223
  # Return the number of keys in the selected database.
213
224
  #
214
225
  # @return [Fixnum]
@@ -458,10 +469,16 @@ class Redis
458
469
  # @param [String] key
459
470
  # @param [String] ttl
460
471
  # @param [String] serialized_value
472
+ # @param [Hash] options
473
+ # - `:replace => Boolean`: if false, raises an error if key already exists
474
+ # @raise [Redis::CommandError]
461
475
  # @return [String] `"OK"`
462
- def restore(key, ttl, serialized_value)
476
+ def restore(key, ttl, serialized_value, options = {})
477
+ args = [:restore, key, ttl, serialized_value]
478
+ args << 'REPLACE' if options[:replace]
479
+
463
480
  synchronize do |client|
464
- client.call([:restore, key, ttl, serialized_value])
481
+ client.call(args)
465
482
  end
466
483
  end
467
484
 
@@ -477,8 +494,8 @@ class Redis
477
494
  def migrate(key, options)
478
495
  host = options[:host] || raise(RuntimeError, ":host not specified")
479
496
  port = options[:port] || raise(RuntimeError, ":port not specified")
480
- db = (options[:db] || client.db).to_i
481
- timeout = (options[:timeout] || client.timeout).to_i
497
+ db = (options[:db] || @client.db).to_i
498
+ timeout = (options[:timeout] || @client.timeout).to_i
482
499
 
483
500
  synchronize do |client|
484
501
  client.call([:migrate, host, port, key, db, timeout])
@@ -756,8 +773,6 @@ class Redis
756
773
  end
757
774
  end
758
775
 
759
- alias :[]= :set
760
-
761
776
  # Set the time to live in seconds of a key.
762
777
  #
763
778
  # @param [String] key
@@ -863,8 +878,6 @@ class Redis
863
878
  end
864
879
  end
865
880
 
866
- alias :[] :get
867
-
868
881
  # Get the values of all the given keys.
869
882
  #
870
883
  # @example
@@ -1041,7 +1054,7 @@ class Redis
1041
1054
  # Prepend one or more values to a list, creating the list if it doesn't exist
1042
1055
  #
1043
1056
  # @param [String] key
1044
- # @param [String, Array] value string value, or array of string values to push
1057
+ # @param [String, Array<String>] value string value, or array of string values to push
1045
1058
  # @return [Fixnum] the length of the list after the push operation
1046
1059
  def lpush(key, value)
1047
1060
  synchronize do |client|
@@ -1063,7 +1076,7 @@ class Redis
1063
1076
  # Append one or more values to a list, creating the list if it doesn't exist
1064
1077
  #
1065
1078
  # @param [String] key
1066
- # @param [String] value
1079
+ # @param [String, Array<String>] value string value, or array of string values to push
1067
1080
  # @return [Fixnum] the length of the list after the push operation
1068
1081
  def rpush(key, value)
1069
1082
  synchronize do |client|
@@ -1701,6 +1714,30 @@ class Redis
1701
1714
  end
1702
1715
  end
1703
1716
 
1717
+ # Count the members, with the same score in a sorted set, within the given lexicographical range.
1718
+ #
1719
+ # @example Count members matching a
1720
+ # redis.zlexcount("zset", "[a", "[a\xff")
1721
+ # # => 1
1722
+ # @example Count members matching a-z
1723
+ # redis.zlexcount("zset", "[a", "[z\xff")
1724
+ # # => 26
1725
+ #
1726
+ # @param [String] key
1727
+ # @param [String] min
1728
+ # - inclusive minimum is specified by prefixing `(`
1729
+ # - exclusive minimum is specified by prefixing `[`
1730
+ # @param [String] max
1731
+ # - inclusive maximum is specified by prefixing `(`
1732
+ # - exclusive maximum is specified by prefixing `[`
1733
+ #
1734
+ # @return [Fixnum] number of members within the specified lexicographical range
1735
+ def zlexcount(key, min, max)
1736
+ synchronize do |client|
1737
+ client.call([:zlexcount, key, min, max])
1738
+ end
1739
+ end
1740
+
1704
1741
  # Return a range of members with the same score in a sorted set, by lexicographical ordering
1705
1742
  #
1706
1743
  # @example Retrieve members matching a
@@ -2700,16 +2737,6 @@ class Redis
2700
2737
  self.class.new(@options)
2701
2738
  end
2702
2739
 
2703
- def connection
2704
- {
2705
- :host => @original_client.host,
2706
- :port => @original_client.port,
2707
- :db => @original_client.db,
2708
- :id => @original_client.id,
2709
- :location => @original_client.location
2710
- }
2711
- end
2712
-
2713
2740
  def method_missing(command, *args)
2714
2741
  synchronize do |client|
2715
2742
  client.call([command] + args)
@@ -2781,8 +2808,8 @@ private
2781
2808
 
2782
2809
  end
2783
2810
 
2784
- require "redis/version"
2785
- require "redis/connection"
2786
- require "redis/client"
2787
- require "redis/pipeline"
2788
- require "redis/subscribe"
2811
+ require_relative "redis/version"
2812
+ require_relative "redis/connection"
2813
+ require_relative "redis/client"
2814
+ require_relative "redis/pipeline"
2815
+ require_relative "redis/subscribe"