From eda665cfe4f5a4240a2fc7a2fbc4e7db6c095c22 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Sun, 13 Mar 2016 23:25:54 -0400 Subject: [PATCH] Add more options --- lib/memcached/client.rb | 15 +++++++++++++++ test/unit/client_initialize_test.rb | 22 ++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/memcached/client.rb b/lib/memcached/client.rb index 0bb48c0..ba7a034 100644 --- a/lib/memcached/client.rb +++ b/lib/memcached/client.rb @@ -144,6 +144,21 @@ But it was #{servers.inspect}. end def normalize_behaviors(options) + # UDP requires noreply + options[:noreply] = true if options[:use_udp] + + # Buffering requires non-blocking + # FIXME This should all be wrapped up in a single :pipeline option. + options[:no_block] = true if options[:buffer_requests] + + # Disallow weights without ketama + options.delete(:ketama_weighted) if options[:distribution] != :consistent_ketama + + # Disallow :sort_hosts with consistent hashing + if options[:sort_hosts] && options[:distribution] == :consistent + raise ArgumentError, ":sort_hosts defeats :consistent hashing" + end + if timeout = options.delete(:timeout) options[:rcv_timeout] ||= timeout options[:snd_timeout] ||= timeout diff --git a/test/unit/client_initialize_test.rb b/test/unit/client_initialize_test.rb index 454f8de..3fe54a8 100644 --- a/test/unit/client_initialize_test.rb +++ b/test/unit/client_initialize_test.rb @@ -88,11 +88,18 @@ class ClientInitializeTest < BaseTest assert_raises(ArgumentError) { Memcached::Client.new "local host:43043:1" } end -# def test_initialize_with_invalid_options -# assert_raise(ArgumentError) do -# Memcached.new @servers, :sort_hosts => true, :distribution => :consistent -# end -# end + def test_initialize_with_sort_host_and_consistent_distribution + assert_raises(ArgumentError) do + Memcached::Client.new @servers, :sort_hosts => true, :distribution => :consistent + end + end + + def test_initialize_with_invalid_options + assert_raises(ArgumentError) do + client = Memcached::Client.new @servers, foo: true + client.connection + end + end # def test_initialize_with_invalid_prefix_key # assert_raises(ArgumentError) do @@ -100,11 +107,6 @@ class ClientInitializeTest < BaseTest # client.connection # end # end - -# def test_initialize_without_prefix_key -# cache = Memcached.new @servers -# assert_equal 3, cache.send(:server_structs).size -# end # # def test_set_prefix_key # cache = Memcached.new @servers, :prefix_key => "foo"