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