1. 程式人生 > >Redis入門一

Redis入門一

com 最長 array ber 有序列表 ati ash object -s

摘要: Redis支持的數據類型: Binary-safe strings: 字符串 Lists:有序列表;底層維護的是一個鏈表結構,包含字符串元素的集合,有順序、根據插入順序而定 Sets :無序集合;元素不可重復、無序 集合裏面的元素是字符串 Sorted sets:有序集合;和Sets 不同集合裏面每個元素都關聯了一個 floating number value 叫做score, 集合會根據score來排序 Hashes:散列;類似java的hashMap 由字段-字段值組成, 都是字符串。

Redis支持的數據類型:

  • Binary-safe strings: 字符串
  • Lists:有序列表;底層維護的是一個鏈表結構,包含字符串元素的集合,有順序、根據插入順序而定
  • Sets :無序集合;元素不可重復、無序 集合裏面的元素是字符串
  • Sorted sets:有序集合;和Sets 不同集合裏面每個元素都關聯了一個 floating number value 叫做score, 集合會根據score來排序
  • Hashes:散列;類似java的hashMap 由字段-字段值組成, 都是字符串。composed of fields associated with values. Both the field and the value are strings
  • Bit arrays:
  • HyperLogLogs

Redis keys 鍵值的選擇

  • Very long keys are not a good idea 鍵值不能太長
  • Very short keys are often not a good idea.鍵值太短也不太好
  • Try to stick with a schema. 鍵值應該按照一種約定的模式來命名,如: "object-type:id" is a good idea, as in "user:1000". Dots or dashes are often used for multi-word fields, as in "comment:1234:reply.to" or "comment:1234:reply-to".多個單詞用點或者斜線分隔
  • The maximum allowed key size is 512 MB.鍵值最長不能超過512 MB

Lists:Redis的Lists底層采用的是鏈表Link lists, 鏈表的優點:
1.插入速度快、時間復雜度是1 Redis Lists are implemented with linked lists because for a database system it is crucial to be able to add elements to a very long list in a very fast way. Another strong advantage, as you‘ll see in a moment, is that Redis Lists can be taken at constant length in constant time.
缺點:數據量大時訪問速度會慢,如果想要快的訪問速度可以采用 sort set

原文鏈接

Redis入門一