语法
$ redis-cli -h host -p port -a password
[root@VM_92_135_centos ~]# redis-cli -h localhost -p 6179 -a password
[root@VM_92_135_centos ~]# redis-cli -p 6179 -a password
Redis
Info 命令
以一种易于理解和阅读的格式,返回关于 Redis 服务器的各种信息和统计数值。
127.0.0.1:6179> info
# Server // Redis 服务器信息
redis_version:3.0.7
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:6d9f5068f58dedd9
redis_mode:standalone
os:Linux 2.6.32-696.6.3.el6.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.4.7
process_id:10485
run_id:110be938a878adcb948ae2a39e24590042b75e83
tcp_port:6179
uptime_in_seconds:2602176
uptime_in_days:30
hz:10
lru_clock:4575578
config_file:/etc/redis/redis.conf
# Clients // 已连接客户端信息
connected_clients:38
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
# Memory //内存信息
used_memory:2746592
used_memory_human:2.62M
used_memory_rss:4067328
used_memory_peak:2936696
used_memory_peak_human:2.80M
used_memory_lua:36864
mem_fragmentation_ratio:1.48
mem_allocator:jemalloc-3.6.0
# Persistence //RDB 和 AOF 的相关信息
loading:0
rdb_changes_since_last_save:9037
rdb_bgsave_in_progress:0
rdb_last_save_time:1528700058
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:278
total_commands_processed:594611
instantaneous_ops_per_sec:0
total_net_input_bytes:55608230
total_net_output_bytes:95981771
instantaneous_input_kbps:0.02
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:59
evicted_keys:0
keyspace_hits:154331
keyspace_misses:429683
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
migrate_cached_sockets:0
# Replication //主/从复制信息
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:104857600
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
# CPU //CPU 计算量统计信息
used_cpu_sys:1013.83
used_cpu_user:568.66
used_cpu_sys_children:0.00
used_cpu_user_children:0.00
# Cluster //Redis 集群信息
cluster_enabled:0
# Keyspace //数据库相关的统计信息
db1:keys=238,expires=1,avg_ttl=12535118
------------------------------------------------------------------------
select 选择数据库。Redis数据库编号从0~15,我们可以选择任意一个数据库来进行数据的存取
127.0.0.1:6179[4]> select 1
OK
127.0.0.1:6179[1]> keys *
keys 返回满足给定pattern的所有key
用表达式*,代表取出所有的key
--------------------------------
dbsize返回当前数据库中key的数目。
127.0.0.1:6179> dbsize
(integer) 0
127.0.0.1:6179> select 1
OK
127.0.0.1:6179[1]> dbsize
(integer) 251
------------------------
echo 在命令行打印一些内容
127.0.0.1:6179[1]> echo 'aa'
"aa"
127.0.0.1:6179[1]> echo masn
"masn"
--------------
flushdb 删除当前选择数据库中的所有key。
-------------------------
flushall
删除所有数据库中的所有key。
---------------------
del 删除一个key
------------
exists 判断一个key是否存在
------------
Get 命令用于获取指定 key 的值。如果 key 不存在,返回 nil 。如果key 储存的值不是字符串类型,返回一个错误。
127.0.0.1:6179[1]> get '__LOGIN_INFO__136239733'
"{"rid":91,"frontendId":"connector-server-1","areaId":"area-server-11"}"
----------------------
127.0.0.1:6180> keys *
1) "bi0205"
127.0.0.1:6180> type "bi0205"
list
127.0.0.1:6180> llen "bi0205"
(integer) 3860
lrange key start end
获取列表指定范围内的元素
127.0.0.1:6180> lrange "bi0205" 3918 3920
1) "0 0 test 2018-07-12 17:33:37 0 2004-10-24 team1Test@mofefun.com mofefun1 mofefun2 192.198.1.1 effaaeeee0 pc 00205 china 0 10000 101 1000 2018-07-12 17:33:37 1 0 0 0 0 0 0 4350 0 1 {"roleName":"","roleJob":"1","roleGender":"1","roleLevel":1,"roleFighting":4350,"roleGateServerIp":"193.112.175.243"} 26 2018-07-12 17:33:37 926 xe9xa3x8exe8xafxad 6 {"propName":"xe9xa3x8exe8xafxad","propCateID":6} 1 0 0 0 0"
2) "0 0 test 2018-07-12 17:33:37 0 2004-10-24 team1Test@mofefun.com mofefun1 mofefun2 192.198.1.1 effaaeeee0 pc 00205 china 0 10000 101 1000 2018-07-12 17:33:37 1 0 0 0 0 0 0 4350 0 1 {"roleName":"","roleJob":"1","roleGender":"1","roleLevel":1,"roleFighting":4350,"roleGateServerIp":"193.112.175.243"} 26 2018-07-12 17:33:37 925 xe5xb9xbbxe9x87x91 6 {"propName":"xe5xb9xbbxe9x87x91","propCateID":6} 1 0 0 0 0"
3) "0 0 test 2018-07-12 17:33:37 0 2004-10-24 team1Test@mofefun.com mofefun1 mofefun2 192.198.1.1 effaaeeee0 pc 00205 china 0 10000 101 1000 2018-07-12 17:33:37 1 0 0 0 0 0 0 4350 0 1 {"roleName":"","roleJob":"1","roleGender":"1","roleLevel":1,"roleFighting":4350,"roleGateServerIp":"193.112.175.243"} 26 2018-07-12 17:33:37 924 xe6x9cx88xe5x90x9f 6 {"propName":"xe6x9cx88xe5x90x9f","propCateID":6} 1 0 0 0 0"
127.0.0.1:6179[1]> type "ROLE/MODULE/92"
hash
HKEYS key获取所有哈希表中的字段
127.0.0.1:6179[1]> hkeys "ROLE/MODULE/92"
1) "weapon"
2) "rewardTask"
3) "pet"
4) "invest_return"
5) "singleDungeon"
6) "playerHistory"
7) "special_ring"
8) "lottery_limit"
9) "waitBeauty"
10) "manor"
11) "onlineActivity"
12) "achieve"
13) "playerIndex"
14) "title"
HGET key field获取存储在哈希表中指定字段的值
127.0.0.1:6179[1]> hget "ROLE/MODULE/92" "duel"
"{"rid":92,"season":25,"grade":1,"qualifying":1,"star":0,"score":0,"refreshTime":0,"finishPlacement":0,"result":{"win":0,"fail":0,"tie":0},"rewards":{}}"
HGETALL key获取在哈希表中指定 key 的所有字段和值
127.0.0.1:6179[1]> hgetall "ROLE/MODULE/92"
1) "weapon"
2) "{"rid":92,"weaponManager":[{"uid":"dc6d454b-7dc8-11e8-817c-0bf069d3b41a","templateId":2004,"curStack":1,"can_trade":0,"status":1,"skill_list":[{"templateId":24010,"level":3,"skillState":2,"runeList":[]},{"templateId":24020,"level":1,"skillState":1,"runeList":[]},{"templateId":24050,"level":1,"skillState":1,"runeList":[]}],"activeShortCutId":1,"short_cut_1":{"retRuneList":[],"retShortCutList":[{"pos":1,"skillId":24010},{"pos":2,"skillId":24020},{"pos":3,"skillId":24050}]},"short_cut_2":{"retRuneList":[],"retShortCutList":[]}}],"short_cut":[]}"
3) "rewardTask"
4) "{"rid":92,"quitTaskTimes":0,"quitTimeLeft":0,"rewardTaskFinishTimes":0,"rewardTasks":[]}"
5) "pet"
6) "{"rid":92,"used_pet_pos":0,"carry_count":5,"pets":[],"chatTasks":[{"id":1,"progress":0,"state":1,"rewardCount":0},{"id":2,"progress":0,"state":1,"rewardCount":0},{"id":3,"progress":0,"state":1,"rewardCount":0},{"id":4,"progress":0,"state":1,"rewardCount":0},{"id":6,"progress":0,"state":1,"rewardCount":1},{"id":7,"progress":10,"state":1,"rewardCount":0},{"id":8,"progress":10,"state":1,"rewardCount":0},{"id":9,"progress":10,"state":1,"rewardCount":0},{"id":10,"progress":10,"state":1,"rewardCount":0},{"id":11,"progress":10,"state":1,"rewardCount":0},{"id":12,"progress":10,"state":1,"rewardCount":0},{"id":13,"progress":10,"state":1,"rewardCount":0},{"id":14,"progress":10,"state":1,"rewardCount":0}],"exploreTasks":{},"starArray":{}}"
7) "invest_return"
8) "{"rid":92,"last_get_time":0,"award_get_state":[]}"
.........................
HLEN key获取哈希表中字段的数量
127.0.0.1:6179[1]> hlen "ROLE/MODULE/92"
(integer) 30
HMGET key field1 [field2]获取所有给定字段的值
127.0.0.1:6179[1]> hmget "ROLE/MODULE/92" "title" "lottery_limit"
1) "{"rid":92,"wear_id":0,"titles":[]}"
2) "{"rid":92,"name":"xe9xa9xacxe7xa7x91xe6x96xaf","num":0,"end_time":1500960000,"free_sec":0,"get_state":1}"
HVALS key获取哈希表中所有值
127.0.0.1:6179[1]> HVALS "ROLE/MODULE/92"
1) "{"rid":92,"weaponManager":[{"uid":"dc6d454b-7dc8-11e8-817c-0bf069d3b41a","templateId":2004,"curStack":1,"can_trade":0,"status":1,"skill_list":[{"templateId":24010,"level":3,"skillState":2,"runeList":[]},{"templateId":24020,"level":1,"skillState":1,"runeList":[]},{"templateId":24050,"level":1,"skillState":1,"runeList":[]}],"activeShortCutId":1,"short_cut_1":{"retRuneList":[],"retShortCutList":[{"pos":1,"skillId":24010},{"pos":2,"skillId":24020},{"pos":3,"skillId":24050}]},"short_cut_2":{"retRuneList":[],"retShortCutList":[]}}],"short_cut":[]}"
2) "{"rid":92,"quitTaskTimes":0,"quitTimeLeft":0,"rewardTaskFinishTimes":0,"rewardTasks":[]}"
....................
redis导出list文本
[root@VM_92_135_centos ~]# redis-cli -p 端口 -a 密码 lrange 键 1 10000 >> /root/bbb.txt