標籤:false body 失敗 string sudo set value 執行 log
Ubuntu安裝Redis
[email protected]:~$ sudo apt install redis-server[email protected]:~$ redis-server[email protected]:~$ redis-cli
set(key, value, ex=None, px=None, nx=False, xx=False)
在Redis中設定值,不存在則建立,存在則覆蓋
ex為值的到期時間,單位為秒
px為值的到期時間,單位為毫秒
nx如果設定為True的話,則只有key不存在的時候,當前的set操作才執行
xx如果設定為True的話,則只有key存在的時候才執行當前的set操作
127.0.0.1:6379> set name johnOK127.0.0.1:6379> get name # 擷取name中的值"john"127.0.0.1:6379> set name jackOK127.0.0.1:6379> get name # 覆蓋了原先的值"jack"127.0.0.1:6379> set age 22 ex 2 # 使age中的值存活2秒OK127.0.0.1:6379> get age"22"127.0.0.1:6379> get age(nil) # 過了時間就查不到值了127.0.0.1:6379> set age 22 px 2000 # 使age中的值存活2000毫秒OK127.0.0.1:6379> get age"22"127.0.0.1:6379> get age(nil) # 過了時間就查不到值了127.0.0.1:6379> set name jack nx # 因為name存在,所以set操作執行失敗(nil)127.0.0.1:6379> set name_1 jack nx # 因為name_1不存在,所以set操作執行成功OK127.0.0.1:6379> set name john xx # 因為name存在,所以set操作執行成功OK127.0.0.1:6379> set name_1 john nx # 因為name_1不存在,所以set操作執行失敗(nil)
Python-Redis的String操作