redis-cli -h 192.168.12.12 远程登录redis客户端
redis 127.0.0.1:6379> ping 测试连接是否存活
PONG
redis 127.0.0.1:6379> echo wilian 在命令行打印一些内容
"wilian"
redis 127.0.0.1:6379> select 1 选择数据库。Redis数据库编号从0~15,我们可以选择任意一个数据库来进行数据的存取
OK
redis 127.0.0.1:6379[1]> dbsize 返回当前数据库中key的数目。
(integer) 0
redis 127.0.0.1:6379[1]> select 0
OK
redis 127.0.0.1:6379> dbsize
(integer) 20
redis 127.0.0.1:6379> info 获取服务器的信息和统计
redis_version:2.4.5
redis_git_sha1:00000000
redis_git_dirty:0
arch_bits:32
multiplexing_api:winsock2
process_id:5956
uptime_in_seconds:100358
uptime_in_days:1
lru_clock:1957468
used_cpu_sys:4.70
used_cpu_user:4.99
used_cpu_sys_children:0.00
used_cpu_user_children:0.00
connected_clients:1
connected_slaves:0
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
used_memory:684452
used_memory_human:668.41K
used_memory_rss:684452
used_memory_peak:684424
used_memory_peak_human:668.38K
mem_fragmentation_ratio:1.00
mem_allocator:libc
loading:0
aof_enabled:0
changes_since_last_save:0
bgsave_in_progress:0
last_save_time:1340763023
bgrewriteaof_in_progress:0
total_connections_received:1
total_commands_processed:199
expired_keys:3
evicted_keys:0
keyspace_hits:163
keyspace_misses:35
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
vm_enabled:0
role:master
db0:keys=20,expires=0
redis 127.0.0.1:6379> monitor 实时转储收到的请求。
OK
1340780669.110663 "monitor"
redis 127.0.0.1:6379> config get dir 获取服务器配置信息
1) "dir"
2) "D:\\mysoft\\redis-2.0.2"
127.0.0.1:6379> info stats
# Stats
total_connections_received:125681
total_commands_processed:18879183860
instantaneous_ops_per_sec:3806#每秒redis调用次数.包括读写
rejected_connections:0
sync_full:1
sync_partial_ok:0
sync_partial_err:0
expired_keys:1000
evicted_keys:0
keyspace_hits:16686960233
keyspace_misses:820886527
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:138
可以通过连续多次执行此指令去分析每秒redis的调用次数.最好保持每秒1W次以下(经验值)
flushdb 删除当前选择数据库中的所有key
flushall 删除所有数据库中的所有key
批量删除某些keys
./redis-cli -h xxx -p xxx keys keysname* | xargs ./redis-cli -h xxx -p xxx del