![yueming yueming]()
使用现在我们开始尝试存储一些数据。下面分别演示四种 Redis 数据类型的使用方法:Keys, Lists, Sets和 Sorted Sets.Keys (单值)在PHP中,Key就是下面的类型: 只需要使用setValue()就可以将 ‘kevin’立即存储到Redis的内存中,随后可能会存储到磁盘后。操作非常简单。然后就可以从Redis中读取这个值:Lists (无索引序列)Lists 是指无序序列。在PHP中,Lists是指下面的形式:Adding new elements to a Redis lists happens in realtime and at constant speed. Meaning that adding an item to a 10 elements list, happens at the same speed as adding an element to the head of a 10 million elements list.Excellent.What’s the downside? Looking up an list item by index is less fast.So use Redis lists every time you require to access data in the same order they are added. Also see Redis Data TypesRediska ExampleSets (有索引无序序列)Are collections of unique unsorted elements. You can think at this as a hash tablewhere all the keys are set to the ‘true’ value.In PHP terms, a Set could be thought of as:Because you now add items as keys, they will be unique, and you can perform all kinds of operations on them you can’t on lists.Examples are: * Testing if a given element already exists * performing the intersection * union * difference between multiple sets and so forth. * etcOk time for that Rediska Example.Sorted Sets (有索引有序序列)Are always ordered by their ’score’ in memory. So any time you retrieve such a set, it’s already sorted no matter what you have added.In PHP terms, a Sorted Set could be thought of as:If we start adding more names & birthyears, old people will automatically be stored on top. Young at the bottom.Rediska Example