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 REDIS_RB_VENDOR_DIR=lib/vendor/redis
PWD=`pwd` PWD=`pwd`
......
...@@ -1336,13 +1336,18 @@ class Redis ...@@ -1336,13 +1336,18 @@ class Redis
end end
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 # @param [String] key
# @return [String] # @return [String]
def spop(key) # @param [Fixnum] count
def spop(key, count = nil)
synchronize do |client| synchronize do |client|
client.call([:spop, key]) if count.nil?
client.call([:spop, key])
else
client.call([:spop, key, count])
end
end end
end end
......
...@@ -451,12 +451,12 @@ class Redis ...@@ -451,12 +451,12 @@ class Redis
case options[:tcp_keepalive] case options[:tcp_keepalive]
when Hash when Hash
[:time, :intvl, :probes].each do |key| [:time, :intvl, :probes].each do |key|
unless options[:tcp_keepalive][key].is_a?(Fixnum) unless options[:tcp_keepalive][key].is_a?(Integer)
raise "Expected the #{key.inspect} key in :tcp_keepalive to be a Fixnum" raise "Expected the #{key.inspect} key in :tcp_keepalive to be an Integer"
end end
end end
when Fixnum when Integer
if options[:tcp_keepalive] >= 60 if options[:tcp_keepalive] >= 60
options[:tcp_keepalive] = {:time => options[:tcp_keepalive] - 20, :intvl => 10, :probes => 2} options[:tcp_keepalive] = {:time => options[:tcp_keepalive] - 20, :intvl => 10, :probes => 2}
......
...@@ -10,6 +10,16 @@ rescue LoadError ...@@ -10,6 +10,16 @@ rescue LoadError
# Not all systems have OpenSSL support # Not all systems have OpenSSL support
end 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 class Redis
module Connection module Connection
module SocketMixin module SocketMixin
...@@ -17,8 +27,13 @@ class Redis ...@@ -17,8 +27,13 @@ class Redis
CRLF = "\r\n".freeze CRLF = "\r\n".freeze
# Exceptions raised during non-blocking I/O ops that require retrying the op # Exceptions raised during non-blocking I/O ops that require retrying the op
NBIO_EXCEPTIONS = [Errno::EWOULDBLOCK, Errno::EAGAIN] if RUBY_VERSION >= "1.9.3"
NBIO_EXCEPTIONS << IO::WaitReadable 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) def initialize(*args)
super(*args) super(*args)
...@@ -68,21 +83,58 @@ class Redis ...@@ -68,21 +83,58 @@ class Redis
begin begin
read_nonblock(nbytes) read_nonblock(nbytes)
rescue *NBIO_EXCEPTIONS rescue *NBIO_READ_EXCEPTIONS
if IO.select([self], nil, nil, @timeout) if IO.select([self], nil, nil, @timeout)
retry retry
else else
raise Redis::TimeoutError raise Redis::TimeoutError
end end
rescue *NBIO_WRITE_EXCEPTIONS
if IO.select(nil, [self], nil, @timeout)
retry
else
raise Redis::TimeoutError
end
end end
rescue EOFError rescue EOFError
raise Errno::ECONNRESET raise Errno::ECONNRESET
end end
# UNIXSocket and TCPSocket don't support write timeouts def _write_to_socket(data)
def write(*args) begin
Timeout.timeout(@write_timeout, TimeoutError) { super } 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
end end
...@@ -255,6 +307,7 @@ class Redis ...@@ -255,6 +307,7 @@ class Redis
raise ArgumentError, "SSL incompatible with unix sockets" if config[:ssl] raise ArgumentError, "SSL incompatible with unix sockets" if config[:ssl]
sock = UNIXSocket.connect(config[:path], config[:connect_timeout]) sock = UNIXSocket.connect(config[:path], config[:connect_timeout])
elsif config[:scheme] == "rediss" || config[:ssl] 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]) sock = SSLSocket.connect(config[:host], config[:port], config[:connect_timeout], config[:ssl_params])
else else
sock = TCPSocket.connect(config[:host], config[:port], config[:connect_timeout]) sock = TCPSocket.connect(config[:host], config[:port], config[:connect_timeout])
......
...@@ -483,8 +483,8 @@ class Redis ...@@ -483,8 +483,8 @@ class Redis
end end
# Remove and return a random member from a set. # Remove and return a random member from a set.
def spop(key) def spop(key, count = nil)
node_for(key).spop(key) node_for(key).spop(key, count)
end end
# Get a random member from a set. # Get a random member from a set.
......
class Redis class Redis
VERSION = "3.3.0" VERSION = "3.3.3"
end 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