[个人笔记向]redis 新手常用指令

win安装https://github.com/MicrosoftArchive/redis.git
安装后进入目录

启动服务端 
redis-server 你的配置文件
e.g    redis-server redis.windows.conf
安装为服务(不过msi会帮你装好)redis-server --service-install redis.windows.conf
启动服务
redis-server --service-start
临时使用上面两步可以跳过
启动客户端
redis-cli

增:
set key value
e.g set test test

查:
get key
e.g get test
->test

生存时间相关,这里只有秒的操作,时间戳和毫秒等查阅相关手册
setex key seconds value
e.g set test 60 test
这里超过时间键值对会删除
get test
->test
get test //after 60s
->nil

对存在的值设置生存时间
expire key seconds
e.g expire test 60
->1//ok
可能返回0
->0//该key不存在

持久化,即永不过期
prisist key
->1//ok
->0    //key 不存在

查询到过期剩余时间,秒为单位
ttl key
->-2 //key 不存在,过期了也会返回-2
->-1 //key 没有设置过期时间
->49 //离过期还有40s

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章