Redis.Commands.Server (Redis v0.8.0)

Copy Markdown View Source

Command builders for Redis server administration and introspection.

Provides pure functions that build command lists for server-level operations including connectivity checks (PING), server information (INFO, DBSIZE, TIME), configuration management (CONFIG GET/SET), client management (CLIENT LIST/KILL), persistence controls (SAVE, BGSAVE), and ACL management. Each function returns a plain list of strings suitable for passing to Redis.command/2 or Redis.pipeline/2.

These functions contain no connection or networking logic -- they only construct the Redis protocol command as a list.

Examples

Ping the server:

iex> Redis.Commands.Server.ping()
["PING"]
iex> Redis.Commands.Server.ping("hello")
["PING", "hello"]

Retrieve a specific INFO section:

iex> Redis.Commands.Server.info("memory")
["INFO", "memory"]

Read and update a configuration parameter:

iex> Redis.Commands.Server.config_get("maxmemory")
["CONFIG", "GET", "maxmemory"]
iex> Redis.Commands.Server.config_set("maxmemory", "256mb")
["CONFIG", "SET", "maxmemory", "256mb"]

Summary

Functions

acl_cat(category \\ nil)

@spec acl_cat(String.t() | nil) :: [String.t()]

acl_deluser(usernames)

@spec acl_deluser([String.t()]) :: [String.t()]

acl_getuser(username)

@spec acl_getuser(String.t()) :: [String.t()]

acl_list()

@spec acl_list() :: [String.t()]

acl_log(opts \\ [])

@spec acl_log(keyword()) :: [String.t()]

acl_setuser(username, rules \\ [])

@spec acl_setuser(String.t(), [String.t()]) :: [String.t()]

bgrewriteaof()

@spec bgrewriteaof() :: [String.t()]

bgsave(opts \\ [])

@spec bgsave(keyword()) :: [String.t()]

client_getname()

@spec client_getname() :: [String.t()]

client_id()

@spec client_id() :: [String.t()]

client_info()

@spec client_info() :: [String.t()]

client_kill(opts \\ [])

@spec client_kill(keyword()) :: [String.t()]

client_list(opts \\ [])

@spec client_list(keyword()) :: [String.t()]

Builds a CLIENT LIST command to retrieve information about connected clients.

Supports filtering by client type (:type) or specific client IDs (:id).

Examples

iex> Redis.Commands.Server.client_list()
["CLIENT", "LIST"]

iex> Redis.Commands.Server.client_list(type: "normal")
["CLIENT", "LIST", "TYPE", "normal"]

client_setname(name)

@spec client_setname(String.t()) :: [String.t()]

client_tracking(on_off, opts \\ [])

@spec client_tracking(
  boolean(),
  keyword()
) :: [String.t()]

command_count()

@spec command_count() :: [String.t()]

command_info(command_names)

@spec command_info([String.t()]) :: [String.t()]

command_list(opts \\ [])

@spec command_list(keyword()) :: [String.t()]

config_get(parameter)

@spec config_get(String.t()) :: [String.t()]

Builds a CONFIG GET command to read a server configuration parameter.

Supports glob-style patterns (e.g., "max*") to retrieve multiple parameters at once.

Example

iex> Redis.Commands.Server.config_get("maxmemory")
["CONFIG", "GET", "maxmemory"]

config_resetstat()

@spec config_resetstat() :: [String.t()]

config_rewrite()

@spec config_rewrite() :: [String.t()]

config_set(parameter, value)

@spec config_set(String.t(), String.t()) :: [String.t()]

dbsize()

@spec dbsize() :: [String.t()]

debug_sleep(seconds)

@spec debug_sleep(integer()) :: [String.t()]

echo(message)

@spec echo(String.t()) :: [String.t()]

flushall(opts \\ [])

@spec flushall(keyword()) :: [String.t()]

flushdb(opts \\ [])

@spec flushdb(keyword()) :: [String.t()]

info(section \\ nil)

@spec info(String.t() | nil) :: [String.t()]

Builds an INFO command to retrieve server information.

When called without arguments, returns all sections. Pass a section name (e.g., "memory", "replication", "stats") to limit the response.

Examples

iex> Redis.Commands.Server.info()
["INFO"]

iex> Redis.Commands.Server.info("replication")
["INFO", "replication"]

lastsave()

@spec lastsave() :: [String.t()]

latency_history(event)

@spec latency_history(String.t()) :: [String.t()]

latency_latest()

@spec latency_latest() :: [String.t()]

latency_reset(opts \\ [])

@spec latency_reset(keyword()) :: [String.t()]

memory_usage(key, opts \\ [])

@spec memory_usage(
  String.t(),
  keyword()
) :: [String.t()]

object_help()

@spec object_help() :: [String.t()]

ping(message \\ nil)

@spec ping(String.t() | nil) :: [String.t()]

Builds a PING command, optionally with a custom message.

When called without arguments, the server responds with "PONG". When called with a message, the server echoes that message back.

Examples

iex> Redis.Commands.Server.ping()
["PING"]

iex> Redis.Commands.Server.ping("hello")
["PING", "hello"]

replicaof(host, port)

@spec replicaof(String.t(), integer()) :: [String.t()]

role()

@spec role() :: [String.t()]

save()

@spec save() :: [String.t()]

shutdown(opts \\ [])

@spec shutdown(keyword()) :: [String.t()]

slaveof(host, port)

@spec slaveof(String.t(), integer()) :: [String.t()]

Deprecated: use replicaof/2 instead.

slowlog_get(count \\ nil)

@spec slowlog_get(integer() | nil) :: [String.t()]

slowlog_len()

@spec slowlog_len() :: [String.t()]

slowlog_reset()

@spec slowlog_reset() :: [String.t()]

swapdb(index1, index2)

@spec swapdb(integer(), integer()) :: [String.t()]

time()

@spec time() :: [String.t()]

waitaof(numlocal, numreplicas, timeout)

@spec waitaof(integer(), integer(), integer()) :: [String.t()]