1 管理命令
启动
redis-server [--port 6379]
redis-server [xx/xx/redis.conf]
使用命令行连接redis
redis-cli [-h 127.0.0.1 -p 6379]
redis-cli shutdown # 带参数发送命令
redis-cli # 不带参数发送命令
127.0.0.1:6379> shutdown
停止
redis-cli shutdown
kill redis-pid
测试连通性
redis-cli
127.0.0.1:6379> ping
PONG
2 key操作命令
keys * #返回所有key,*是通配符
dbsize # 获取键的总数
exists key1 key2 # 查询key1和key2是否存在,返回存在的键的个数
del key1 key2 # 删除键值
type key1 # 查询键的类型
move key db # 移动键,把key移到db数据库
ttl key # 查询key的生命周期
pttl key # 生命周期毫秒记法 返回-1表示永远不过期
expire key seconds # 设置key的过期时间
pexpire key seconds # 毫秒记法
persist key #设置永不过期