Four NoSQL database classification
Key-value memory (key-value): Redis, Tyrant,
Column storage: HBase, Riak, Cassandra
Document Database: mongoDb, CouchDB
Graphics database: Neo4J, InfoGrid
Performance: easy to expand, large amounts of data, high availability
Redis: C language development, the key to high-performance database
Support types: strings, hashes, lists, sets, ordered set
Usage scenarios: cache, the task queue (spike, buy), website access statistics, expired data processing (accurate to milliseconds), distributed cluster architecture separate session
Key not too long, not too short, unified naming convention
type of data
Storage String (used more) capacity up to 512M
set name chen
get name=”chen”
del name
When no num num incr database is automatically set to the value 1, by the specified one, if the other type being given
decr num decreasing
Deer num2 -1
The specified value incrby num3 5 = 5 specified value increase
decrby num3 4 =1
append num3 5 = 15 behind the number plus 5 num3
append num4 123 此时 key=num4 value=123
Storage Hash ( used more )
Assignment, value, delete, increase in numbers, self-command
hset myhash username jack 树名,key,value
hset myhash2 age 20
a plurality of key-value pairs hmset
hmset myhash2 username rose age 21
hget single hmget myhash username age
hgetall myhash
hdel 树名 key
nil=null
Numerical hincrby myhash age 5 plus 5
hexists myhash user 1 has no this key the key 0
The number of attributes hlen myhash
hkeys myhash get all key names
hvals myhash all value
Store list commonly used commands: both ends to add, view a list of both ends of the pop-up, get a list of elements, extended command
r l and the opposite
lpush mylist abc 3 sequentially returned from a queue
lpush mylist 123
rpush inserted from the right
lrange mylist 0 -1 -2 last to first to penultimate
321cba
lpop left mylist 3 dequeue
Right rpop mylist a dequeue
Back length llen
lpushx mylist a head portion inserted in the list, if there will return 0
lrem mylist count the number of value
lrem mylist 0 a queue from start to finish delete all of a
lrem mylist 2 a start to finish delete a queue 2
lset list 3 mmm the index (starting at 0) to a value of 3 mmm
linsert list before b 11 b is in front of the check 11, after the corresponding
rpoplpush list1 list2 list1 team will eject the last element pushed into list2 HOL
This for producers and consumers
Storage Set
List and different is repeated elements Set collection appears not allowed
Commonly used commands: Add, Delete, Get a collection of elements, set intersection, difference, union, extended command
Add: sadd myset abc can not be followed by a return to repeat elements
sadd myset 1 2 3 Continue adding
srem myset 1 2 returns 2, delete the two elements
smembers myset inquiry
sismember myset a return to determining whether there is a presence, absence 0
Operation sadd myset1 abc
sadd myset2 a c 1 2
Difference-set: sdiff myset1 myset2 return b, relating to the order of the front and rear diff, the back rest of the front Save
Union: sunion myset1 myset2
Intersection: sinter myset1 myset2
Get set in the number of members scard myset1 returns 3
Returns a set of random elements: srandmember myset1
There will be a new set of sdiffstore my myset1 myset2 12 sets the result in the difference in my set difference of two sets of
sinterstore, sunionstore as
Special Scene: The only trace data, users maintain relationships between data objects
Order ID to buy the same product of the same customers, intersection of
Sorted-Set orderly storage
Game ranking, microblogging hot topic
Add an element, get, delete, query range, extended command
Add: zadd mysort 70 90 Wang Wu Zhang Doe returned 80 3: Score + Elemental
Zhang zadd mysort 100 returns 0: Joe Smith as it has, but the score was replaced Zhang
zscore mysort zs zs fraction of inquiry
Returns the number of elements zcard mysort
zrem mysort zs ls deleted Zhangsanlisi element returns the number of remaining elements
Find zrange mysort 0 -1 range only query lists the elements
zrange mysort 0 -1 withscores elements listed in ascending default score +
zrevrange mysort mysort 0 -1 withscores descending, level 0 to -1
zremrangebyranke mysort 0 4 0 to Level 4 ranking deleted
zremrangebyscore mysort 80 100 scores delete 80-100 of
zrangebyscore mysort 0 100 withscores 0-100分
Extended command
zincrby mysort 3 ls added to John Doe score 3
zount mysort 80 90 80 Dao 90 points, how many people
Usage scenarios: large-scale integration game rankings, building the index data
General instructions:
All key query keys *
key my * all to my beginning
key my? my1 ,my2 ,my3
del key
rename rename keyName keynewName
type keyname view type
After the 1000 set 1000 seconds expire keyname key disappears
ttl keyname see how many seconds disappear key, or -1 if not set