зеркало из https://github.com/github/memcached.git
Allow to configure the codec (#195)
Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
This commit is contained in:
Родитель
d0e8d7e9fb
Коммит
2915fb9d85
|
@ -23,7 +23,7 @@ module Memcached
|
|||
def initialize(config = "localhost:11211", options = {})
|
||||
options = DEFAULTS.merge(options)
|
||||
|
||||
@codec = Memcached::MarshalCodec
|
||||
@codec = options.delete(:codec) || Memcached::MarshalCodec
|
||||
@default_ttl = options.delete(:ttl) || 0
|
||||
@prefix = options.delete(:prefix_key)
|
||||
@credentials = options.delete(:credentials)
|
||||
|
|
|
@ -175,6 +175,31 @@ class ClientTest < BaseTest
|
|||
assert(failed < keys.size / 3, "#{failed} failed out of #{keys.size}")
|
||||
end
|
||||
|
||||
module YAMLCodec
|
||||
extend self
|
||||
|
||||
FLAG = Memcached::Client::FLAG_ENCODED
|
||||
|
||||
def encode(key, value, flags)
|
||||
[ YAML.dump(value), flags | FLAG ]
|
||||
end
|
||||
|
||||
def decode(key, value, flags)
|
||||
if (flags & FLAG) != 0
|
||||
YAML.load(value)
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_custom_codec
|
||||
cache = Memcached::Client.new(@servers, codec: YAMLCodec)
|
||||
cache.set("yaml", :symbol)
|
||||
assert_equal :symbol, cache.get("yaml")
|
||||
assert_equal YAML.dump(:symbol), cache.get("yaml", raw: true)
|
||||
end
|
||||
|
||||
# Touch command
|
||||
|
||||
def test_touch_missing_key
|
||||
|
|
Загрузка…
Ссылка в новой задаче