redis 4.2.5 → 4.3.0

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
  SHA256:
3
- metadata.gz: 862e8133262fead707e4ca317b29d0e35425e3a7861ea1a52033bc91ba61bf6d
4
- data.tar.gz: 5b2b32250d783fe58b0af54cc386f2568241644a0badc0b7247bb29b1ac94a93
3
+ metadata.gz: 5d173abb7a6c08e1feb87c9fd5ba33a2a0d907c6d045f6959d55f3234e56ceeb
4
+ data.tar.gz: 7463d58522a3db5262eeea4b95834d82ede95cf102d2375e051cf4ada1b235c3
5
5
  SHA512:
6
- metadata.gz: 2aab289f4f22b2f3a804ca7b0da4cf95e352a8d246611490d8d803edebbbc7e7c299355cd0b90e6f3ac8bc0d11e9bf3792a328c95847d32e1d984729afe66ed2
7
- data.tar.gz: d9ec8ba4d314d099e909cdddf6dfb4c3c14b853b46f45c4909ac3ba10fb1880bd9a7b0465257fa91f9a4ea6c9f82723c16c177810ac15c89fab3790d7af31ad0
6
+ metadata.gz: 0b34ab14e41e1bd63a99319f3ee5e1e7ea0c1e89581e525dfd82b77968a834525807b025f02d8ff5df4e7a994f19cc7ee4098103c70abd78ab6c22ec435a055c
7
+ data.tar.gz: 84da776467bebb7fd59333084787e484203e55b81be5031c78b44741f2b79342cc1f6f48c1f9663b15f360a3af590783ee2f403da07a3e04486e35ba70e49e01
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Unreleased
2
2
 
3
+ # 4.3.0
4
+
5
+ * Add the TYPE argument to scan and scan_each. See #985.
6
+ * Support AUTH command for ACL. See #967.
7
+
3
8
  # 4.2.5
4
9
 
5
10
  * Optimize the ruby connector write buffering. See #964.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # redis-rb [![Build Status][travis-image]][travis-link] [![Inline docs][inchpages-image]][inchpages-link] ![](https://github.com/redis/redis-rb/workflows/Test/badge.svg?branch=master)
1
+ # redis-rb [![Build Status][gh-actions-image]][gh-actions-link] [![Inline docs][inchpages-image]][inchpages-link]
2
2
 
3
3
  A Ruby client that tries to match [Redis][redis-home]' API one-to-one, while still
4
4
  providing an idiomatic interface.
@@ -54,6 +54,12 @@ To connect to a password protected Redis instance, use:
54
54
  redis = Redis.new(password: "mysecret")
55
55
  ```
56
56
 
57
+ To connect a Redis instance using [ACL](https://redis.io/topics/acl), use:
58
+
59
+ ```ruby
60
+ redis = Redis.new(username: 'myname', password: 'mysecret')
61
+ ```
62
+
57
63
  The Redis class exports methods that are named identical to the commands
58
64
  they execute. The arguments these methods accept are often identical to
59
65
  the arguments specified on the [Redis website][redis-commands]. For
@@ -440,7 +446,7 @@ redis = Redis.new(:driver => :synchrony)
440
446
  ## Testing
441
447
 
442
448
  This library is tested against recent Ruby and Redis versions.
443
- Check [Travis][travis-link] for the exact versions supported.
449
+ Check [Github Actions][gh-actions-link] for the exact versions supported.
444
450
 
445
451
  ## See Also
446
452
 
@@ -459,12 +465,11 @@ client and evangelized Redis in Rubyland. Thank you, Ezra.
459
465
  requests.
460
466
 
461
467
 
462
- [inchpages-image]: https://inch-ci.org/github/redis/redis-rb.svg
463
- [inchpages-link]: https://inch-ci.org/github/redis/redis-rb
464
- [redis-commands]: https://redis.io/commands
465
- [redis-home]: https://redis.io
466
- [redis-url]: http://www.iana.org/assignments/uri-schemes/prov/redis
467
- [travis-home]: https://travis-ci.org/
468
- [travis-image]: https://secure.travis-ci.org/redis/redis-rb.svg?branch=master
469
- [travis-link]: https://travis-ci.org/redis/redis-rb
470
- [rubydoc]: http://www.rubydoc.info/gems/redis
468
+ [inchpages-image]: https://inch-ci.org/github/redis/redis-rb.svg
469
+ [inchpages-link]: https://inch-ci.org/github/redis/redis-rb
470
+ [redis-commands]: https://redis.io/commands
471
+ [redis-home]: https://redis.io
472
+ [redis-url]: http://www.iana.org/assignments/uri-schemes/prov/redis
473
+ [gh-actions-image]: https://github.com/redis/redis-rb/workflows/Test/badge.svg
474
+ [gh-actions-link]: https://github.com/redis/redis-rb/actions
475
+ [rubydoc]: http://www.rubydoc.info/gems/redis
data/lib/redis.rb CHANGED
@@ -39,6 +39,7 @@ class Redis
39
39
  # @option options [String] :path path to server socket (overrides host and port)
40
40
  # @option options [Float] :timeout (5.0) timeout in seconds
41
41
  # @option options [Float] :connect_timeout (same as timeout) timeout for initial connect in seconds
42
+ # @option options [String] :username Username to authenticate against server
42
43
  # @option options [String] :password Password to authenticate against server
43
44
  # @option options [Integer] :db (0) Database to select after initial connect
44
45
  # @option options [Symbol] :driver Driver to use, currently supported: `:ruby`, `:hiredis`, `:synchrony`
@@ -143,12 +144,13 @@ class Redis
143
144
 
144
145
  # Authenticate to the server.
145
146
  #
146
- # @param [String] password must match the password specified in the
147
- # `requirepass` directive in the configuration file
147
+ # @param [Array<String>] args includes both username and password
148
+ # or only password
148
149
  # @return [String] `OK`
149
- def auth(password)
150
+ # @see https://redis.io/commands/auth AUTH command
151
+ def auth(*args)
150
152
  synchronize do |client|
151
- client.call([:auth, password])
153
+ client.call([:auth, *args])
152
154
  end
153
155
  end
154
156
 
@@ -2636,12 +2638,13 @@ class Redis
2636
2638
  _eval(:evalsha, args)
2637
2639
  end
2638
2640
 
2639
- def _scan(command, cursor, args, match: nil, count: nil, &block)
2641
+ def _scan(command, cursor, args, match: nil, count: nil, type: nil, &block)
2640
2642
  # SSCAN/ZSCAN/HSCAN already prepend the key to +args+.
2641
2643
 
2642
2644
  args << cursor
2643
2645
  args << "MATCH" << match if match
2644
2646
  args << "COUNT" << count if count
2647
+ args << "TYPE" << type if type
2645
2648
 
2646
2649
  synchronize do |client|
2647
2650
  client.call([command] + args, &block)
@@ -2656,11 +2659,15 @@ class Redis
2656
2659
  # @example Retrieve a batch of keys matching a pattern
2657
2660
  # redis.scan(4, :match => "key:1?")
2658
2661
  # # => ["92", ["key:13", "key:18"]]
2662
+ # @example Retrieve a batch of keys of a certain type
2663
+ # redis.scan(92, :type => "zset")
2664
+ # # => ["173", ["sortedset:14", "sortedset:78"]]
2659
2665
  #
2660
2666
  # @param [String, Integer] cursor the cursor of the iteration
2661
2667
  # @param [Hash] options
2662
2668
  # - `:match => String`: only return keys matching the pattern
2663
2669
  # - `:count => Integer`: return count keys at most per iteration
2670
+ # - `:type => String`: return keys only of the given type
2664
2671
  #
2665
2672
  # @return [String, Array<String>] the next cursor and all found keys
2666
2673
  def scan(cursor, **options)
@@ -2676,10 +2683,15 @@ class Redis
2676
2683
  # redis.scan_each(:match => "key:1?") {|key| puts key}
2677
2684
  # # => key:13
2678
2685
  # # => key:18
2686
+ # @example Execute block for each key of a type
2687
+ # redis.scan_each(:type => "hash") {|key| puts redis.type(key)}
2688
+ # # => "hash"
2689
+ # # => "hash"
2679
2690
  #
2680
2691
  # @param [Hash] options
2681
2692
  # - `:match => String`: only return keys matching the pattern
2682
2693
  # - `:count => Integer`: return count keys at most per iteration
2694
+ # - `:type => String`: return keys only of the given type
2683
2695
  #
2684
2696
  # @return [Enumerator] an enumerator for all found keys
2685
2697
  def scan_each(**options, &block)
data/lib/redis/client.rb CHANGED
@@ -17,6 +17,7 @@ class Redis
17
17
  write_timeout: nil,
18
18
  connect_timeout: nil,
19
19
  timeout: 5.0,
20
+ username: nil,
20
21
  password: nil,
21
22
  db: 0,
22
23
  driver: nil,
@@ -61,6 +62,10 @@ class Redis
61
62
  @options[:read_timeout]
62
63
  end
63
64
 
65
+ def username
66
+ @options[:username]
67
+ end
68
+
64
69
  def password
65
70
  @options[:password]
66
71
  end
@@ -110,7 +115,7 @@ class Redis
110
115
  # Don't try to reconnect when the connection is fresh
111
116
  with_reconnect(false) do
112
117
  establish_connection
113
- call [:auth, password] if password
118
+ call [:auth, username, password].compact if username || password
114
119
  call [:select, db] if db != 0
115
120
  call [:client, :setname, @options[:id]] if @options[:id]
116
121
  @connector.check(self)
@@ -131,7 +136,7 @@ class Redis
131
136
  reply = process([command]) { read }
132
137
  raise reply if reply.is_a?(CommandError)
133
138
 
134
- if block_given?
139
+ if block_given? && reply != 'QUEUED'
135
140
  yield reply
136
141
  else
137
142
  reply
@@ -434,7 +439,8 @@ class Redis
434
439
  defaults[:scheme] = uri.scheme
435
440
  defaults[:host] = uri.host if uri.host
436
441
  defaults[:port] = uri.port if uri.port
437
- defaults[:password] = CGI.unescape(uri.password) if uri.password
442
+ defaults[:username] = CGI.unescape(uri.user) if uri.user && !uri.user.empty?
443
+ defaults[:password] = CGI.unescape(uri.password) if uri.password && !uri.password.empty?
438
444
  defaults[:db] = uri.path[1..-1].to_i if uri.path
439
445
  defaults[:role] = :master
440
446
  else
@@ -510,7 +516,7 @@ class Redis
510
516
  require_relative "connection/#{driver}"
511
517
  rescue LoadError, NameError
512
518
  begin
513
- require "connection/#{driver}"
519
+ require "redis/connection/#{driver}"
514
520
  rescue LoadError, NameError => error
515
521
  raise "Cannot load driver #{driver.inspect}: #{error.message}"
516
522
  end
@@ -579,6 +585,7 @@ class Redis
579
585
  client = Client.new(@options.merge({
580
586
  host: sentinel[:host] || sentinel["host"],
581
587
  port: sentinel[:port] || sentinel["port"],
588
+ username: sentinel[:username] || sentinel["username"],
582
589
  password: sentinel[:password] || sentinel["password"],
583
590
  reconnect_attempts: 0
584
591
  }))
data/lib/redis/cluster.rb CHANGED
@@ -128,7 +128,7 @@ class Redis
128
128
  def send_command(command, &block)
129
129
  cmd = command.first.to_s.downcase
130
130
  case cmd
131
- when 'auth', 'bgrewriteaof', 'bgsave', 'quit', 'save'
131
+ when 'acl', 'auth', 'bgrewriteaof', 'bgsave', 'quit', 'save'
132
132
  @node.call_all(command, &block).first
133
133
  when 'flushall', 'flushdb'
134
134
  @node.call_master(command, &block).first
@@ -18,6 +18,7 @@ class Redis
18
18
  @node_opts = build_node_options(node_addrs)
19
19
  @replica = options.delete(:replica) == true
20
20
  add_common_node_option_if_needed(options, @node_opts, :scheme)
21
+ add_common_node_option_if_needed(options, @node_opts, :username)
21
22
  add_common_node_option_if_needed(options, @node_opts, :password)
22
23
  @options = options
23
24
  end
@@ -63,7 +64,9 @@ class Redis
63
64
  raise InvalidClientOptionError, "Invalid uri scheme #{addr}" unless VALID_SCHEMES.include?(uri.scheme)
64
65
 
65
66
  db = uri.path.split('/')[1]&.to_i
66
- { scheme: uri.scheme, password: uri.password, host: uri.host, port: uri.port, db: db }.reject { |_, v| v.nil? }
67
+
68
+ { scheme: uri.scheme, username: uri.user, password: uri.password, host: uri.host, port: uri.port, db: db }
69
+ .reject { |_, v| v.nil? || v == '' }
67
70
  rescue URI::InvalidURIError => err
68
71
  raise InvalidClientOptionError, err.message
69
72
  end
@@ -79,7 +82,7 @@ class Redis
79
82
 
80
83
  # Redis cluster node returns only host and port information.
81
84
  # So we should complement additional information such as:
82
- # scheme, password and so on.
85
+ # scheme, username, password and so on.
83
86
  def add_common_node_option_if_needed(options, node_opts, key)
84
87
  return options if options[key].nil? && node_opts.first[key].nil?
85
88
 
data/lib/redis/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Redis
4
- VERSION = '4.2.5'
4
+ VERSION = '4.3.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.5
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Zygmuntowicz
@@ -16,7 +16,7 @@ authors:
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
- date: 2020-11-20 00:00:00.000000000 Z
19
+ date: 2021-06-11 00:00:00.000000000 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: em-synchrony
@@ -102,9 +102,9 @@ licenses:
102
102
  metadata:
103
103
  bug_tracker_uri: https://github.com/redis/redis-rb/issues
104
104
  changelog_uri: https://github.com/redis/redis-rb/blob/master/CHANGELOG.md
105
- documentation_uri: https://www.rubydoc.info/gems/redis/4.2.5
105
+ documentation_uri: https://www.rubydoc.info/gems/redis/4.3.0
106
106
  homepage_uri: https://github.com/redis/redis-rb
107
- source_code_uri: https://github.com/redis/redis-rb/tree/v4.2.5
107
+ source_code_uri: https://github.com/redis/redis-rb/tree/v4.3.0
108
108
  post_install_message:
109
109
  rdoc_options: []
110
110
  require_paths: