module Redis::Commands::Server

def bgrewriteaof

Returns:
  • (String) - `OK`
def bgrewriteaof
  send_command([:bgrewriteaof])
end

def bgsave

Returns:
  • (String) - `OK`
def bgsave
  send_command([:bgsave])
end

def client(subcommand = nil, *args)

Returns:
  • (String, Hash) - depends on subcommand

Parameters:
  • subcommand (String, Symbol) -- e.g. `kill`, `list`, `getname`, `setname`
def client(subcommand = nil, *args)
  send_command([:client, subcommand] + args) do |reply|
    if subcommand.to_s == "list"
      reply.lines.map do |line|
        entries = line.chomp.split(/[ =]/)
        Hash[entries.each_slice(2).to_a]
      end
    else
      reply
    end
  end
end

def config(action, *args)

Returns:
  • (String, Hash) - string reply, or hash when retrieving more than one

Parameters:
  • action (Symbol) -- e.g. `:get`, `:set`, `:resetstat`
def config(action, *args)
  send_command([:config, action] + args) do |reply|
    if reply.is_a?(Array) && action == :get
      Hashify.call(reply)
    else
      reply
    end
  end
end

def dbsize

Returns:
  • (Integer) -
def dbsize
  send_command([:dbsize])
end

def debug(*args)

def debug(*args)
  send_command([:debug] + args)
end

def flushall(options = nil)

Returns:
  • (String) - `OK`

Parameters:
  • options (Hash) --
def flushall(options = nil)
  if options && options[:async]
    send_command(%i[flushall async])
  else
    send_command([:flushall])
  end
end

def flushdb(options = nil)

Returns:
  • (String) - `OK`

Parameters:
  • options (Hash) --
def flushdb(options = nil)
  if options && options[:async]
    send_command(%i[flushdb async])
  else
    send_command([:flushdb])
  end
end

def info(cmd = nil)

Returns:
  • (Hash) -

Parameters:
  • cmd (String, Symbol) -- e.g. "commandstats"
def info(cmd = nil)
  send_command([:info, cmd].compact) do |reply|
    if reply.is_a?(String)
      reply = HashifyInfo.call(reply)
      if cmd && cmd.to_s == "commandstats"
        # Extract nested hashes for INFO COMMANDSTATS
        reply = Hash[reply.map do |k, v|
          v = v.split(",").map { |e| e.split("=") }
          [k[/^cmdstat_(.*)$/, 1], Hash[v]]
        end]
      end
    end
    reply
  end
end

def lastsave

Returns:
  • (Integer) -
def lastsave
  send_command([:lastsave])
end

def monitor(&block)

Other tags:
    Yieldparam: line - timestamp and command that was executed

Other tags:
    Yield: - a block to be called for every line of output
def monitor(&block)
  synchronize do |client|
    client.call_loop([:monitor], &block)
  end
end

def save

Returns:
  • (String) -
def save
  send_command([:save])
end

def shutdown

Synchronously save the dataset to disk and then shut down the server.
def shutdown
  synchronize do |client|
    client.with_reconnect(false) do
      begin
        client.call([:shutdown])
      rescue ConnectionError
        # This means Redis has probably exited.
        nil
      end
    end
  end
end

def slaveof(host, port)

Make the server a slave of another instance, or promote it as master.
def slaveof(host, port)
  send_command([:slaveof, host, port])
end

def slowlog(subcommand, length = nil)

Returns:
  • (Array, Integer, String) - depends on subcommand

Parameters:
  • length (Integer) -- maximum number of entries to return
  • subcommand (String) -- e.g. `get`, `len`, `reset`
def slowlog(subcommand, length = nil)
  synchronize do |client|
    args = [:slowlog, subcommand]
    args << length if length
    client.call args
  end
end

def sync

Internal command used for replication.
def sync
  send_command([:sync])
end

def time

Returns:
  • (Array) - tuple of seconds since UNIX epoch and
def time
  send_command([:time]) do |reply|
    reply&.map(&:to_i)
  end
end