redis的鍵命令用於管理redis中的鍵(key)
command key_name示例
127.0
.0.1:6379> set testdel delcmd
ok127.0
.0.1:6379> keys *
1) "testdel"
127.0
.0.1:6379> del testdel
(integer) 1
127.0
.0.1:6379> get testdel
(nil)
127.0
.0.1:6379> keys *
(empty list or
set)
127.0
.0.1:6379>
示例127.0.0.1:6379> set dumpkey dump
ok127.0.0.1:6379> dump dumpkey
"\x00\x04dump\a
\x00\tus4\xdd
\x8d\xb0n"
示例127.0
.0.1
:6379> exists
hello
(integer) 0
127.0
.0.1
:6379> exists
dumpkey
(integer) 1
示例127.0
.0.1
:6379> expire
dumpkey 5
(integer) 1
127.0
.0.1
:6379> get
dumpkey
(nil)
示例用法同expire 注意的是這裡用的是時間戳
示例用法同expire 注意的是這裡用的是毫秒為單位
示例用法同expire 以unix時間戳形式來設定鍵的到期時間(以毫秒為單位)
示例127.0
.0.1:6379> mset one
1two
2three
3four4ok
127.0
.0.1:6379> key *
(error) err unknown command
'key'
127.0
.0.1:6379> keys *
1) "four"
2) "one"
3) "two"
4) "exkey"
5) "three"
127.0
.0.1:6379> keys *o*
1) "four"
2) "one"
3) "two"
127.0
.0.1:6379> keys f???
1) "four"
127.0
.0.1:6379> keys f??
(empty list or
set)
示例127.0
.0.1:6379> set mykey "redis"
ok127.0
.0.1:6379> get mykey
"redis"
127.0
.0.1:6379> move mykey 1
(integer) 1
127.0
.0.1:6379> get mykey
(nil)
注意:redis資料庫只在單機中有,集群沒有資料庫這一說法
示例
127.0
.0.1
:6379> pttl
newone
(integer) 173840
127.0
.0.1
:6379> persist
newone
(integer) 1
127.0
.0.1
:6379> pttl
newone
(integer) -1
示例127.0
.0.1
:6379> pttl
newone
(integer) -1
127.0
.0.1
:6379> expire
newone 180
(integer) 1
127.0
.0.1
:6379> pttl
newone
(integer) 173840
示例127.0.0.1:6379> randomkey
"four"
示例127.0
.0.1:6379> rename
one newone
ok
示例127.0
.0.1:6379> renamenx two newtwo
(integer) 1
127.0
.0.1:6379> keys *
1) "newone"
2) "four"
3) "newtwo"
4) "exkey"
5) "three"
示例127.0
.0.1:6379> type
onestring
redis常用命令 redis學習 2
redis的常用命令主要分為兩個方面 乙個是鍵值相關命令 乙個是伺服器相關命令 1 鍵值相關命令 keys 取出當前所有的key exists name 檢視n是否有name這個key del name 刪除key name expire confirm 100 設定confirm這個key100秒...
Redis學習(六)Redis鍵 key
redis 鍵命令用於管理 redis 的鍵。redis 鍵命令的基本語法如下 redis 127.0.0.1 6379 command key name redis 127.0.0.1 6379 set runoobkey redis okredis 127.0.0.1 6379 del runo...
redis必殺命令 鍵(key)
語法 redis 鍵命令的基本語法如下 redis 127.0 0.1 6379 command key name例如 redis 127.0 0.1 6379 set w3ckey redis okredis 127.0 0.1 6379 del w3ckey integer 1redis key...