Redis--keys的通用操做

##1.獲取所有key
命令:keys *code

127.0.0.1:6379> keys *
1) "myHash2"
2) "myHash"
3) "id"
4) "myHahs"
127.0.0.1:6379>

##2.獲取所有以某個字符開頭的key
命令:keys 字符*get

127.0.0.1:6379> keys my*
1) "myHash2"
2) "myHash"
3) "myHahs"
127.0.0.1:6379>

##3.刪除某個或者某些key
命令:del key1 key2 key3 ...string

127.0.0.1:6379> keys *
1) "myHash2"
2) "myHash"
3) "id"
4) "myHahs"
127.0.0.1:6379> del myHash2 id
(integer) 2
127.0.0.1:6379> keys *
1) "myHash"
2) "myHahs"
127.0.0.1:6379>

##4.檢查某個key是否存在----0:不存在;1:存在命名

127.0.0.1:6379> keys *
1) "myHash"
2) "myHahs"
127.0.0.1:6379> exists myHash
(integer) 1
127.0.0.1:6379> exists id
(integer) 0
127.0.0.1:6379>

##5.對key進行重命名時間

127.0.0.1:6379> keys *
1) "id"
2) "myHash"
127.0.0.1:6379> get id
"100"
127.0.0.1:6379> rename id newId
OK
127.0.0.1:6379> get id
(nil)
127.0.0.1:6379> get newId
"100"
127.0.0.1:6379>

##6.對key設置過時時間
expire key 時間(單位:秒)co

127.0.0.1:6379> keys *
1) "newId"
2) "myHash"
127.0.0.1:6379> expire myHash 1000
(integer) 1
127.0.0.1:6379>

##7.查看某個key所剩的超時時間
命令:ttl key字符

127.0.0.1:6379> ttl myHash
(integer) 889
127.0.0.1:6379>

##8.獲取指定key的類型new

127.0.0.1:6379> keys *
1) "newId"
2) "myHash"
127.0.0.1:6379> type newId
string
127.0.0.1:6379>
相關文章
相關標籤/搜索