redis字符串操作必备
添加字符串 set hello world 设置多个KV mset AA AAA BB BBB CC CCC 设置过期时间 setex hello1 5 word1 查询字符串 get hello 查询多key mget hello hello2 hello3 查询长度 strlen hello 修改字符串 set hello world2 删除字符串 del hello
Redis Hash hset hkey1 name zhangsan 一次设置多个值 hmset hkey3 name wangwu age 20 sex 1 查看数据 hget hkey1 name 查询某一key内多字段的值 hmget hkey3 name age 查看是否存在 hexists hkey3 name 修改数据 hset hkey1 name zhangsan2 删除key中的数据 hdel hkey3 sex
List 必备 添加一个或多个值到列表 lpush lkey1 zhangsan lisi 向已经存在的列表中插入数据(右边插入) rpush lkey1 AA BB 通过索引查询数据 lindex lkey1 0 通过索引修改数据 lset lkey1 5 eee 删除指定key数据 del lkey1 移出并获取列表的第一个元素 lpop lkey1 移出并获取列表的最后一个元素 rpop lkey1 移除列表的最后一个元素,并将该元素添加到另一个列表并返回 rpoplpush lkey1 lkey2
Set 必须掌握 向集合添加一个或多个数据 sadd skey1 zhangsan lisi 查询集合所有数据 smembers skey1 查询两个集合的差值 sdiff skey1 skey2 查询两个集合交集 sinter skey1 skey2 查询并集 sunion skey1 skey2 查询差值并将结果写入新集合 sdiffstore skey3 skey1 skey2 将数据在一个集合移动到另一个集合 smove skey1 skey2 zhangsan 移除结果中的某个数据 srem skey2 zhangsan
Key 必须掌握
查询所有符合模式的key Keys * 查询剩余过期时间(秒) ttl hkey1 对key进行重命名 Rename hkey1 hkey10 删除存在的key del BB 判断key是否存在 exists AA
Redis 数据库 Redis 默认有16个数据库 清空某一数据库内的所有数据 flushdb 清空所有数据库的数据 flushall