users:leto "{name: leto, planet: dune, likers: [spice]}"
我想查出planet都是dune的users都有哪些记录。redid做不到
持久化
With respect to persistence, by default, Redis snapshots the database to disk based on how many keys have changed. You configure it so that if X number of keys change, then save the database every Y seconds. By default, Redis will save the database every 60 seconds if 1000 or more keys have changed all the way to 15 minutes if 9 or less keys has changed.
花费
Redis keeps all your data in memory. The obvious implication of
this is the cost of running Redis: RAM is still the most expensive part
of server hardware.
When you add those three things together you end up with something
wonderful: speed. But that’s only part of it. The real reason Redis
shines versus other solutions is its specialized data structures.
![](https://www.evernote.com/shard/s166/sh/cf77d16d-3cc6-4fe8-8d57-2661a25f620e/3b51ff35fc39b0f9edaf25adead1a290/res/cc43dc2c-0d25-45da-8d31-16a750fd68d7/QQ20140120-3.png?resizeSmall&width=832)
五种基本数据结构
1、Strings
![](https://www.evernote.com/shard/s166/sh/cf77d16d-3cc6-4fe8-8d57-2661a25f620e/3b51ff35fc39b0f9edaf25adead1a290/res/6d669f2e-22ea-4891-b98a-19731c96b25e/QQ20140120-4.png?resizeSmall&width=832)
![](https://www.evernote.com/shard/s166/sh/cf77d16d-3cc6-4fe8-8d57-2661a25f620e/3b51ff35fc39b0f9edaf25adead1a290/res/9423ed95-5385-4f04-84fa-608e125fb4e9/QQ20140120-5.png?resizeSmall&width=832)
2、Hashes
![](https://www.evernote.com/shard/s166/sh/cf77d16d-3cc6-4fe8-8d57-2661a25f620e/3b51ff35fc39b0f9edaf25adead1a290/res/466a6e5b-b0cb-4e0e-8f17-a003a5560aa0/QQ20140120-6.png?resizeSmall&width=832)
3、Lists
![](https://www.evernote.com/shard/s166/sh/cf77d16d-3cc6-4fe8-8d57-2661a25f620e/3b51ff35fc39b0f9edaf25adead1a290/res/83418699-24d0-4eea-b831-2547f64391e4/QQ20140120-7.png?resizeSmall&width=832)
4、Sets
Sets are used to store unique values and provide a number of
set-based operations, like unions. Sets aren’t ordered but they provide
efficient value-based operations.
![](https://www.evernote.com/shard/s166/sh/cf77d16d-3cc6-4fe8-8d57-2661a25f620e/3b51ff35fc39b0f9edaf25adead1a290/res/f714815f-f423-441b-a082-0f407bfc918f/QQ20140120-8.png?resizeSmall&width=832)
5、Sorted Sets
![](https://www.evernote.com/shard/s166/sh/cf77d16d-3cc6-4fe8-8d57-2661a25f620e/3b51ff35fc39b0f9edaf25adead1a290/res/58306031-eeef-4234-899f-75a5e9ad1862/QQ20140120-9.png?resizeSmall&width=832)
Big O Notation
redis命令的速度
![](https://www.evernote.com/shard/s166/sh/cf77d16d-3cc6-4fe8-8d57-2661a25f620e/3b51ff35fc39b0f9edaf25adead1a290/res/d6577ef4-1c56-4812-b303-dad10c9792c4/QQ20140120-10.png?resizeSmall&width=832)
sismember居然是O(1)。猜测set是用哈希实现
当需求是不同的Key查同一个值时,可以利用Strings和Hashsets的结合
以下是不合理的做法
![](https://www.evernote.com/shard/s166/sh/cf77d16d-3cc6-4fe8-8d57-2661a25f620e/3b51ff35fc39b0f9edaf25adead1a290/res/c9333b30-e01f-4305-ad4d-67c3b73f963a/QQ20140120-11.png?resizeSmall&width=832)
以下是比较好的做法
![](https://www.evernote.com/shard/s166/sh/cf77d16d-3cc6-4fe8-8d57-2661a25f620e/3b51ff35fc39b0f9edaf25adead1a290/res/17841e04-a4e4-48f9-ac36-76f45394f265/QQ20140120-12.png?resizeSmall&width=832)
Monitor and Slow Log
查看日志
![](https://www.evernote.com/shard/s166/sh/cf77d16d-3cc6-4fe8-8d57-2661a25f620e/3b51ff35fc39b0f9edaf25adead1a290/res/321ac9fa-8072-45a4-9c35-725c3d6fcd4f/QQ20140120-13.png?resizeSmall&width=832)
Redis 2.6 includes a built-in Lua interpreter
Redis’ Lua implementation ships with a handful of useful libraries. While table.lib, string.lib and math.lib are quite useful, for me, cjson.lib is worth singling out.
配置
redis.conf
You can find it at http://download.redis.io/redis-stable/redis.conf
授权
Authentication
备份
Replication
Backups
![](https://www.evernote.com/shard/s166/sh/cf77d16d-3cc6-4fe8-8d57-2661a25f620e/3b51ff35fc39b0f9edaf25adead1a290/res/61375df2-4f82-4298-acc8-af033afe3246/QQ20140120-14.png?resizeSmall&width=832)
![](https://www.evernote.com/shard/s166/sh/cf77d16d-3cc6-4fe8-8d57-2661a25f620e/3b51ff35fc39b0f9edaf25adead1a290/res/19b76fef-3497-4d39-acca-bb41978d49f9/QQ20140120-15.png?resizeSmall&width=832)
![](https://www.evernote.com/shard/s166/sh/cf77d16d-3cc6-4fe8-8d57-2661a25f620e/3b51ff35fc39b0f9edaf25adead1a290/res/2d534ec8-05fb-419c-b4e7-26fb53f94ae4/QQ20140120-16.png?resizeSmall&width=832)
![](https://www.evernote.com/shard/s166/sh/cf77d16d-3cc6-4fe8-8d57-2661a25f620e/3b51ff35fc39b0f9edaf25adead1a290/res/e022d212-455b-42b6-b547-d216a392aaf7/QQ20140120-17.png?resizeSmall&width=832)
参考: