查看系统是否安装的有redis:ps -ef | grep redis
redis登录命令:redis-cli -c -h IP -p 7000
显示当前redis里面所有的key:keys *
清空当前数据库:Flushdb
String集合
增加:set key value
查询 get key
修改 set key value
删除 del key
查询是否存在 exists key
Hash集合
增加hset hash_key key value
查询返回集合所有的key hkeys key
返回集合所有value hvals key
返回特定key的value hget hash_key key eg:hget info name
修改hset hash_key key value eg:hset info name lisi
删除 hdel hash_key key hdel info name
List集合
增加 lpush key value[value……] eg:lpush name zhangsan lisi wangwu
查询 lrange key start end eg:lrange name 0 -1
修改 lset key range value eg:lset name 0 xiaoming
删除
lrem : lrem mylist 0 "value" //从mylist中删除全部等值value的元素 0为全部,负值为从尾部开始
IP:6379> lrem name 0 zhangsan
IP:6379> lrem name 0 lisi
IP:6379> lrem name 0 wangwu
IP:6379> lpop name
"xiaoming"
Set集合
增加:
sadd key value[value……] eg: sadd name zhangsan lisi wangwu
查询
smembers key
IP:6379> smembers name
修改
添加存在的value为,添加不进去,但也不报错,set是不允许重复的
IP:6379> smembers name
IP:6379> sadd name zhangsan
删除
srem key value
删除特定value值 , 若存在返回 1 如果没有返回 0
IP:6379> srem name lisi
(integer) 1
IP:6379> smembers name
集合交集
IP:6379> sadd {user}:testset1 zhangsan lisi wangwu
IP:6379> sadd {user}:testset2 zhangsan xiaoming xiaohong
IP:6379> smembers {user}:testset1
IP:6379> smembers {user}:testset2
IP:6379> keys *
1) "{user}:testset2"
2) "{user}:testset1"
IP:6379> sinter {user}:testset1 {user}:testset2
集合并集
IP:6379> sunion {user}:testset1 {user}:testset2
集合差集
IP:6379> sdiff {user}:testset1 {user}:testset2
SortedSet集合
增加
zadd key index value[value……]
IP:6379> zadd name 1 zhanngsan
查询
zrange key start end
IP:6379> zrange name 0 -1
删除
zrem key value
IP:6379> zrem name lisi
添加数据报(error)CLUSTERDOWN Hash slot not served”问题解决
redis-trib.rb check IP:7000
redis-trib.rb fixIP:7000
导入导出安装redis-dump
Redis启用requirpass,添加密码
redis-cli -c -h IP -p 7000
config get requirepass
config set requirepass password
密码验证 auth password
查看redis版本:redis-server –v