The concept of a distributed cache redis

What is NOSQL

NoSQL database management system is different from traditional relational databases collectively. The most important difference is that both NoSQL does not use SQL as a query language.
NoSQL data storage mode may not require a fixed table. NoSQL is based on a key pair, it is conceivable to the corresponding relationship between the primary key and the values in the table.
NoSQL: redis, memcached, mongodb, guava (loadingCache)

What is Redis

Redis is an open source (BSD license), the data structure stored in the memory system that can be used as a database, cache and messaging middleware. It supports multiple types of data structures, such as a string (strings), Hash (of the hashes), lists (Lists), set (sets), an ordered set (sorted sets) and the like.

Starting from mysql to know redis

concept

 One common use is stored in relational database long report data and report data such as aggregated data within a fixed time range.

Common practice is to collect aggregated data: a first row into individual report table which, after the polymerization and then to collect these data by the scanning lines, and update some of those rows in the table the polymerization Pat.

Why graphic appears redis

Graphic detail

Query optimizer: join, left join, subquery, dependent child sql query optimization and sorting complex.

The difference between Redis and memcached and mysql

What are the advantages of each memcached and redis

Memory management mechanism to compare

Slab Allocation Memcached default memory management mechanisms, the main idea is predetermined according to the size of the allocated memory is divided into blocks corresponding to the length of the key-value store particular data record length, in order to completely solve the problem of memory fragmentation. Analyzing the free list storage state.

Redis application memory use on-site way to store data, and rarely used free-list and other ways to optimize memory allocation, memory fragmentation may exist to some extent.

First search that memory is idle, found the distribution. [Cpu contiguous memory, memory allocation java virtual machine is similar to redis, direct memory allocation (pointer collision)]

Comparison of data persistence solution

memcached does not support persistent data memory operation, all data is stored in the form of in-memory.

redis support persistence operations. redis provides two different methods in terms of persistent data is stored to the hard disk inside

  • rdb: belongs to the whole amount of data backup, backup data
  • aof: append only if, persistence incremental backup, the backup command [e.g.: set key, del key]

Compare cached data expires mechanism

When you delete a passive method Memcached failure of the primary key is used, that is, internal Memcached will not fail to monitor whether the primary key, but when you visit the Get primary key will check whether it has expired.

Redis regular, periodic and other cache invalidation mechanisms to reduce memory leaks

Supported data types

Memcached support a single data type, [k, v]

redis supports five data types.

redis two ways to use as a database and as a memory cache

redis used as a database of what advantages and disadvantages

advantage
  • Scheme without constraint, relatively easy to change the data structure, the data type determines the outset
  • Compressive strength capacity, high performance, 100,000 / qps
Shortcoming
  • No index, no foreign keys, lack int / date basic data types,
  • Many conditions need to set inline (sinter, zinterstore) and is connected indirectly
  • Development of low efficiency, poor maintainability

redis used as cache, with two programs used by the database

  • jedis integration scheme set key, value [ "11", "22"] to query a first layer in the buffer, if the data is returned directly to give the second layer in a database query, and flush the cache next time the query [ " 33, "44"]
  • As mybatis / hibernate second level cache scheme, L1 cache: sqlSession, process cache, a single link is valid.

Graphical Analysis architecture plus the difference between before and after the redis

 

Guess you like

Origin www.cnblogs.com/woxbwo/p/11495170.html