class Splash::Backends::Redis

Redis backend definition

Public Class Methods

new(store) click to toggle source

Constructor @param [Symbol] store name in [:execution_trace] actually (see config and constants ) @return [Splash::Backends::Redis] a Redis backend

# File lib/splash/backends/redis.rb, line 16
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

Public Instance Methods

del(options) click to toggle source

delete a specific record @param [Hash] options @option options [Symbol] :key the name of the record @return [Boolean] status of the operation

# File lib/splash/backends/redis.rb, line 65
def del(options)
  hostname = (options[:hostname])? options[:hostname] : @hostname
  @store.del prefix_hostname(options[:key],hostname)
end
exist?(options) click to toggle source

verifiy a specific record existance @param [Hash] options @option options [Symbol] :key the name of the record @return [Boolean] presence of the record

# File lib/splash/backends/redis.rb, line 80
def exist?(options)
  hostname = (options[:hostname])? options[:hostname] : @hostname
  return ( not @store.get(prefix_hostname(options[:key],hostname)).nil?)
end
flush() click to toggle source

flush all records in backend

# File lib/splash/backends/redis.rb, line 71
def flush
  #`#{@redis_cli_cmd} -n #{@config[:base]} flushdb`
  @store.flushdb
end
get(options) click to toggle source

return value of queried record @param [Hash] options @option options [Symbol] :key the name of the record @return [String] content value of record

# File lib/splash/backends/redis.rb, line 46
def get(options)
  hostname = (options[:hostname])? options[:hostname] : @hostname
  return @store.get(prefix_hostname(options[:key],hostname))
end
list(pattern='*', hostname = @hostname) click to toggle source

return the list of find records in backend for a specific pattern @param [String] hostname optionnal (default : local hostname) @param [String] pattern shell regexp @return [Array] list of record (for all hostname if hostname is specified)

# File lib/splash/backends/redis.rb, line 30
def list(pattern='*', hostname = @hostname)
   return @store.keys("#{hostname}##{pattern}").map{|item| item = remove_hostname(item)}
end
listall(pattern='*') click to toggle source

return the list of find records in backend for a specific pattern, without hostname Checking Redis Backend specific method @param [String] pattern shell regexp @return [Array] list of record (for all hostname if hostname is specified)

# File lib/splash/backends/redis.rb, line 38
def listall(pattern='*')
   return @store.keys(pattern)
end
put(options) click to toggle source

defined and store value for specified key @param [Hash] options @option options [Symbol] :key the name of the record @option options [Symbol] :value the content value of the record @return [String] content value of record

# File lib/splash/backends/redis.rb, line 56
def put(options)
  hostname = (options[:hostname])? options[:hostname] : @hostname
  @store.set prefix_hostname(options[:key],hostname), options[:value]
end

Private Instance Methods

prefix_hostname(key,hostname) click to toggle source

Redis backend specific method for prefix record name with hostname @param [String] key @param [String] hostname @return [String] prefixed string

# File lib/splash/backends/redis.rb, line 91
def prefix_hostname(key,hostname)
  return "#{hostname}##{key}"
end
remove_hostname(astring) click to toggle source

Redis backend specific method for removing hostname of record @param [String] astring @return [String] cleaned string

# File lib/splash/backends/redis.rb, line 98
def remove_hostname(astring)
  result = astring.split("#")
  result.shift
  return result.join("#")
end