ROLE

Syntax
ROLE
Available since:
Redis Open Source 2.8.12
Time complexity:
O(1)
ACL categories:
@admin, @fast, @dangerous,

Provide information on the role of a Redis instance in the context of replication, by returning if the instance is currently a master, slave, or sentinel. The command also returns additional information about the state of the replication (if the role is master or slave) or the list of monitored master names (if the role is sentinel).

Output format

The command returns an array of elements. The first element is the role of the instance, as one of the following three strings:

  • "master"
  • "slave"
  • "sentinel"

The additional elements of the array depends on the role.

Master output

An example of output when ROLE is called in a master instance:

1) "master"
2) (integer) 3129659
3) 1) 1) "127.0.0.1"
      2) "9001"
      3) "3129242"
   2) 1) "127.0.0.1"
      2) "9002"
      3) "3129543"

The master output is composed of the following parts:

  1. The string master.
  2. The current master replication offset, which is an offset that masters and replicas share to understand, in partial resynchronizations, the part of the replication stream the replicas needs to fetch to continue.
  3. An array composed of three elements array representing the connected replicas. Every sub-array contains the replica IP, port, and the last acknowledged replication offset.

Output of the command on replicas

An example of output when ROLE is called in a replica instance:

1) "slave"
2) "127.0.0.1"
3) (integer) 9000
4) "connected"
5) (integer) 3167038

The replica output is composed of the following parts:

  1. The string slave, because of backward compatibility (see note at the end of this page).
  2. The IP of the master.
  3. The port number of the master.
  4. The state of the replication from the point of view of the master, that can be connect (the instance needs to connect to its master), connecting (the master-replica connection is in progress), sync (the master and replica are trying to perform the synchronization), connected (the replica is online).
  5. The amount of data received from the replica so far in terms of master replication offset.

Sentinel output

An example of Sentinel output:

1) "sentinel"
2) 1) "resque-master"
   2) "html-fragments-master"
   3) "stats-master"
   4) "metadata-master"

The sentinel output is composed of the following parts:

  1. The string sentinel.
  2. An array of master names monitored by this Sentinel instance.

Examples

redis> ROLE
"# Server
redis_version:8.0.0
redis_git_sha1:00000000
redis_git_dirty:1
redis_build_id:b1df01fec13473d8
redis_mode:standalone
os:Linux 6.6.72+ x86_64
arch_bits:64
monotonic_clock:POSIX clock_gettime
multiplexing_api:epoll
atomicvar_api:c11-builtin
gcc_version:12.2.0
process_id:1
process_supervised:no
run_id:607a0568c26f744fc9006e20ab57d8408a253dfc
tcp_port:6379
server_time_usec:1749898260995826
uptime_in_seconds:956392
uptime_in_days:11
hz:10
configured_hz:10
lru_clock:5067796
executable:/data/redis-server
config_file:/etc/redis/redis.conf
io_threads_active:0
listener0:name=tcp,bind=*,bind=-::*,port=6379

# Clients
connected_clients:2
cluster_connections:0
maxclients:10000
client_recent_max_input_buffer:8
client_recent_max_output_buffer:0
blocked_clients:0
tracking_clients:0
pubsub_clients:0
watching_clients:0
clients_in_timeout_table:0
total_watched_keys:0
total_blocking_keys:0
total_blocking_keys_on_nokey:0

# Memory
used_memory:33706768
used_memory_human:32.15M
used_memory_rss:48619520
used_memory_rss_human:46.37M
used_memory_peak:33724960
used_memory_peak_human:32.16M
used_memory_peak_perc:99.95%
used_memory_overhead:6767432
used_memory_startup:962840
used_memory_dataset:26939336
used_memory_dataset_perc:82.27%
allocator_allocated:34250032
allocator_active:34635776
allocator_resident:38981632
allocator_muzzy:0
total_system_memory:33661292544
total_system_memory_human:31.35G
used_memory_lua:31744
used_memory_vm_eval:31744
used_memory_lua_human:31.00K
used_memory_scripts_eval:0
number_of_cached_scripts:0
number_of_functions:0
number_of_libraries:0
used_memory_vm_functions:32768
used_memory_vm_total:64512
used_memory_vm_total_human:63.00K
used_memory_functions:192
used_memory_scripts:192
used_memory_scripts_human:192B
maxmemory:4294967296
maxmemory_human:4.00G
maxmemory_policy:allkeys-lru
allocator_frag_ratio:1.01
allocator_frag_bytes:309712
allocator_rss_ratio:1.13
allocator_rss_bytes:4345856
rss_overhead_ratio:1.25
rss_overhead_bytes:9637888
mem_fragmentation_ratio:1.44
mem_fragmentation_bytes:14914568
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_total_replication_buffers:0
mem_replica_full_sync_buffer:0
mem_clients_slaves:0
mem_clients_normal:3840
mem_cluster_links:0
mem_aof_buffer:0
mem_allocator:jemalloc-5.3.0
mem_overhead_db_hashtable_rehashing:0
active_defrag_running:0
lazyfree_pending_objects:0
lazyfreed_objects:0

# Persistence
loading:0
async_loading:0
current_cow_peak:0
current_cow_size:0
current_cow_size_age:0
current_fork_perc:0.00
current_save_keys_processed:0
current_save_keys_total:0
rdb_changes_since_last_save:331445
rdb_bgsave_in_progress:0
rdb_last_save_time:1748941868
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
rdb_saves:0
rdb_last_cow_size:0
rdb_last_load_keys_expired:0
rdb_last_load_keys_loaded:0
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_rewrites:0
aof_rewrites_consecutive_failures:0
aof_last_write_status:ok
aof_last_cow_size:0
module_fork_in_progress:0
module_fork_last_cow_size:0

# Threads
io_thread_0:clients=2,reads=1640599,writes=1258052

# Stats
total_connections_received:382570
total_commands_processed:1257503
instantaneous_ops_per_sec:0
total_net_input_bytes:61782249
total_net_output_bytes:27761361
total_net_repl_input_bytes:0
total_net_repl_output_bytes:0
instantaneous_input_kbps:0.01
instantaneous_output_kbps:0.00
instantaneous_input_repl_kbps:0.00
instantaneous_output_repl_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_subkeys:0
expired_keys:18778
expired_stale_perc:0.00
expired_time_cap_reached_count:0
expire_cycle_cpu_milliseconds:128573
evicted_keys:0
evicted_clients:0
evicted_scripts:0
total_eviction_exceeded_time:0
current_eviction_exceeded_time:0
keyspace_hits:181348
keyspace_misses:14417
pubsub_channels:0
pubsub_patterns:0
pubsubshard_channels:0
latest_fork_usec:0
total_forks:0
migrate_cached_sockets:0
slave_expires_tracked_keys:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0
total_active_defrag_time:0
current_active_defrag_time:0
tracking_total_keys:0
tracking_total_items:0
tracking_total_prefixes:0
unexpected_error_replies:0
total_error_replies:1840
dump_payload_sanitizations:0
total_reads_processed:1640599
total_writes_processed:1258052
io_threaded_reads_processed:0
io_threaded_writes_processed:0
client_query_buffer_limit_disconnections:0
client_output_buffer_limit_disconnections:0
reply_buffer_shrinks:1859
reply_buffer_expands:1871
eventloop_cycles:11535945
eventloop_duration_sum:2760703751
eventloop_duration_cmd_sum:90092116
instantaneous_eventloop_cycles_per_sec:9
instantaneous_eventloop_duration_usec:222
acl_access_denied_auth:0
acl_access_denied_cmd:478
acl_access_denied_key:0
acl_access_denied_channel:0

# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:bd13a49f3cee00838a5be4eff521fe29f0963221
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

# CPU
used_cpu_sys:872.284616
used_cpu_user:2304.771639
used_cpu_sys_children:0.013391
used_cpu_user_children:0.006794
used_cpu_sys_main_thread:872.011328
used_cpu_user_main_thread:2304.467966

# Modules
module:name=timeseries,ver=79991,api=1,filters=0,usedby=[],using=[],options=[]
module:name=search,ver=80000,api=1,filters=0,usedby=[],using=[ReJSON],options=[handle-io-errors]
module:name=bf,ver=79990,api=1,filters=0,usedby=[],using=[],options=[]
module:name=vectorset,ver=1,api=1,filters=0,usedby=[],using=[],options=[handle-io-errors|handle-repl-async-load]
module:name=ReJSON,ver=79990,api=1,filters=0,usedby=[search],using=[],options=[handle-io-errors]

# Errorstats
errorstat_Bad:count=1
errorstat_EOF:count=2
errorstat_ERR:count=1258
errorstat_EXECABORT:count=2
errorstat_Error:count=13
errorstat_Existing:count=5
errorstat_Invalid:count=1
errorstat_NOPERM:count=476
errorstat_Not:count=1
errorstat_TopK_:count=1
errorstat_WRONGTYPE:count=74
errorstat_expected:count=3
errorstat_invalid:count=3

# Cluster
cluster_enabled:0

# Keyspace
db0:keys=116712,expires=496,avg_ttl=31353483221149,subexpiry=0

# Keysizes
db0_distrib_strings_sizes:0=18446744073709550183,1=1735,2=9022,4=31970,8=8056,16=1312,32=337,64=5,128=11,256=11
db0_distrib_lists_items:1=1400,2=10962,4=18,8=214
db0_distrib_sets_items:0=3,1=2291,2=8034,4=260,8=1
db0_distrib_zsets_items:0=18446744073709550923,1=922,2=14165,4=4612
db0_distrib_hashes_items:1=4461,2=16142,4=15
"
redis>

A note about the word slave used in this man page: Starting with Redis 5, if not for backward compatibility, the Redis project no longer uses the word slave. Unfortunately in this command the word slave is part of the protocol, so we'll be able to remove such occurrences only when this API will be naturally deprecated.

Return information

Array reply: where the first element is one of master, slave, or sentinel, and the additional elements are role-specific as illustrated above.
RATE THIS PAGE
Back to top ↑