summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-08-03 07:41:31 +0000
committerDouwe Maan <douwe@gitlab.com>2017-08-03 07:41:31 +0000
commit5497af1865a448ae4a8d69a2a93b17aed100a5b8 (patch)
tree708e9b5d3b6104022a4bd35479996327ca147913
parent980eb544646cccf4dde60825452c59b13b14aa6d (diff)
parent274bddcd4b15ca2cb93c6caaf3ee17d7d9a85c14 (diff)
downloadgitlab-shell-5497af1865a448ae4a8d69a2a93b17aed100a5b8.tar.gz
Merge branch 'update-redis-rb-3.3.3' into 'master'
Bump redis-rb library to 3.3.3 See merge request !151
-rw-r--r--Makefile2
-rw-r--r--lib/vendor/redis/lib/redis.rb11
-rw-r--r--lib/vendor/redis/lib/redis/client.rb6
-rw-r--r--lib/vendor/redis/lib/redis/connection/ruby.rb65
-rw-r--r--lib/vendor/redis/lib/redis/distributed.rb4
-rw-r--r--lib/vendor/redis/lib/redis/version.rb2
6 files changed, 74 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index 2a78178..b4fd50a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-REDIS_RB_VERSION=v3.3.0
+REDIS_RB_VERSION=v3.3.3
REDIS_RB_VENDOR_DIR=lib/vendor/redis
PWD=`pwd`
diff --git a/lib/vendor/redis/lib/redis.rb b/lib/vendor/redis/lib/redis.rb
index 62dcab7..c61d483 100644
--- a/lib/vendor/redis/lib/redis.rb
+++ b/lib/vendor/redis/lib/redis.rb
@@ -1336,13 +1336,18 @@ class Redis
end
end
- # Remove and return a random member from a set.
+ # Remove and return one or more random member from a set.
#
# @param [String] key
# @return [String]
- def spop(key)
+ # @param [Fixnum] count
+ def spop(key, count = nil)
synchronize do |client|
- client.call([:spop, key])
+ if count.nil?
+ client.call([:spop, key])
+ else
+ client.call([:spop, key, count])
+ end
end
end
diff --git a/lib/vendor/redis/lib/redis/client.rb b/lib/vendor/redis/lib/redis/client.rb
index c867f63..31be2de 100644
--- a/lib/vendor/redis/lib/redis/client.rb
+++ b/lib/vendor/redis/lib/redis/client.rb
@@ -451,12 +451,12 @@ class Redis
case options[:tcp_keepalive]
when Hash
[:time, :intvl, :probes].each do |key|
- unless options[:tcp_keepalive][key].is_a?(Fixnum)
- raise "Expected the #{key.inspect} key in :tcp_keepalive to be a Fixnum"
+ unless options[:tcp_keepalive][key].is_a?(Integer)
+ raise "Expected the #{key.inspect} key in :tcp_keepalive to be an Integer"
end
end
- when Fixnum
+ when Integer
if options[:tcp_keepalive] >= 60
options[:tcp_keepalive] = {:time => options[:tcp_keepalive] - 20, :intvl => 10, :probes => 2}
diff --git a/lib/vendor/redis/lib/redis/connection/ruby.rb b/lib/vendor/redis/lib/redis/connection/ruby.rb
index e3cf002..96f1d6a 100644
--- a/lib/vendor/redis/lib/redis/connection/ruby.rb
+++ b/lib/vendor/redis/lib/redis/connection/ruby.rb
@@ -10,6 +10,16 @@ rescue LoadError
# Not all systems have OpenSSL support
end
+if RUBY_VERSION < "1.9.3"
+ class String
+ # Ruby 1.8.7 does not have byteslice, but it handles encodings differently anyway.
+ # We can simply slice the string, which is a byte array there.
+ def byteslice(*args)
+ slice(*args)
+ end
+ end
+end
+
class Redis
module Connection
module SocketMixin
@@ -17,8 +27,13 @@ class Redis
CRLF = "\r\n".freeze
# Exceptions raised during non-blocking I/O ops that require retrying the op
- NBIO_EXCEPTIONS = [Errno::EWOULDBLOCK, Errno::EAGAIN]
- NBIO_EXCEPTIONS << IO::WaitReadable if RUBY_VERSION >= "1.9.3"
+ if RUBY_VERSION >= "1.9.3"
+ NBIO_READ_EXCEPTIONS = [IO::WaitReadable]
+ NBIO_WRITE_EXCEPTIONS = [IO::WaitWritable]
+ else
+ NBIO_READ_EXCEPTIONS = [Errno::EWOULDBLOCK, Errno::EAGAIN]
+ NBIO_WRITE_EXCEPTIONS = [Errno::EWOULDBLOCK, Errno::EAGAIN]
+ end
def initialize(*args)
super(*args)
@@ -68,21 +83,58 @@ class Redis
begin
read_nonblock(nbytes)
- rescue *NBIO_EXCEPTIONS
+ rescue *NBIO_READ_EXCEPTIONS
if IO.select([self], nil, nil, @timeout)
retry
else
raise Redis::TimeoutError
end
+ rescue *NBIO_WRITE_EXCEPTIONS
+ if IO.select(nil, [self], nil, @timeout)
+ retry
+ else
+ raise Redis::TimeoutError
+ end
end
rescue EOFError
raise Errno::ECONNRESET
end
- # UNIXSocket and TCPSocket don't support write timeouts
- def write(*args)
- Timeout.timeout(@write_timeout, TimeoutError) { super }
+ def _write_to_socket(data)
+ begin
+ write_nonblock(data)
+
+ rescue *NBIO_WRITE_EXCEPTIONS
+ if IO.select(nil, [self], nil, @write_timeout)
+ retry
+ else
+ raise Redis::TimeoutError
+ end
+ rescue *NBIO_READ_EXCEPTIONS
+ if IO.select([self], nil, nil, @write_timeout)
+ retry
+ else
+ raise Redis::TimeoutError
+ end
+ end
+
+ rescue EOFError
+ raise Errno::ECONNRESET
+ end
+
+ def write(data)
+ return super(data) unless @write_timeout
+
+ length = data.bytesize
+ total_count = 0
+ loop do
+ count = _write_to_socket(data)
+
+ total_count += count
+ return total_count if total_count >= length
+ data = data.byteslice(count..-1)
+ end
end
end
@@ -255,6 +307,7 @@ class Redis
raise ArgumentError, "SSL incompatible with unix sockets" if config[:ssl]
sock = UNIXSocket.connect(config[:path], config[:connect_timeout])
elsif config[:scheme] == "rediss" || config[:ssl]
+ raise ArgumentError, "This library does not support SSL on Ruby < 1.9" if RUBY_VERSION < "1.9.3"
sock = SSLSocket.connect(config[:host], config[:port], config[:connect_timeout], config[:ssl_params])
else
sock = TCPSocket.connect(config[:host], config[:port], config[:connect_timeout])
diff --git a/lib/vendor/redis/lib/redis/distributed.rb b/lib/vendor/redis/lib/redis/distributed.rb
index 4bda232..df49148 100644
--- a/lib/vendor/redis/lib/redis/distributed.rb
+++ b/lib/vendor/redis/lib/redis/distributed.rb
@@ -483,8 +483,8 @@ class Redis
end
# Remove and return a random member from a set.
- def spop(key)
- node_for(key).spop(key)
+ def spop(key, count = nil)
+ node_for(key).spop(key, count)
end
# Get a random member from a set.
diff --git a/lib/vendor/redis/lib/redis/version.rb b/lib/vendor/redis/lib/redis/version.rb
index 3f1fbc0..b5d80d2 100644
--- a/lib/vendor/redis/lib/redis/version.rb
+++ b/lib/vendor/redis/lib/redis/version.rb
@@ -1,3 +1,3 @@
class Redis
- VERSION = "3.3.0"
+ VERSION = "3.3.3"
end