#Redis
- Binary Safe Strings
- More than just a kv store
- Most insert commands are variadic
- Bit arrays so could be nice and shiny strings like
app:user:groupor binary data from png. - Long keys aren't a good idea
- Keys are like urls and hence should be readable and pretty
- In rare cases one may use a hashing scheme to generate a key name to avoid collisions and still have small key names, highly discouraged though. Not an excuse for slacking off.
- Make up a schema for key names, say a Util class, stick to it.
- Max Length: 512MB (2^32 bits)
- Strings
- Hashes
- Lists
- Sets
- Ordered Sets (
zsets) - Transactions
- Even if something fails whole transaction is still carried out.
- Use watchers to ensure that nothing changes in the data that is supposed to be used in transaction
- Publishers and Subscribers
- Bit arrays (bitmaps)
- HyperLogLogs
- Aggregate types are created when data is inserted, deleted when they become empty
- Data can't be arbitrarily shoved into any type. A string kv would give error on
lpush.
SETSETNXGETGETSETMSETMGETEXITSDELTYPEINCRINCRBYINCRBYFLOATDECRDECRBYDECRBYFLOATRENAME
- Implemented as LinkedList (not Python List which is Array), compromise on access time by index vs fast inserts to large lists on either ends.
- Use Sorted sets for faster access to mid of collection
RPUSHLPUSHRPOPLPOPLLENLRANGELTRIM- Used for capped lists
BLPOPBRPOP- Pop form one and push into another
RPOPLPUSHLPOPRPUSHBLPOPRPUSHBRPOPLPUSH
B stands for blocking
PUBLISHSUBSCRIBEUNSUBSCRIBEPSUBSCRIBEPUNSUBSCRIBE
Subscribe is blocking operations. P standards for regex pattern to (un)subscribe to multiple channels. Channels are created dynamically if they don't exist yet.
- Dictionaries/associative arrays
HMSETHGETHGETALLHINCRBY
SADDSPOPSRANDMEMBERSMEMBERSSISMEMBERSCARDSINTERSUNIONSTORE
Good for implementing unordered relations, say post and tags
- Sort Logic:
- Score
- Lexicographically if same score
ZADDZRANGE- Supports
WITHSCORESas optional argument
- Supports
ZREVRANGEZRANGEBYSCOREZRANKZREVREANKZRANGEBYRANKZRANGEBYLEXZREVRANGEBYLEXZLEXCOUNT
*LEX work when all elements in set have same score.
EXPIREEXPIREATTTL- return -1 also if there is no key
PERSISTSETEXZREMRANGEBYSCOREZREMRANGEBYRANKZREMRANGEBYLEX
Expire time resolution is always 1ms.
- Bitmaps
- HypeLogLogs
- [Source] (http://redis.io/topics/data-types-intro)