Python-Redis的String操作

來源:互聯網
上載者:User

標籤: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操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.