Class: Dalli::Client
- Inherits:
-
Object
- Object
- Dalli::Client
- Defined in:
- lib/dalli/client.rb
Overview
Dalli::Client is the main class which developers will use to interact with Memcached.
Constant Summary collapse
- ALLOWED_STAT_KEYS =
i[items slabs settings].freeze
- CACHE_NILS =
{ cache_nils: true }.freeze
Instance Method Summary collapse
-
#add(key, value, ttl = nil, req_options = nil) ⇒ Object
Conditionally add a key/value pair, if the key does not already exist on the server.
-
#alive! ⇒ Object
Make sure memcache servers are alive, or raise an Dalli::RingError.
-
#append(key, value, req_options = nil) ⇒ Object
Append value to the value already stored on the server for 'key'.
- #cache_nils ⇒ Object
-
#cas(key, ttl = nil, req_options = nil) ⇒ Object
compare and swap values using optimistic locking.
-
#cas!(key, ttl = nil, req_options = nil) ⇒ Object
like #cas, but will yield to the block whether or not the value already exists.
-
#close ⇒ Object
(also: #reset)
Close our connection to each server.
-
#decr(key, amt = 1, ttl = nil, default = nil, req_options = nil) ⇒ Object
Decr subtracts the given amount from the counter on the memcached server.
-
#delete(key, req_options = nil) ⇒ Object
Delete a key.
-
#delete_cas(key, cas = 0, req_options = nil) ⇒ Object
Delete a key/value pair, verifying existing CAS.
-
#delete_multi(keys, req_options = nil) ⇒ Integer
Delete multiple keys efficiently using pipelining.
-
#fetch(key, ttl = nil, req_options = nil) ⇒ Object
Fetch the value associated with the key.
-
#fetch_with_lock(key, ttl: nil, lock_ttl: 30, recache_threshold: nil, req_options: nil) { ... } ⇒ Object
Fetch the value with thundering herd protection using the meta protocol's N (vivify) and R (recache) flags.
-
#flush(delay = 0) ⇒ Object
(also: #flush_all)
Flush the memcached server, at 'delay' seconds in the future.
-
#gat(key, ttl = nil, req_options = nil) ⇒ Object
Gat (get and touch) fetch an item and simultaneously update its expiration time.
-
#get(key, req_options = nil) ⇒ Object
Get the value associated with the key.
-
#get_cas(key, req_options = nil) {|value, cas| ... } ⇒ Object
Get the value and CAS ID associated with the key.
-
#get_multi(*keys, req_options: nil) ⇒ Object
Fetch multiple keys efficiently.
-
#get_multi_cas(*keys, req_options: nil) ⇒ Object
Fetch multiple keys efficiently, including available metadata such as CAS.
-
#get_multi_with_metadata(*keys, req_options: nil, &block) ⇒ Hash
Fetch multiple keys efficiently, returning a stale-aware metadata Hash per key.
-
#get_with_metadata(key, options = {}) ⇒ Hash
Get value with extended metadata.
-
#incr(key, amt = 1, ttl = nil, default = nil, req_options = nil) ⇒ Object
Incr adds the given amount to the counter on the memcached server.
-
#initialize(servers = nil, options = {}) ⇒ Client
constructor
Dalli::Client is the main class which developers will use to interact with the memcached server.
- #not_found?(val) ⇒ Boolean
-
#prepend(key, value, req_options = nil) ⇒ Object
Prepend value to the value already stored on the server for 'key'.
-
#quiet ⇒ Object
(also: #multi)
Turn on quiet aka noreply support for a number of memcached operations.
-
#replace(key, value, ttl = nil, req_options = nil) ⇒ Object
Conditionally add a key/value pair, only if the key already exists on the server.
-
#replace_cas(key, value, cas, ttl = nil, req_options = nil) ⇒ Object
Conditionally add a key/value pair, verifying existing CAS, only if the key already exists on the server.
-
#reset_stats ⇒ Object
Reset stats for each server.
- #set(key, value, ttl = nil, req_options = nil) ⇒ Object
-
#set_cas(key, value, cas, ttl = nil, req_options = nil) ⇒ Object
Set the key-value pair, verifying existing CAS.
-
#set_multi(hash, ttl = nil, req_options = nil) ⇒ void
Set multiple keys and values efficiently using pipelining.
-
#stats(type = nil) ⇒ Object
Collect the stats for each server.
-
#touch(key, ttl = nil) ⇒ Object
Touch updates expiration time for a given key.
-
#version ⇒ Object
Version of the memcache servers.
-
#with {|_self| ... } ⇒ Object
Stub method so a bare Dalli client can pretend to be a connection pool.
Constructor Details
#initialize(servers = nil, options = {}) ⇒ Client
Dalli::Client is the main class which developers will use to interact with the memcached server. Usage:
Dalli::Client.new(['localhost:11211:10',
'cache-2.example.com:11211:5',
'192.168.0.1:22122:5',
'/var/run/memcached/socket'],
failover: true, expires_in: 300)
servers is an Array of "host:port:weight" where weight allows you to distribute cache unevenly. Both weight and port are optional. If you pass in nil, Dalli will use the MEMCACHE_SERVERS environment variable or default to 'localhost:11211' if it is not present. Dalli also supports the ability to connect to Memcached on localhost through a UNIX socket. To use this functionality, use a full pathname (beginning with a slash character '/') in place of the "host:port" pair in the server configuration.
Options:
- :namespace - prepend each key with this value to provide simple namespacing.
- :failover - if a server is down, look for and store values on another server in the ring. Default: true.
- :threadsafe - ensure that only one thread is actively using a socket at a time. Default: true.
- :expires_in - default TTL in seconds if you do not pass TTL as a parameter to an individual operation, defaults to 0 or forever.
- :compress - if true Dalli will compress values larger than compression_min_size bytes before sending them to memcached. Default: true.
- :compression_min_size - the minimum size (in bytes) for which Dalli will compress values sent to Memcached. Defaults to 4K.
- :serializer - defaults to Marshal
- :compressor - defaults to Dalli::Compressor, a Zlib-based implementation
- :cache_nils - defaults to false, if true Dalli will not treat cached nil values as 'not found' for #fetch operations.
- :raw - If set, disables serialization and compression entirely at the client level. Only String values are supported. This is useful when the caller handles its own serialization (e.g., Rails' ActiveSupport::Cache). Note: this is different from the per-request :raw option which converts values to strings but still uses the serialization pipeline.
- :digest_class - defaults to Digest::MD5, allows you to pass in an object that responds to the hexdigest method, useful for injecting a FIPS compliant hash object.
- :otel_db_statement - controls the
db.query.textspan attribute when OpenTelemetry is loaded.:includelogs the full operation and key(s),:obfuscatereplaces keys with "?",nil(default) omits the attribute entirely. - :otel_peer_service - when set, adds a
peer.servicespan attribute with this value for logical service naming.
55 56 57 58 59 60 61 |
# File 'lib/dalli/client.rb', line 55 def initialize(servers = nil, = {}) @normalized_servers = ::Dalli::ServersArgNormalizer.normalize_servers(servers) = () () @key_manager = ::Dalli::KeyManager.new() @ring = nil end |
Instance Method Details
#add(key, value, ttl = nil, req_options = nil) ⇒ Object
Conditionally add a key/value pair, if the key does not already exist on the server. Returns truthy if the operation succeeded.
418 419 420 421 |
# File 'lib/dalli/client.rb', line 418 def add(key, value, ttl = nil, = nil) validate_routing_tokens!() perform(:add, key, value, ttl_or_default(ttl), ) end |
#alive! ⇒ Object
Make sure memcache servers are alive, or raise an Dalli::RingError
621 622 623 |
# File 'lib/dalli/client.rb', line 621 def alive! ring.server_for_key('') end |
#append(key, value, req_options = nil) ⇒ Object
Append value to the value already stored on the server for 'key'. Appending only works for values stored with :raw => true.
521 522 523 524 |
# File 'lib/dalli/client.rb', line 521 def append(key, value, = nil) validate_routing_tokens!() perform(:append, key, value.to_s, ) end |
#cache_nils ⇒ Object
640 641 642 |
# File 'lib/dalli/client.rb', line 640 def cache_nils [:cache_nils] end |
#cas(key, ttl = nil, req_options = nil) ⇒ Object
compare and swap values using optimistic locking. Fetch the existing value for key. If it exists, yield the value to the block. Add the block's return value as the new value for the key. Add will fail if someone else changed the value.
Returns:
- nil if the key did not exist.
- false if the value was changed by someone else.
- true if the value was successfully updated.
329 330 331 |
# File 'lib/dalli/client.rb', line 329 def cas(key, ttl = nil, = nil, &) cas_core(key, false, ttl, , &) end |
#cas!(key, ttl = nil, req_options = nil) ⇒ Object
like #cas, but will yield to the block whether or not the value already exists.
Returns:
- false if the value was changed by someone else.
- true if the value was successfully updated.
340 341 342 |
# File 'lib/dalli/client.rb', line 340 def cas!(key, ttl = nil, = nil, &) cas_core(key, true, ttl, , &) end |
#close ⇒ Object Also known as: reset
Close our connection to each server. If you perform another operation after this, the connections will be re-established.
628 629 630 631 |
# File 'lib/dalli/client.rb', line 628 def close @ring&.close @ring = nil end |
#decr(key, amt = 1, ttl = nil, default = nil, req_options = nil) ⇒ Object
Decr subtracts the given amount from the counter on the memcached server. Amt must be a positive integer value.
memcached counters are unsigned and cannot hold negative values. Calling decr on a counter which is 0 will just return 0.
If default is nil, the counter must already exist or the operation will fail and will return nil. Otherwise this method will return the new value for the counter.
Note that the ttl will only apply if the counter does not already exist. To decrease an existing counter and update its TTL, use #cas.
If the value already exists, it must have been set with raw: true
570 571 572 573 574 575 |
# File 'lib/dalli/client.rb', line 570 def decr(key, amt = 1, ttl = nil, default = nil, = nil) check_positive!(amt) validate_routing_tokens!() perform(:decr, key, amt.to_i, ttl_or_default(ttl), default, ) end |
#delete(key, req_options = nil) ⇒ Object
Delete a key.
req_options may include the memcached meta-delete options:
-
:invalidate(Boolean) — mark the item stale instead of removing it. This is the tombstone: readers seestale: truefrom #get_with_metadata and #get_multi_with_metadata, and the existing value is still readable unless:drop_valueis also set. A tombstoned key is not a miss, which lets a reader tell "another process is repopulating this" apart from "this was never here". -
:tombstone_ttl(Integer seconds) — how long the stale marker lives. Requires:invalidate; memcached only honors the TTL on a delete when it accompanies the invalidate flag, so passing it alone raises ArgumentError rather than sending a request the server would treat differently than intended. Once it elapses, reads see a miss. -
:drop_value(Boolean) — remove the item's value but leave the item, so a tombstone need not retain the old payload. On its own it is not a tombstone: reads are an ordinary hit with an empty value. -
:p_token/:l_token(String) — opaque routing tokens for an intermediate proxy or router; see #get.dc.delete('key', invalidate: true, tombstone_ttl: 30, drop_value: true)
476 477 478 |
# File 'lib/dalli/client.rb', line 476 def delete(key, = nil) delete_cas(key, 0, ) end |
#delete_cas(key, cas = 0, req_options = nil) ⇒ Object
Delete a key/value pair, verifying existing CAS. Returns true if succeeded, and falsy otherwise. Delete a key, optionally with a CAS check.
req_options accepts the same meta-delete options as #delete.
444 445 446 447 448 |
# File 'lib/dalli/client.rb', line 444 def delete_cas(key, cas = 0, = nil) () validate_routing_tokens!() perform(:delete, key, cas, ) end |
#delete_multi(keys, req_options = nil) ⇒ Integer
Delete multiple keys efficiently using pipelining. This method is more efficient than calling delete() in a loop because it batches requests by server and uses quiet mode.
req_options accepts the same meta-delete options as #delete and applies
them to every key in the batch.
Example:
client.delete_multi(['key1', 'key2', 'key3'])
client.delete_multi(%w[key1 key2], invalidate: true, tombstone_ttl: 30)
503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
# File 'lib/dalli/client.rb', line 503 def delete_multi(keys, = nil) return 0 if keys.empty? () validate_routing_tokens!() Instrumentation.trace('delete_multi', multi_trace_attrs('delete_multi', keys.size, keys)) do if ring.servers.size == 1 single_server_delete_multi(keys, ) else pipelined_deleter.process(keys, ) end end end |
#fetch(key, ttl = nil, req_options = nil) ⇒ Object
Fetch the value associated with the key. If a value is found, then it is returned.
If a value is not found and no block is given, then nil is returned.
If a value is not found (or if the found value is nil and :cache_nils is false) and a block is given, the block will be invoked and its return value written to the cache and returned.
261 262 263 264 265 266 267 268 269 |
# File 'lib/dalli/client.rb', line 261 def fetch(key, ttl = nil, = nil) = .nil? ? CACHE_NILS : .merge(CACHE_NILS) if cache_nils val = get(key, ) return val unless block_given? && not_found?(val) new_val = yield add(key, new_val, ttl_or_default(ttl), ) new_val end |
#fetch_with_lock(key, ttl: nil, lock_ttl: 30, recache_threshold: nil, req_options: nil) { ... } ⇒ Object
Fetch the value with thundering herd protection using the meta protocol's N (vivify) and R (recache) flags.
This method prevents multiple clients from simultaneously regenerating the same cache entry (the "thundering herd" problem). Only one client wins the right to regenerate; other clients receive the stale value (if available) or wait.
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/dalli/client.rb', line 301 def fetch_with_lock(key, ttl: nil, lock_ttl: 30, recache_threshold: nil, req_options: nil, &block) raise ArgumentError, 'Block is required for fetch_with_lock' unless block_given? validate_routing_tokens!() key = key.to_s key = @key_manager.validate_key(key) server = ring.server_for_key(key) Instrumentation.trace('fetch_with_lock', trace_attrs('fetch_with_lock', key, server)) do fetch_with_lock_request(key, ttl, lock_ttl, recache_threshold, , &block) end rescue NetworkError => e Dalli.logger.debug { e.inspect } Dalli.logger.debug { 'retrying fetch_with_lock with new server' } retry end |
#flush(delay = 0) ⇒ Object Also known as: flush_all
Flush the memcached server, at 'delay' seconds in the future. Delay defaults to zero seconds, which means an immediate flush.
581 582 583 |
# File 'lib/dalli/client.rb', line 581 def flush(delay = 0) ring.servers.map { |s| s.request(:flush, delay) } end |
#gat(key, ttl = nil, req_options = nil) ⇒ Object
Gat (get and touch) fetch an item and simultaneously update its expiration time.
If a value is not found, then nil is returned.
79 80 81 82 |
# File 'lib/dalli/client.rb', line 79 def gat(key, ttl = nil, = nil) validate_routing_tokens!() perform(:gat, key, ttl_or_default(ttl), ) end |
#get(key, req_options = nil) ⇒ Object
Get the value associated with the key.
If a value is not found, then nil is returned.
70 71 72 73 |
# File 'lib/dalli/client.rb', line 70 def get(key, = nil) validate_routing_tokens!() perform(:get, key, ) end |
#get_cas(key, req_options = nil) {|value, cas| ... } ⇒ Object
Get the value and CAS ID associated with the key. If a block is provided, value and CAS will be passed to the block.
96 97 98 99 100 101 102 |
# File 'lib/dalli/client.rb', line 96 def get_cas(key, = nil) validate_routing_tokens!() (value, cas) = perform(:cas, key, ) return [value, cas] unless block_given? yield value, cas end |
#get_multi(*keys, req_options: nil) ⇒ Object
Fetch multiple keys efficiently. If a block is given, yields key/value pairs one at a time. Otherwise returns a hash of { 'key' => 'value', 'key2' => 'value1' }
req_options accepts :p_token/:l_token, applied to every key in the batch.
A transient network error is retried automatically. If a server remains unreachable after retrying, raises Dalli::NetworkError rather than silently omitting that server's keys from the result.
rubocop:disable Style/ExplicitBlockArgument
166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/dalli/client.rb', line 166 def get_multi(*keys, req_options: nil) keys.flatten! keys.compact! return {} if keys.empty? validate_routing_tokens!() if block_given? get_multi_yielding(keys, ) { |k, v| yield k, v } else get_multi_hash(keys, ) end end |
#get_multi_cas(*keys, req_options: nil) ⇒ Object
Fetch multiple keys efficiently, including available metadata such as CAS. If a block is given, yields key/data pairs one a time. Data is an array: [value, cas_id] If no block is given, returns a hash of { 'key' => [value, cas_id] }
req_options accepts :p_token/:l_token, applied to every key in the batch.
241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/dalli/client.rb', line 241 def get_multi_cas(*keys, req_options: nil) validate_routing_tokens!() if block_given? pipelined_getter.process(keys, ) { |*args| yield(*args) } else {}.tap do |hash| pipelined_getter.process(keys, ) { |k, data| hash[k] = data } end end end |
#get_multi_with_metadata(*keys, req_options: nil, &block) ⇒ Hash
Fetch multiple keys efficiently, returning a stale-aware metadata Hash per key. If a block is given, yields key/metadata pairs one at a time.
Like #get_multi and #get_multi_cas, keys that were not found are omitted from the result -- absence is the miss. A tombstoned item (see #delete with the meta protocol's invalidate flag) is not a miss: it is returned with stale: true, possibly with an empty value, which is the distinction stale-aware callers need.
client.('a', 'b', 'absent')
# => { 'a' => { value: 'v', cas: 12, stale: false, miss: false },
# 'b' => { value: '', cas: 13, stale: true, miss: false } }
Missing keys are requested - result.keys.
Result key order matches request order only when every key lands on the same server; across multiple servers it follows per-server response order instead, the same as #get_multi.
req_options accepts :p_token/:l_token, applied to every key in the batch.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/dalli/client.rb', line 206 def (*keys, req_options: nil, &block) keys.flatten! keys.compact! return {} if keys.empty? validate_routing_tokens!() results = Instrumentation.trace('get_multi_with_metadata', multi_trace_attrs('get_multi_with_metadata', keys.size, keys)) do if ring.servers.size == 1 (keys, ) else pipelined_getter.(keys, ) end end if block results.each(&block) # Matches get_multi/get_multi_cas: nil when a block is given, so # callers can't come to depend on a return value that block-form # get_multi never provided. return nil end results end |
#get_with_metadata(key, options = {}) ⇒ Hash
Get value with extended metadata.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/dalli/client.rb', line 138 def (key, = {}) validate_routing_tokens!() key = key.to_s key = @key_manager.validate_key(key) server = ring.server_for_key(key) Instrumentation.trace('get_with_metadata', trace_attrs('get_with_metadata', key, server)) do server.request(:meta_get, key, ) end rescue NetworkError => e Dalli.logger.debug { e.inspect } Dalli.logger.debug { 'retrying get_with_metadata with new server' } retry end |
#incr(key, amt = 1, ttl = nil, default = nil, req_options = nil) ⇒ Object
Incr adds the given amount to the counter on the memcached server. Amt must be a positive integer value.
If default is nil, the counter must already exist or the operation will fail and will return nil. Otherwise this method will return the new value for the counter.
Note that the ttl will only apply if the counter does not already exist. To increase an existing counter and update its TTL, use #cas.
If the value already exists, it must have been set with raw: true
547 548 549 550 551 552 |
# File 'lib/dalli/client.rb', line 547 def incr(key, amt = 1, ttl = nil, default = nil, = nil) check_positive!(amt) validate_routing_tokens!() perform(:incr, key, amt.to_i, ttl_or_default(ttl), default, ) end |
#not_found?(val) ⇒ Boolean
636 637 638 |
# File 'lib/dalli/client.rb', line 636 def not_found?(val) cache_nils ? val == ::Dalli::NOT_FOUND : val.nil? end |
#prepend(key, value, req_options = nil) ⇒ Object
Prepend value to the value already stored on the server for 'key'. Prepending only works for values stored with :raw => true.
529 530 531 532 |
# File 'lib/dalli/client.rb', line 529 def prepend(key, value, = nil) validate_routing_tokens!() perform(:prepend, key, value.to_s, ) end |
#quiet ⇒ Object Also known as: multi
Turn on quiet aka noreply support for a number of memcached operations.
All relevant operations within this block will be effectively pipelined as Dalli will use 'quiet' versions. The invoked methods will all return nil, rather than their usual response. Method latency will be substantially lower, as the caller will not be blocking on responses.
Currently supports storage (set, add, replace, append, prepend), arithmetic (incr, decr), flush and delete operations. Use of unsupported operations inside a block will raise an error.
Any error replies will be discarded at the end of the block, and Dalli client methods invoked inside the block will not have return values
361 362 363 364 365 366 367 368 |
# File 'lib/dalli/client.rb', line 361 def quiet old = Thread.current[::Dalli::QUIET] Thread.current[::Dalli::QUIET] = true yield ensure @ring&.pipeline_consume_and_ignore_responses Thread.current[::Dalli::QUIET] = old end |
#replace(key, value, ttl = nil, req_options = nil) ⇒ Object
Conditionally add a key/value pair, only if the key already exists on the server. Returns truthy if the operation succeeded.
426 427 428 |
# File 'lib/dalli/client.rb', line 426 def replace(key, value, ttl = nil, = nil) replace_cas(key, value, 0, ttl, ) end |
#replace_cas(key, value, cas, ttl = nil, req_options = nil) ⇒ Object
Conditionally add a key/value pair, verifying existing CAS, only if the key already exists on the server. Returns the new CAS value if the operation succeeded, or falsy otherwise.
434 435 436 437 |
# File 'lib/dalli/client.rb', line 434 def replace_cas(key, value, cas, ttl = nil, = nil) validate_routing_tokens!() perform(:replace, key, value, ttl_or_default(ttl), cas, ) end |
#reset_stats ⇒ Object
Reset stats for each server.
603 604 605 606 607 |
# File 'lib/dalli/client.rb', line 603 def reset_stats ring.servers.map do |server| server.alive? ? server.request(:reset_stats) : nil end end |
#set(key, value, ttl = nil, req_options = nil) ⇒ Object
371 372 373 |
# File 'lib/dalli/client.rb', line 371 def set(key, value, ttl = nil, = nil) set_cas(key, value, 0, ttl, ) end |
#set_cas(key, value, cas, ttl = nil, req_options = nil) ⇒ Object
Set the key-value pair, verifying existing CAS. Returns the resulting CAS value if succeeded, and falsy otherwise.
410 411 412 413 |
# File 'lib/dalli/client.rb', line 410 def set_cas(key, value, cas, ttl = nil, = nil) validate_routing_tokens!() perform(:set, key, value, ttl_or_default(ttl), cas, ) end |
#set_multi(hash, ttl = nil, req_options = nil) ⇒ void
This method returns an undefined value.
Set multiple keys and values efficiently using pipelining. This method is more efficient than calling set() in a loop because it batches requests by server and uses quiet mode.
A transient network error is retried automatically. If a server remains unreachable after retrying, raises Dalli::NetworkError; keys already sent to other servers before the error are not rolled back.
Example:
client.set_multi({ 'key1' => 'value1', 'key2' => 'value2' }, 300)
393 394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'lib/dalli/client.rb', line 393 def set_multi(hash, ttl = nil, = nil) return if hash.empty? validate_routing_tokens!() Instrumentation.trace('set_multi', multi_trace_attrs('set_multi', hash.size, hash.keys)) do if ring.servers.size == 1 single_server_set_multi(hash, ttl_or_default(ttl), ) else pipelined_setter.process(hash, ttl_or_default(ttl), ) end end end |
#stats(type = nil) ⇒ Object
Collect the stats for each server. You can optionally pass a type including :items, :slabs or :settings to get specific stats Returns a hash like { 'hostname:port' => { 'stat1' => 'value1', ... }, 'hostname2:port' => { ... } }
592 593 594 595 596 597 598 599 |
# File 'lib/dalli/client.rb', line 592 def stats(type = nil) type = nil unless ALLOWED_STAT_KEYS.include? type values = {} ring.servers.each do |server| values[server.name.to_s] = server.alive? ? server.request(:stats, type.to_s) : nil end values end |
#touch(key, ttl = nil) ⇒ Object
Touch updates expiration time for a given key.
Returns true if key exists, otherwise nil.
88 89 90 91 |
# File 'lib/dalli/client.rb', line 88 def touch(key, ttl = nil) resp = perform(:touch, key, ttl_or_default(ttl)) resp.nil? ? nil : true end |
#version ⇒ Object
Version of the memcache servers.
611 612 613 614 615 616 617 |
# File 'lib/dalli/client.rb', line 611 def version values = {} ring.servers.each do |server| values[server.name.to_s] = server.alive? ? server.request(:version) : nil end values end |
#with {|_self| ... } ⇒ Object
Stub method so a bare Dalli client can pretend to be a connection pool.
645 646 647 |
# File 'lib/dalli/client.rb', line 645 def with yield self end |