Module: Emb

Defined in:
lib/emb.rb,
lib/emb/multi.rb,
lib/emb/proxy.rb,
lib/emb/client.rb,
lib/emb/version.rb

Defined Under Namespace

Classes: MultiProxy, Proxy

Constant Summary collapse

DEFAULTS =
{ host: "localhost", port: 6379, pool: 5 }.freeze
VERSION =
Gem.loaded_specs['emb'].version.to_s

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object



7
8
9
# File 'lib/emb/proxy.rb', line 7

def [](name)
  @registry[name] ||= Proxy.new(name.to_sym)
end

.help ⇒ Object



32
# File 'lib/emb.rb', line 32

def help = send_command("EMB.HELP")

.info(name) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/emb.rb', line 20

def info(name)
  raw = send_command("EMB.INFO", name.to_s)

  return {} if raw.nil?

  raw
    .each_slice(2)
    .to_h { |k, v| [k.to_sym, v] }
end

.models ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/emb.rb', line 10

def models
  raw = send_command("EMB.MODELS")

  return [] if raw.nil?

  raw.map do |name, dim, status|
    { name: name, dim: dim.to_i, status: status }
  end
end

.multi {|mp| ... } ⇒ Object

Yields:

  • (mp)


33
34
35
36
37
38
39
# File 'lib/emb/multi.rb', line 33

def multi
  mp = MultiProxy.new

  yield mp

  mp.run
end

.ping ⇒ Object



34
# File 'lib/emb.rb', line 34

def ping = send_command("PING")

.reset_registry! ⇒ Object



11
12
13
# File 'lib/emb/proxy.rb', line 11

def reset_registry!
  @registry.clear
end

.send_command(*args) ⇒ Object



20
21
22
# File 'lib/emb/client.rb', line 20

def send_command(*args)
  pool.with { |r| r.call(*args) }
end

.setup(host: DEFAULTS[:host], port: DEFAULTS[:port], pool: DEFAULTS[:pool]) ⇒ Object Also known as: config



12
13
14
15
16
# File 'lib/emb/client.rb', line 12

def setup(host: DEFAULTS[:host], port: DEFAULTS[:port], pool: DEFAULTS[:pool])
  @pool = ConnectionPool.new(size: pool) do
    RedisClient.new(host: host, port: port, protocol: 2, reconnect_attempts: 3)
  end
end

.stats ⇒ Object



30
# File 'lib/emb.rb', line 30

def stats = send_command("EMB.STATS")