这篇文章记录下Redis中与服务器相关的命令。
命令:ping,测试连接是否连通。
连接连通情况下:
127.0.0.1:6379> ping
PONG
关掉redis服务,再执行ping命令,连接不通:
127.0.0.1:6379> ping
Could not connect to Redis at 127.0.0.1:6379: Connection refused
命令:echo message,输出messgae
127.0.0.1:6379> echo aaaa
"aaaa"
命令:quit/exit,退出连接
127.0.0.1:6379> quit
[root@localhost src]# ./redis-cli
127.0.0.1:6379> exit
[root@localhost src]#
命令:select index,选中数据库,默认情况下,redis有16个数据库,0~15,默认连接数据库0。
[root@localhost src]# ./redis-cli
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> select 2
OK
127.0.0.1:6379[2]> select 0
OK
127.0.0.1:6379>
命令:dbsize,返回当前数据库中key的数目。
127.0.0.1:6379> dbsize
(integer) 5
127.0.0.1:6379> keys *
1) "list1"
2) "person"
3) "zset"
4) "ceshi"
5) "su1"
命令:info [section], 获取服务器的信息,加上参数section,则返回部分信息;不加参数,返回所有信息。
127.0.0.1:6379> info server
# Server
redis_version:5.0.4
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:b21160b3c66b7f36
redis_mode:standalone
os:Linux 2.6.32-504.el6.i686 i686
arch_bits:32
multiplexing_api:epoll
atomicvar_api:sync-builtin
gcc_version:4.4.7
process_id:6394
run_id:1985e76fdb7cfa37f4205e0f5ba3bac6d51c6994
tcp_port:6379
uptime_in_seconds:817
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:14821038
executable:/opt/redis-5.0.4/src/./redis-server
config_file:
127.0.0.1:6379> info CPU
# CPU
used_cpu_sys:0.699893
used_cpu_user:0.607907
used_cpu_sys_children:0.000000
used_cpu_user_children:0.000000
127.0.0.1:6379> info
# Server
redis_version:5.0.4
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:b21160b3c66b7f36
redis_mode:standalone
os:Linux 2.6.32-504.el6.i686 i686
arch_bits:32
multiplexing_api:epoll
atomicvar_api:sync-builtin
gcc_version:4.4.7
process_id:6394
run_id:1985e76fdb7cfa37f4205e0f5ba3bac6d51c6994
tcp_port:6379
uptime_in_seconds:1213
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:14821434
executable:/opt/redis-5.0.4/src/./redis-server
config_file:
# Clients
connected_clients:1
client_recent_max_input_buffer:2
client_recent_max_output_buffer:0
blocked_clients:0
# Memory
used_memory:607876
used_memory_human:593.63K
used_memory_rss:2121728
used_memory_rss_human:2.02M
used_memory_peak:607876
used_memory_peak_human:593.63K
used_memory_peak_perc:100.00%
used_memory_overhead:606410
used_memory_startup:556612
used_memory_dataset:1466
used_memory_dataset_perc:2.86%
allocator_allocated:574116
allocator_active:2096128
allocator_resident:2096128
total_system_memory:1053351936
total_system_memory_human:1004.55M
used_memory_lua:25600
used_memory_lua_human:25.00K
used_memory_scripts:0
used_memory_scripts_human:0B
number_of_cached_scripts:0
maxmemory:3221225472
maxmemory_human:3.00G
maxmemory_policy:noeviction
allocator_frag_ratio:3.65
allocator_frag_bytes:1522012
allocator_rss_ratio:1.00
allocator_rss_bytes:0
rss_overhead_ratio:1.01
rss_overhead_bytes:25600
mem_fragmentation_ratio:3.70
mem_fragmentation_bytes:1547612
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:49550
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:1558324093
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
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:3
total_commands_processed:13
instantaneous_ops_per_sec:0
total_net_input_bytes:287
total_net_output_bytes:30671
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:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec: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
# Replication
role:master
connected_slaves:0
master_replid:72efb236f294d0140aea5a9dc5fc7e041a255d7a
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:0.922859
used_cpu_user:0.777881
used_cpu_sys_children:0.000000
used_cpu_user_children:0.000000
# Cluster
cluster_enabled:0
# Keyspace
db0:keys=5,expires=0,avg_ttl=0
db1:keys=1,expires=0,avg_ttl=0
命令:config get key,获取redis服务器的指定的配置参数,返回所有配置参数,命令是config get *(数据太多就不展示了)。
127.0.0.1:6379> config get dbfilename
1) "dbfilename"
2) "dump.rdb"
命令:flushdb [ASYNC], 在不阻塞服务器的情况下,删除当前数据库的数据,async:异步。
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> keys *
1) "su"
127.0.0.1:6379[1]> flushdb async
OK
127.0.0.1:6379[1]> keys *
(empty list or set)
命令:flushall [ASYNC],在不阻塞服务器的情况下,删除所有数据库的数据,async:异步。
127.0.0.1:6379[1]> select 0
OK
127.0.0.1:6379> keys *
1) "list1"
2) "person"
3) "zset"
4) "ceshi"
5) "su1"
127.0.0.1:6379> select 2
OK
127.0.0.1:6379[2]> keys *
(empty list or set)
127.0.0.1:6379[2]> set aaa 111
OK
127.0.0.1:6379[2]> keys *
1) "aaa"
127.0.0.1:6379[2]> flushall async
OK
127.0.0.1:6379[2]> keys *
(empty list or set)
127.0.0.1:6379[2]> select 0
OK
127.0.0.1:6379> keys *
(empty list or set)
如果有写的不对的地方,请大家多多批评指正,非常感谢!