Class: Emb::RuntimeConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/emb/runtime_config.rb

Overview

Hash-like live view of the server's runtime configuration, backed by CONFIG GET / CONFIG SET.

config.to_h           # => { "cache" => "auto", "listen" => ":6379", … }
config['cache']       # => "auto"          (scalar for an exact key)
config['cache*']      # => { "cache" => …, "cache_file" => … }  (glob)
config['cache_file'] = '/var/lib/emb/cache.rdb'   # => "OK"

Values are Strings (config is text, not metrics) and round-trip into writers unchanged. Server errors (unknown/read-only parameter, invalid value, NOAUTH) raise RedisClient::CommandError.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ RuntimeConfig

Returns a new instance of RuntimeConfig.



16
17
18
# File 'lib/emb/runtime_config.rb', line 16

def initialize(client)
  @client = client
end

Instance Method Details

#[](key) ⇒ Object

Read one parameter or a glob. An exact key returns its String value (nil when the server has no such parameter); a glob that matches several parameters returns a Hash.



28
29
30
31
32
33
34
# File 'lib/emb/runtime_config.rb', line 28

def [](key)
  key = key.to_s
  map = pairs(@client.send_command('CONFIG', 'GET', key))
  return map[key] if map.key?(key)

  map.empty? ? nil : map
end

#[]=(key, value) ⇒ Object

Write one parameter (CONFIG SET). Returns the server's reply ("OK").



37
38
39
# File 'lib/emb/runtime_config.rb', line 37

def []=(key, value)
  @client.send_command('CONFIG', 'SET', key.to_s, value.to_s)
end

#to_hObject

All parameters as a String-keyed Hash (CONFIG GET).



21
22
23
# File 'lib/emb/runtime_config.rb', line 21

def to_h
  pairs(@client.send_command('CONFIG', 'GET'))
end