module Dalli::KeysMatch::Client
Public Instance Methods
delete_matched(pattern)
click to toggle source
# File lib/dalli/keys_match.rb, line 77 def delete_matched(pattern) return 0 if pattern.nil? matches = keys(pattern) matches.map { |k| delete(k) }.select { |r| r }.size end
keys(pattern = nil)
click to toggle source
# File lib/dalli/keys_match.rb, line 71 def keys(pattern = nil) keys_with_namespace(pattern).map do |key| key_without_namespace(key) end end
keys_with_namespace(pattern = nil)
click to toggle source
# File lib/dalli/keys_match.rb, line 53 def keys_with_namespace(pattern = nil) re = stats_pattern_regexp(pattern) result = [] ring.servers.each do |server| next unless server.alive? items = server.request(:stats, 'items') slabs = items.inject({}) do |r, (k,v)| r[$1] = v if k =~ /items:(\d+):number/ r end slabs.each do |id, size| result.push(*server.stats_cachedump(id, size, re)) end server.close_telnet! end result end
Protected Instance Methods
stats_pattern_regexp(pattern)
click to toggle source
# File lib/dalli/keys_match.rb, line 86 def stats_pattern_regexp(pattern) return if namespace.nil? && pattern.nil? if namespace if pattern.is_a?(Regexp) opts, source = pattern.to_s.scan(/^\(\?([a-z\-]{3,4})\:(.*)\)$/m).flatten source_with_namespace = \ if source.sub!(/^\^/,'') "^#{namespace}:#{source}" else "^#{namespace}:.*#{source}" end Regexp.new("(?#{opts}:#{source_with_namespace})") else Regexp.new("#{namespace}:.*#{pattern}") end else Regexp.new(pattern.to_s) end end