Redis基礎命令

來源:互聯網
上載者:User

標籤:

redis本身不區分命令的大小寫,這裡一律用小寫,以下是部分簡單的命令。

1.keys (...)擷取所有的鍵資訊,如果資料量大了,會影響效能,輸出的時候只會輸出鍵名,前面有序號首碼,參數支援正則。

127.0.0.1:6379> keys f*1) "fo"2) "f"127.0.0.1:6379> keys *1) "test"2) "fo"3) "f"

2.exists (...)測試鍵是否存在,存在返回1,否則返回0.

127.0.0.1:6379> exists w(integer) 0127.0.0.1:6379> exists fo(integer) 1

3.del (...)刪除命令,後面跟鍵名,刪除成功返回1,否則返回0,del不支援萬用字元,但是可以用系統內建的argx命令進行組合,例如:redis-cli keys "*" | xargs redis-cli del。

127.0.0.1:6379> del fo(integer) 1127.0.0.1:6379> del fo #已經刪除過一次了,再刪除就返回0了。(integer) 0

4.type (...)查看鍵的類型,如果不存在則返回none。

127.0.0.1:6379> type fstring127.0.0.1:6379> type fonone

5.set/get設定擷取資訊,擷取時如果不存在則返回nil。

127.0.0.1:6379> set t1 tOK127.0.0.1:6379> get t1"t"127.0.0.1:6379> get t2(nil)

6.incr (...) 讓數字字串進行遞增,並返回遞增後的值,如果存在多個用戶端操作同一個,redis保證操作是原子性的,不會出現並發的問題。

127.0.0.1:6379> set t1 1OK127.0.0.1:6379> get t1"1"127.0.0.1:6379> incr t1(integer) 2127.0.0.1:6379> get t1"2"

7.append (...) 向尾部追加

127.0.0.1:6379> get f"1"127.0.0.1:6379> append f lll(integer) 4127.0.0.1:6379> get f"1lll"

8.strlen (...)

127.0.0.1:6379> strlen f(integer) 4

9.mset (...)/mget (...) 擷取設定多個索引值。

127.0.0.1:6379> mset f1 1 f2 2 f3 3OK127.0.0.1:6379> mget f1 f2 f31) "1"2) "2"3) "3"

 

Redis基礎命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.