Redis命令5

Redis 服务器命令

Redis 服务器命令主要是用于管理 redis 服务。

实例

如何获取 redis 服务器的统计信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
127.0.0.1:6379> info
# Server
redis_version:5.0.5
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:6d3bf9e511543b78
redis_mode:standalone
os:Darwin 18.6.0 x86_64
arch_bits:64
multiplexing_api:kqueue
atomicvar_api:atomic-builtin
gcc_version:4.2.1
process_id:65254
run_id:3d46ae00173412623b99d81100173246db224357
tcp_port:6379
uptime_in_seconds:497757
uptime_in_days:5
hz:10
configured_hz:10
lru_clock:4627403
executable:/Users/asher/Desktop/redis-5.0.5/src/./redis-server
config_file:

# Clients
connected_clients:2
client_recent_max_input_buffer:2
client_recent_max_output_buffer:0
blocked_clients:0

# Memory
used_memory:1070656
used_memory_human:1.02M
used_memory_rss:1712128
used_memory_rss_human:1.63M
used_memory_peak:1070656
used_memory_peak_human:1.02M
used_memory_peak_perc:100.03%
used_memory_overhead:1054744
used_memory_startup:987824
used_memory_dataset:15912
used_memory_dataset_perc:19.21%
allocator_allocated:1024592
allocator_active:1674240
allocator_resident:1674240
total_system_memory:8589934592
total_system_memory_human:8.00G
used_memory_lua:37888
used_memory_lua_human:37.00K
used_memory_scripts:0
used_memory_scripts_human:0B
number_of_cached_scripts:0
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
allocator_frag_ratio:1.63
allocator_frag_bytes:649648
allocator_rss_ratio:1.00
allocator_rss_bytes:0
rss_overhead_ratio:1.02
rss_overhead_bytes:37888
mem_fragmentation_ratio:1.67
mem_fragmentation_bytes:687536
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:66616
mem_aof_buffer:0
mem_allocator:libc
active_defrag_running:0
lazyfree_pending_objects:0

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1564893311
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:0
rdb_current_bgsave_time_sec:-1
rdb_last_cow_size: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_last_write_status:ok
aof_last_cow_size:0

# Stats
total_connections_received:8
total_commands_processed:214
instantaneous_ops_per_sec:0
total_net_input_bytes:9198
total_net_output_bytes:101508
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
expired_stale_perc:0.00
expired_time_cap_reached_count:0
evicted_keys:0
keyspace_hits:66
keyspace_misses:7
pubsub_channels:1
pubsub_patterns:0
latest_fork_usec:966
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

# Replication
role:master
connected_slaves:0
master_replid:b65a8be1272fab6dfd7b73b0c51e75d06e370c79
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:36.666434
used_cpu_user:23.420130
used_cpu_sys_children:0.044782
used_cpu_user_children:0.009325

# Cluster
cluster_enabled:0

# Keyspace
db0:keys=6,expires=0,avg_ttl=0
127.0.0.1:6379>

Redis time 命令

用于返回当前服务器时间。可用版本 >= 2.6.0

语法

time

返回值

一个包含两个字符串的列表: 第一个字符串是当前时间(以 UNIX 时间戳格式表示),而第二个字符串是当前这一秒钟已经逝去的微秒数。

实例

1
2
3
127.0.0.1:6379> time 
1) "1564908791"
2) "483839"

Redis lastsave 命令

返回最近一次 Redis 成功将数据保存到磁盘上的时间,以 UNIX 时间戳格式表示。可用版本 >= 1.0.0

语法

lastsave

返回值

一个 UNIX 时间戳。

实例

1
2
127.0.0.1:6379> lastsave 
(integer) 1564893311