Class: RDKit::RESPResponder

Inherits:
Object show all
Includes:
DBCommands, SimpleCommands, Subcommands
Defined in:
lib/rdkit/resp_responder.rb

Direct Known Subclasses

RESPRunner

Instance Method Summary collapse

Methods included from DBCommands

#select

Methods included from DBCommands::ServerCommands

#flushall, #flushdb

Methods included from DBCommands::KeyCommands

#del, #exists, #keys, #type

Methods included from DBCommands::HashCommands

#hdel, #hexists, #hget, #hkeys, #hlen, #hset, #hstrlen, #hvals

Methods included from DBCommands::SetCommands

#sadd, #scard, #sismember, #smembers, #srem

Methods included from DBCommands::ListCommands

#llen, #lpop, #lpush, #lrange, #rpop

Methods included from DBCommands::StringCommands

#get, #getset, #mget, #mset, #set, #setnx, #strlen

Methods included from SimpleCommands

#echo, #ping, #time

Instance Method Details

#client(cmd, *args) ⇒ Object



66
67
68
# File 'lib/rdkit/resp_responder.rb', line 66

def client(cmd, *args)
  execute_subcommand('client', %w{ list kill getname setname }, cmd, *args)
end

#config(cmd, *args) ⇒ Object



58
59
60
# File 'lib/rdkit/resp_responder.rb', line 58

def config(cmd, *args)
  execute_subcommand('config', %w{ get set resetstat }, cmd, *args)
end

#debug(cmd, *args) ⇒ Object



70
71
72
# File 'lib/rdkit/resp_responder.rb', line 70

def debug(cmd, *args)
  execute_subcommand('debug', %w{ sleep segfault }, cmd, *args)
end

#gcObject



27
28
29
30
31
# File 'lib/rdkit/resp_responder.rb', line 27

def gc
  GC.start

  'OK'
end

#heapdumpObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rdkit/resp_responder.rb', line 33

def heapdump
  require "objspace"

  ObjectSpace.trace_object_allocations_start

  GC.start

  file = "tmp/heap-#{Process.pid}-#{Time.now.to_i}.json"

  ObjectSpace.dump_all(output: File.open(file, "w"))

  file
end

#info(section = 'default') ⇒ Object

获取服务器状态



17
18
19
20
21
22
23
24
25
# File 'lib/rdkit/resp_responder.rb', line 17

def info(section='default')
  info = Introspection.info(section)

  unless info.empty?
    info.map do |type, value|
      "# #{type.capitalize}\r\n" + value.map { |k, v| "#{k}:#{v}" }.join("\r\n") + "\r\n"
    end.join("\r\n") + "\r\n"
  end
end

#monitorObject



47
48
49
50
51
# File 'lib/rdkit/resp_responder.rb', line 47

def monitor
  server.monitors << server.current_client

  'OK'
end

#run(cmd) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/rdkit/resp_responder.rb', line 3

def run(cmd)
  if cmd.respond_to?(:call)
    RESP.compose(cmd.call)
  else
    RESP.compose(call(cmd))
  end
rescue StandardError => e
  RESP.compose(e)
end

#serverObject



74
75
76
# File 'lib/rdkit/resp_responder.rb', line 74

def server
  Server.instance
end

#shutdownObject



53
54
55
# File 'lib/rdkit/resp_responder.rb', line 53

def shutdown
  server.stop
end

#slowlog(cmd, *args) ⇒ Object



62
63
64
# File 'lib/rdkit/resp_responder.rb', line 62

def slowlog(cmd, *args)
  execute_subcommand('slowlog', %w{ get reset len }, cmd, *args)
end