Redis命令使用
1、登陆redis
redis-cli -h 127.0.0.1 -p 6379 -a 'passwrod' redis-cli -h 127.0.0.1 -p 6379 --user 'xxx' --pass 'xxx'
2、帮助信息查询
2.1、help
2.1.1、查询使用方法
127.0.0.1:6379> help redis-cli 6.2.5 To get help about Redis commands type: "help @<group>" to get a list of commands in <group> "help <command>" for help on <command> "help <tab>" to get a list of possible help topics "quit" to exit To set redis-cli preferences: ":set hints" enable online hints ":set nohints" disable online hints Set your preferences in ~/.redisclirc
2.1.2、redis命令行历史记录位置
~/.redisclirc
2.2、命令组分类
@generic 通用的命令组
@string 字符相关命令组
@list 列表相关命令组
@set 集合相关命令组
@sorted_set 有序集合相关命令组
@hash hash相关命令组
@pubsub 发布订阅相关命令组
@transactions 事务相关命令组
@connection 连接相关命令组
@server 服务相关命令组
@scripting 脚本相关命令组
@hyperloglog 超级日志相关命令组
@cluster 集群相关命令组
@geo 基因类数据相关命令组
@stream 流数据相关命令组
# 使用方法: help @string
3、命令基本操作【实践】
3.1、ping
测试是否ping通
ping
3.2、dbsize
查看当前数据库的key的数量 DBSIZE (integer) 0
3.3、select
选择数据库 select 0
3.4、info
查看所有属性信息 info cluster info cpu
3.5、 config get
获取配置属性
config get bind
3.6、keys
获取所有的key信息
127.0.0.1:6379> help keys KEYS pattern summary: Find all keys matching the given pattern since: 1.0.0 group: generic
3.7、exists
判断一个key是否存在 127.0.0.1:6379> help EXISTS EXISTS key [key ...] summary: Determine if a key exists since: 1.0.0 group: generic
3.8、set
设置一个key 127.0.0.1:6379> help set SET key value [EX seconds|PX milliseconds|EXAT timestamp|PXAT milliseconds-timestamp|KEEPTTL] [NX|XX] [GET] summary: Set the string value of a key since: 1.0.0 group: string
3.9、get
获取一个key
127.0.0.1:6379> help get GET key summary: Get the value of a key since: 1.0.0 group: string
3.10、del
删除一个key 127.0.0.1:6379> help del DEL key [key ...] summary: Delete a key since: 1.0.0 group: generic
3.11、type
查看key的类型 127.0.0.1:6379> help type TYPE key summary: Determine the type stored at key since: 1.0.0 group: generic
3.12、expire
设置一个有过期期限的key 127.0.0.1:6379> help EXPIRE EXPIRE key seconds summary: Set a key's time to live in seconds since: 1.0.0 group: generic
3.13、ttl
127.0.0.1:6379> help ttl TTL key summary: Get the time to live for a key since: 1.0.0 group: generic
3.14、flushdb
删除当前库的所有key 127.0.0.1:6379> help flushdb FLUSHDB [ASYNC|SYNC] summary: Remove all keys from the current database since: 1.0.0 group: server
3.15、flushall
# 删除当前数据库所有的数据
127.0.0.1:6379> help flushall FLUSHALL [ASYNC|SYNC] summary: Remove all keys from all databases since: 1.0.0 group: server