Redis 資料類型

來源:互聯網
上載者:User

標籤:

Redis資料類型

官網說明文檔:http://www.redis.io/topics/data-types-intro

 

 

Redis keys

Redis keys are binary safe, this means that you can use any binary sequence as a key, from a string like "foo" to the content of a JPEG file. The empty string is also a valid key.

Redis key是二進位安全的,這意味著你可以使用任何二進位序列作為一個key,從一個字串”foo”到JPEG檔案的內容。Null 字元串也是合法的key。

 

規則

  • Key不要太長,消耗記憶體,在資料集中尋找key可能會需要更多的匹配成本。
  • Key不要太短,可讀性較差,
  • 追尋一種模式"object-type:id"  "comment:1234:reply.to" or "comment:1234:reply-to"
  • Key允許的最大值為512M

 

Redis用戶端 Redis-Cli

查看協助

redis-cli  --help

指定資料區塊編號

redis-cli -n 0

 

擷取命令的協助資訊

官網協助文檔:http://www.redis.io/commands

help @string  擷取資料類型string的相關操作命令

help @list 擷取資料類型list的相關操作命令

help set

help <tab>鍵 有提示資訊

 

String

這裡簡單介紹下String類型:

help @string

  APPEND key value  summary: Append a value to a key  since: 2.0.0  BITCOUNT key [start] [end]  summary: Count set bits in a string  since: 2.6.0  BITOP operation destkey key [key ...]  summary: Perform bitwise operations between strings  since: 2.6.0  BITPOS key bit [start] [end]  summary: Find first bit set or clear in a string  since: 2.8.7  DECR key  summary: Decrement the integer value of a key by one  since: 1.0.0  DECRBY key decrement  summary: Decrement the integer value of a key by the given number  since: 1.0.0  GET key  summary: Get the value of a key  since: 1.0.0  GETBIT key offset  summary: Returns the bit value at offset in the string value stored at key  since: 2.2.0  GETRANGE key start end  summary: Get a substring of the string stored at a key  since: 2.4.0  GETSET key value  summary: Set the string value of a key and return its old value  since: 1.0.0  INCR key  summary: Increment the integer value of a key by one  since: 1.0.0  INCRBY key increment  summary: Increment the integer value of a key by the given amount  since: 1.0.0  INCRBYFLOAT key increment  summary: Increment the float value of a key by the given amount  since: 2.6.0  MGET key [key ...]  summary: Get the values of all the given keys  since: 1.0.0  MSET key value [key value ...]  summary: Set multiple keys to multiple values  since: 1.0.1  MSETNX key value [key value ...]  summary: Set multiple keys to multiple values, only if none of the keys exist  since: 1.0.1  PSETEX key milliseconds value  summary: Set the value and expiration in milliseconds of a key  since: 2.6.0  SET key value [EX seconds] [PX milliseconds] [NX|XX]  summary: Set the string value of a key  since: 1.0.0  SETBIT key offset value  summary: Sets or clears the bit at offset in the string value stored at key  since: 2.2.0  SETEX key seconds value  summary: Set the value and expiration of a key  since: 2.0.0  SETNX key value  summary: Set the value of a key, only if the key does not exist  since: 1.0.0  SETRANGE key offset value  summary: Overwrite part of a string at key starting at the specified offset  since: 2.2.0  STRLEN key  summary: Get the length of the value stored in a key  since: 2.2.0

 

設定Key-value值

SET key value [EX seconds] [PX milliseconds] [NX|XX]

EX  到期時間,秒  等同於 SETEX key seconds value

PX  到期時間,毫秒  等同於 PSETEX key milliseconds value

NX  鍵不存在,才能設定  等同於 SETNX key value

XX  鍵存在時,才能設定

 

設定多個Key和value

MSET key value [key value ...]MSETNX key value [key value ...]   鍵不存在時,才設定值

 

到期設定

設定多少秒或毫秒後到期

EXPIRE key seconds    秒PEXPIRE key milliseconds  毫秒

 

設定在指定unix時間戳記到期

EXPIREAT key timestamp     秒PEXPIREAT key milliseconds-timestamp    毫秒
PERSIST key  刪除到期的key

 

查看剩餘時間

TTL keyPTTL key

-1 沒有設定TTL

-2找有找到key

 

尋找key

KEYS pattern

*任意長度字元

?任意一個字元

[]字元集合

 

增量計數

INCR key

例子:

set counter 100

INCR counter

101

INCRBY key increment  根據給定的值進行增量計數
DECR keyDECRBY key increment 

 

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.