1、redis常用的五大数据类型
1.1string
string是redis最基本的类型,一个key对应一个value
string可以包含任何数据,最大不能超过512M
通过上章的介绍使win和ubantu连接同一个redis服务器,用win来输入命令,ubantu来检查命令
①set key value:设置值
②get key:获取值
③mset key value key value:设置多个值
④mget key1 key2…:获取多个值
⑤append key value:添加字段返回的是字符串长度。可以直接添加数字python中字符串和数字不能直接追加
⑥del key1 key2…:删除
⑦strlen key:返回字符串长度,太显而易见不截图了
⑧expire key second:设置键的有效时间key必须存在(验证码的有效时间)
⑨setex key seconds value:添加键并且设置有效时间
incr key:给key值加1
decr key:给key值减1
incrby key increment:给key增加指定值
decrny key decrement:给key减少指定值
getrange key start end:获取指定区间范围内的值,类似between…and的关系类似于切片但他是双闭合
setrange key offset value:代表从第几位开始替换,下脚标从零开始
从0 -1表示全部
help @string:可以显示所有string的命令
redis中string的应用场景:共享session信息,在服务器中保存用户的登录状态的信息