class RedisDashboard::Client

Attributes

connection[R]
url[R]

Public Class Methods

new(url) click to toggle source
# File lib/redis_dashboard/client.rb, line 4
def initialize(url)
  @url = url
end

Public Instance Methods

clients() click to toggle source
# File lib/redis_dashboard/client.rb, line 8
def clients
  connection.client("list")
end
close() click to toggle source
# File lib/redis_dashboard/client.rb, line 42
def close
  connection.close if connection
end
config() click to toggle source
# File lib/redis_dashboard/client.rb, line 12
def config
  array_reply_to_hash(connection.config("get", "*"))
end
info() click to toggle source
# File lib/redis_dashboard/client.rb, line 16
def info
  connection.info
end
memory_stats() click to toggle source
# File lib/redis_dashboard/client.rb, line 38
def memory_stats
  array_reply_to_hash(connection.memory("stats"))
end
slow_commands() click to toggle source
# File lib/redis_dashboard/client.rb, line 27
def slow_commands
  connection.slowlog("get", config["slowlog-max-len"]).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
stats() click to toggle source
# File lib/redis_dashboard/client.rb, line 20
def stats
  stats = connection.info("commandstats").sort { |a, b| b.last["usec"].to_i <=> a.last["usec"].to_i }
  total = stats.reduce(0) { |total, stat| total += stat.last["usec"].to_i }
  stats.each { |stat| stat.last["impact"] = stat.last["usec"].to_f * 100 / total }
  stats
end

Private Instance Methods

array_reply_to_hash(array) click to toggle source

Array reply is a Redis format which is translated into a hash for convenience.

# File lib/redis_dashboard/client.rb, line 53
def array_reply_to_hash(array)
  hash = {}
  while (pair = array.slice!(0, 2)).any?
    hash[pair.first] = pair.last.is_a?(Array) ? array_reply_to_hash(pair.last) : pair.last
  end
  hash
end