Class: Splash::Backends::Redis

Inherits:
Object
  • Object
show all
Includes:
Config
Defined in:
lib/splash/backends/redis.rb

Overview

Redis backend definition

Constant Summary

Constants included from Constants

Constants::AUTHOR, Constants::BACKENDS_STRUCT, Constants::CONFIG_FILE, Constants::COPYRIGHT, Constants::DAEMON_LOGMON_SCHEDULING, Constants::DAEMON_METRICS_SCHEDULING, Constants::DAEMON_PID_FILE, Constants::DAEMON_PROCESS_NAME, Constants::DAEMON_PROCMON_SCHEDULING, Constants::DAEMON_STDERR_TRACE, Constants::DAEMON_STDOUT_TRACE, Constants::DEFAULT_RETENTION, Constants::EMAIL, Constants::EXECUTION_TEMPLATE, Constants::EXECUTION_TEMPLATE_TOKENS_LIST, Constants::LICENSE, Constants::LOGGERS_STRUCT, Constants::PID_PATH, Constants::PROMETHEUS_ALERTMANAGER_URL, Constants::PROMETHEUS_PUSHGATEWAY_URL, Constants::PROMETHEUS_URL, Constants::TRACE_PATH, Constants::TRANSPORTS_STRUCT, Constants::VERSION, Constants::WEBADMIN_IP, Constants::WEBADMIN_PID_FILE, Constants::WEBADMIN_PID_PATH, Constants::WEBADMIN_PORT, Constants::WEBADMIN_PROCESS_NAME, Constants::WEBADMIN_PROXY, Constants::WEBADMIN_STDERR_TRACE, Constants::WEBADMIN_STDOUT_TRACE

Instance Method Summary collapse

Methods included from Config

#get_config, #rehash_config

Methods included from ConfigUtilities

#addservice, #checkconfig, #flush_backend, #setupsplash

Methods included from Helpers

#check_unicode_term, #daemonize, #format_by_extensions, #format_response, #get_processes, #group_root, #install_file, #is_root?, #make_folder, #make_link, #run_as_root, #search_file_in_gem, #user_root, #verify_file, #verify_folder, #verify_link, #verify_service

Constructor Details

#initialize(store) ⇒ Splash::Backends::Redis

Constructor

Parameters:

  • store (Symbol)

    name in [:execution_trace] actually (see config and constants )



16
17
18
19
20
21
22
23
24
# 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

Instance Method Details

#del(options) ⇒ Boolean

delete a specific record

Parameters:

  • options (Hash)

Options Hash (options):

  • :key (Symbol)

    the name of the record

Returns:

  • (Boolean)

    status of the operation



65
66
67
68
# 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) ⇒ Boolean

verifiy a specific record existance

Parameters:

  • options (Hash)

Options Hash (options):

  • :key (Symbol)

    the name of the record

Returns:

  • (Boolean)

    presence of the record



80
81
82
83
# 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

#flushObject

flush all records in backend



71
72
73
74
# File 'lib/splash/backends/redis.rb', line 71

def flush
  #`#{@redis_cli_cmd} -n #{@config[:base]} flushdb`
  @store.flushdb
end

#get(options) ⇒ String

return value of queried record

Parameters:

  • options (Hash)

Options Hash (options):

  • :key (Symbol)

    the name of the record

Returns:

  • (String)

    content value of record



46
47
48
49
# 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) ⇒ Array

return the list of find records in backend for a specific pattern

Parameters:

  • hostname (String) (defaults to: @hostname)

    optionnal (default : local hostname)

  • pattern (String) (defaults to: '*')

    shell regexp

Returns:

  • (Array)

    list of record (for all hostname if hostname is specified)



30
31
32
# 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 = '*') ⇒ Array

return the list of find records in backend for a specific pattern, without hostname Checking Redis Backend specific method

Parameters:

  • pattern (String) (defaults to: '*')

    shell regexp

Returns:

  • (Array)

    list of record (for all hostname if hostname is specified)



38
39
40
# File 'lib/splash/backends/redis.rb', line 38

def listall(pattern='*')
   return @store.keys(pattern)
end

#put(options) ⇒ String

defined and store value for specified key

Parameters:

  • options (Hash)

Options Hash (options):

  • :key (Symbol)

    the name of the record

  • :value (Symbol)

    the content value of the record

Returns:

  • (String)

    content value of record



56
57
58
59
# 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