Sha256: f48d47a377bf50a74d599a7cbca40d06a6781c99034fde8dfb8f8b7583e3af96
Contents?: true
Size: 1.78 KB
Versions: 2
Compression:
Stored size: 1.78 KB
Contents
# coding: utf-8 module Splash module Backends class Redis include Splash::Config def initialize(store) @hostname = Socket.gethostname @config = get_config[:backends][:stores][store] conf = { :host => @config[:host], :port => @config[:port], :db => @config[:base].to_i} conf[:password] = @config[:auth] if @config[:auth] @store = ::Redis.new conf #@redis_cli_cmd = `which redis-cli` @store.auth(@config[:auth]) if @config[:auth] end def list(pattern='*', hostname = @hostname) return @store.keys("#{hostname}##{pattern}").map{|item| item = remove_hostname(item)} end def listall(pattern='*') return @store.keys(pattern) end def get(options) hostname = (options[:hostname])? options[:hostname] : @hostname return @store.get(prefix_hostname(options[:key],hostname)) end def put(options) hostname = (options[:hostname])? options[:hostname] : @hostname @store.set prefix_hostname(options[:key],hostname), options[:value] end def del(options) hostname = (options[:hostname])? options[:hostname] : @hostname @store.del prefix_hostname(options[:key],hostname) end def flush #`#{@redis_cli_cmd} -n #{@config[:base]} flushdb` @store.flushdb end def exist?(options) hostname = (options[:hostname])? options[:hostname] : @hostname return ( not @store.get(prefix_hostname(options[:key],hostname)).nil?) end private def prefix_hostname(key,hostname) return "#{hostname}##{key}" end def remove_hostname(astring) result = astring.split("#") result.shift return result.join("#") end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
prometheus-splash-0.5.3 | lib/splash/backends/redis.rb |
prometheus-splash-0.5.2 | lib/splash/backends/redis.rb |