Redis服务器相关命令
下面切入正题咯:
常用服务器命令总结(自用总结 不喜勿喷):
命令1:ping
测试连接是否存活
返回pong则证明连接正常
127.0.0.1:6379> ping
PONG
redis-server关闭时情况:
not connected> ping
Could not connect to Redis at 127.0.0.1:6379: Connection refused
命令2:quit或exit
退出当前连接
127.0.0.1:6379> quit
macmini:redis-2.8.21 zhongyinghao$ redis-cli
127.0.0.1:6379> exit
macmini:redis-2.8.21 zhongyinghao$ redis-cli
命令3:dbsize
返回当前数据库中的key数量
127.0.0.1:6379> dbsize
(integer) 15
命令4:info
获取当前服务器的信息统计
127.0.0.1:6379> info
# Server
redis_version:2.8.21
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:a17da468d2eeb223
redis_mode:standalone
os:Darwin 14.1.0 x86_64
arch_bits:64
multiplexing_api:kqueue
gcc_version:4.2.1
process_id:475
run_id:17139c7a418b988830c714885a368c20e32daef0
tcp_port:6379
uptime_in_seconds:406
uptime_in_days:0
hz:10
lru_clock:13313061
config_file:
# Clients
connected_clients:1
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
# Memory
used_memory:1006608
used_memory_human:983.02K
used_memory_rss:1822720
used_memory_peak:1006608
used_memory_peak_human:983.02K
used_memory_lua:36864
mem_fragmentation_ratio:1.81
mem_allocator:libc
# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1439376015
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
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
# Stats
total_connections_received:3
total_commands_processed:2
instantaneous_ops_per_sec:0
total_net_input_bytes:82
total_net_output_bytes:80
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
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
# Replication
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
# CPU
used_cpu_sys:0.26
used_cpu_user:0.09
used_cpu_sys_children:0.00
used_cpu_user_children:0.00
# Keyspace
db0:keys=15,expires=0,avg_ttl=0
db15:keys=1,expires=0,avg_ttl=0
命令5:config ge
实时传出收到的请求
127.0.0.1:6379> config get timeout
1) "timeout"
2) “0"
127.0.0.1:6379> config get *
1) "dbfilename"
2) "dump.rdb"
3) "requirepass"
4) ""
5) "masterauth"
6) ""
7) "unixsocket"
命令6:flushdb
删除当前数据库中的所有内容
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> flushdb
OK
127.0.0.1:6379[1]> keys *
(empty list or set)
命令7:flushall
删除所有数据库中的所有key
即删除0~15号数据库中所有的key
127.0.0.1:6379[1]> flushall
OK
127.0.0.1:6379[1]> keys *
(empty list or set)
127.0.0.1:6379> select 0
OK
127.0.0.1:6379> keys *
(empty list or set)