Class: RedisDashboard::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_dashboard/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Client



4
5
6
# File 'lib/redis_dashboard/client.rb', line 4

def initialize(url)
  @url = url
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



2
3
4
# File 'lib/redis_dashboard/client.rb', line 2

def url
  @url
end

Instance Method Details

#clientsObject



8
9
10
11
12
13
14
15
16
# File 'lib/redis_dashboard/client.rb', line 8

def clients
  connection.client.call([:client, "list"]).split("\n").map do |line|
    line.split(" ").reduce({}) do |hash, str|
      pair = str.split("=")
      hash[pair[0]] = pair[1]
      hash
    end
  end
end

#closeObject



31
32
33
# File 'lib/redis_dashboard/client.rb', line 31

def close
  connection.close if connection
end

#configObject



18
19
20
21
22
23
24
25
# File 'lib/redis_dashboard/client.rb', line 18

def config
  hash = {}
  array = connection.config("get", "*")
  while (pair = array.slice!(0, 2)).any?
    hash[pair.first] = pair.last
  end
  hash
end

#infoObject



27
28
29
# File 'lib/redis_dashboard/client.rb', line 27

def info
  connection.info
end

#slow_commands(length = 128) ⇒ Object

128 is the default slowlog-max-len



35
36
37
38
39
40
41
42
43
44
# File 'lib/redis_dashboard/client.rb', line 35

def slow_commands(length = 128) # 128 is the default slowlog-max-len
  connection.slowlog("get", length).map do |entry|
    cmd = RedisDashboard::Command.new
    cmd.id = entry[0]
    cmd.timestamp = entry[1]
    cmd.microseconds = entry[2]
    cmd.command = entry[3]
    cmd
  end.sort{ |left, right| right.microseconds <=> left.microseconds }
end