Commit 5497af18 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'update-redis-rb-3.3.3' into 'master'

Bump redis-rb library to 3.3.3

See merge request !151
parents 980eb544 274bddcd
REDIS_RB_VERSION=v3.3.0
REDIS_RB_VERSION=v3.3.3
REDIS_RB_VENDOR_DIR=lib/vendor/redis
PWD=`pwd`
......
......@@ -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
......
......@@ -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}
......
......@@ -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])
......
......@@ -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.
......
class Redis
VERSION = "3.3.0"
VERSION = "3.3.3"
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment