зеркало из https://github.com/github/memcached.git
client: Use Memcached's default syntax for weight
A server's weight is now defined by an optional `/?weight` at the end of the server string. This matches the official syntax in Memcached and reduces ambiguities (e.g. in cases where you want to use a server without specifying a port but specifying its weight).
This commit is contained in:
Родитель
c6e00847fa
Коммит
0544f5ea56
|
@ -18,7 +18,6 @@ module Memcached
|
|||
# :poll_max_retries => 1, TODO: doesnt exist anymore
|
||||
:connect_timeout => 0.25,
|
||||
:hash_with_prefix_key => true,
|
||||
:default_weight => 8,
|
||||
:server_failure_limit => 2,
|
||||
:verify_key => true,
|
||||
}
|
||||
|
@ -30,7 +29,6 @@ module Memcached
|
|||
|
||||
@codec = Memcached::MarshalCodec
|
||||
@default_ttl = options.delete(:ttl) || 0
|
||||
@default_weight = options.delete(:default_weight) || 1
|
||||
@prefix = options.delete(:prefix_key)
|
||||
|
||||
@connection = nil
|
||||
|
@ -139,7 +137,7 @@ module Memcached
|
|||
end
|
||||
|
||||
private
|
||||
def create_config_str(servers, extra = nil)
|
||||
def create_config_str(servers)
|
||||
if servers.is_a?(String)
|
||||
return servers if servers.include? '--'
|
||||
servers = [servers]
|
||||
|
@ -149,18 +147,18 @@ module Memcached
|
|||
|
||||
config = servers.map do |server|
|
||||
server = server.to_s
|
||||
if File.socket?(server)
|
||||
hostname = server.gsub(/\/\?\d+$/, '')
|
||||
|
||||
if hostname =~ /^[\w\.-]+(:\d{1,5})?$/
|
||||
"--SERVER=#{server}"
|
||||
elsif File.socket?(hostname)
|
||||
"--SOCKET=\"#{server}\""
|
||||
else
|
||||
host, port, weight = server.split(":")
|
||||
port = (port && !port.empty?) ? ":#{port}" : ""
|
||||
weight = (weight && !weight.empty?) ? "/?#{weight}" : ""
|
||||
"--SERVER=#{host}#{port}#{weight}"
|
||||
raise ArgumentError, "not a valid server address: #{server}"
|
||||
end
|
||||
end.join(' ')
|
||||
config << " #{extra.strip}" if extra
|
||||
config << " --VERIFY-KEY" unless config.include? "--VERIFY-KEY"
|
||||
config
|
||||
end
|
||||
config << "--VERIFY-KEY"
|
||||
config.join(' ')
|
||||
end
|
||||
|
||||
def normalize_behaviors(options)
|
||||
|
|
|
@ -42,7 +42,7 @@ class ClientInitializeTest < BaseTest
|
|||
end
|
||||
|
||||
def test_initialize_with_ports_and_weights
|
||||
client = Memcached::Client.new ['localhost:43042:2', 'localhost:43043:10']
|
||||
client = Memcached::Client.new ['localhost:43042/?2', 'localhost:43043/?10']
|
||||
assert_includes client.config, '--SERVER=localhost:43042/?2'
|
||||
assert_includes client.config, '--SERVER=localhost:43043/?10'
|
||||
end
|
||||
|
|
|
@ -55,17 +55,17 @@ class ClientSetTest < BaseTest
|
|||
|
||||
def test_set_with_server_timeout
|
||||
socket = stub_server 43047
|
||||
cache = Memcached::Client.new("localhost:43047:1", :timeout => 0.5)
|
||||
cache = Memcached::Client.new("localhost:43047", :timeout => 0.5)
|
||||
assert_raises(Memcached::Timeout) do
|
||||
cache.set key, "v"
|
||||
end
|
||||
|
||||
cache = Memcached::Client.new("localhost:43047:1", :poll_timeout => 0.001, :rcv_timeout => 0.5)
|
||||
cache = Memcached::Client.new("localhost:43047", :poll_timeout => 0.001, :rcv_timeout => 0.5)
|
||||
assert_raises(Memcached::Timeout) do
|
||||
cache.set key, "v"
|
||||
end
|
||||
|
||||
cache = Memcached::Client.new("localhost:43047:1", :poll_timeout => 0.25, :rcv_timeout => 0.25)
|
||||
cache = Memcached::Client.new("localhost:43047", :poll_timeout => 0.25, :rcv_timeout => 0.25)
|
||||
assert_raises(Memcached::Timeout) do
|
||||
cache.set key, "v"
|
||||
end
|
||||
|
@ -75,18 +75,18 @@ class ClientSetTest < BaseTest
|
|||
|
||||
def test_set_with_no_block_server_timeout
|
||||
socket = stub_server 43048
|
||||
cache = Memcached::Client.new("localhost:43048:1", :no_block => true, :timeout => 0.25)
|
||||
cache = Memcached::Client.new("localhost:43048", :no_block => true, :timeout => 0.25)
|
||||
|
||||
assert_raises(Memcached::Timeout) do
|
||||
cache.set key, "v"
|
||||
end
|
||||
|
||||
cache = Memcached::Client.new("localhost:43048:1", :no_block => true, :poll_timeout => 0.25, :rcv_timeout => 0.001)
|
||||
cache = Memcached::Client.new("localhost:43048", :no_block => true, :poll_timeout => 0.25, :rcv_timeout => 0.001)
|
||||
assert_raises(Memcached::Timeout) do
|
||||
cache.set key, "v"
|
||||
end
|
||||
|
||||
cache = Memcached::Client.new("localhost:43048:1", :no_block => true,
|
||||
cache = Memcached::Client.new("localhost:43048", :no_block => true,
|
||||
:poll_timeout => 0.001,
|
||||
:rcv_timeout => 0.25 # No affect in no-block mode
|
||||
)
|
||||
|
|
Загрузка…
Ссылка в новой задаче