Outline
redis
Is a nosql
database, his data is stored in memory, and redis
can synchronize the timing of the in-memory data to disk, that data can be persistent, and compared him memcached
to support more data structure ( string
, list列表[队列和栈]
, set[集合]
, sorted set[有序集合]
, hash(hash表)
). Related reference documentation: http://redisdoc.com/index.html
redis usage scenarios:
- Login session storage: Store in the
redis
middle, andmemcached
compared the data will not be lost. - Top version / counter: for example, some of the show class project, there is often some former anchor ranked number names. There are some articles to read the amount of technology, or Sina microblogging number of points such as praise.
- As the message queue: such
celery
is usedredis
as an intermediary. - Online Now: still show the previous example, the current system will show how much the number of online.
- Some commonly used data cache: Such as our
BBS
forum, the plate does not change often, but every access from every homemysql
get in, you canredis
cache up in, not every request database. - The first 200 articles or reviews cache cache: general users visit the website, only the front part of the article or view a comment, you can put in front of 200 articles and corresponding comments cached. Users access to over, access the database, and after more than 200 articles, put the article before deleting.
- Friends relationship: friendship use microblogging
redis
to achieve. - Publish and subscribe functions: can be used to make chat software.
redis
Andmemcached
the comparison:memcached repeat Types of Pure in-memory database RAM disk synchronization database type of data When necessary to define the data type fixed value Do not need Virtual Memory not support stand by Expiration Policy stand by stand by Storing data security not support Data may be synchronized to the dump.db Disaster Recovery not support You can restore data disk into memory distributed stand by Master-slave synchronization Subscriptions and publishing not support stand by