Difference Redis, Memcache and the MongoDB

>>Memcached

Advantage of Memcached:
Memcached can make use of the advantages of multi-core, high throughput single instance, you can reach hundreds of thousands of QPS (depending on the key, byte size and value of server hardware performance, everyday environment QPS peak in about 4-6w) . Apply to the maximum extent carry amount.
Direct support is configured to session handle.
Memcached limitations:
only support simple key / value data structures, like Redis supports rich data types.
Can not persist, the backup data can not only use for caching, and restart all the data is lost.
Data can not be synchronized, you can not migrate data to other MC in MC instances.
Memcached memory allocation using Slab Allocation mechanism of memory management, value size distribution differs considerably between cause reduced memory utilization, and cause other issues are still kicked out when utilization is low. Users need to pay attention to the design value.

Redis >>

Redis advantages of:
supporting a variety of data structures, such as a string (string), List (doubly linked list), dict (hash table), SET (set), zset (ordered set), hyperloglog (cardinality estimate)
support persistence operations, and can be aof rdb data persistence to disk, data backup or data recovery operations, means better prevent data loss.
Supports data replication via Replication,, can be carried out by master-slave synchronization mechanism for real-time data replication, multi-level replication and incremental replication, master-slave mechanism is an important means to carry out Redis HA.
Single-threaded requests, all commands executed serially, concurrent data consistency without the need to consider the issue.
Support pub / sub messaging subscribe mechanism, it can be used for subscriptions and message notification.
Support simple transaction needs, but rarely used in the industry scene, is not mature.

Redis limitations:
Redis can only use single-threaded, performance is limited by CPU performance, it was the highest single-instance CPU may reach 5-6wQPS per second (depending on the data structure, data size and server hardware performance, everyday environment QPS peak about 1-2w around).
Support simple transaction needs, but rarely used in the industry scene, not mature, both advantage and a disadvantage.
On Redis string will consume more memory types, may be used dict (hash table) stores compressed to reduce memory consumption.

Mc and Redis Key-Value types are not suitable for building relationships between different sets of data, not suitable for query search. For example redis the keys pattern that matches the operating performance of redis is a disaster.

>>mongoDB 

mongoDB is a document of the database. First explain the document database that can store that data xml, json, bson type system.

Includes a self-describing data (self-describing), presenting a hierarchical tree data structure. redis can use the hash simple relational data store.

mongoDB json format to store data.

To suit the scene: the event log, or blog content management platforms, such as commenting system.

1.mongodb persistent principle

mongodb with different mysql, mysql every update operation will be written directly to the hard drive, but will not mongo, as a memory database, data manipulation will first write to memory, and then the hard drive will be persisted to go, then how lasting mongo of it
mongodb at startup, initialize a thread dedicated to continuous cycle (unless the application crash off) for acquiring defer to persist from the queue within a certain period of time and the data written to the disk journal (log) and mongofile (data) at, of course, because it is not when users add a record to be written to disk, so press mongodb developers say, it will not cause wear and tear on the performance, because read the code was found, when the CUD operations, records (Record type) are put into a queue to defer for bulk delay (groupcommit) commit write, it is believed that the time period in which the parameter is a parameter to be a serious consideration, system 90 milliseconds, if the value is lower, it may will cause frequent disk operations, system downtime when too high will cause data loss too.

2. What is a NoSQL database? RDBMS and NoSQL What is the difference? With and without NoSQL database under what circumstances?
NoSQL non-relational databases, NoSQL = Not Only SQL.
Structured data using a relational database, NoSQL uses key-value pairs stored data.
A can be considered ready to respond to the dynamic database NoSQL increased data items; when unstructured / semi-structured data is large; when extended in the horizontal direction.
In considering the maturity of the database; support; analysis and business intelligence; managing and professional issues, priority should be given relational database.

What is the basic difference between 3.MySQL and is MongoDB?
The difference between a relational database and the non-relational databases, i.e., different data storage structure.

What 4.MongoDB feature is?
(1) document-oriented (2) High Performance (3) high availability (4) and extensible (5) rich query language

5.MongoDB support for stored procedures do? If supported, how to use?
MongoDB support stored procedures, it is written in javascript, save in db.system.js table.

6. How to understand GridFS mechanism in MongoDB, MongoDB Why GridFS to store files?
GridFS is a file storage of large files in MongoDB specifications. GridFS can be separated using a large file into multiple small documents stored, so that we can effectively save large documents, but also solve the problem of limited BSON objects.

7. Why MongoDB big data file?
Way pre-allocated space MongoDB used to prevent file fragmentation.

8. What is being migrated when updating a block occurs when the document (Chunk)?
Update will occur immediately on the old block (Chunk), then change will be copied to the new patch before transfer of ownership.

9.MongoDB in A: indexing on {B, C}, Query A: {B, C} and A: {C, B} will use the index it?
No, only the A: uses an index on {B, C}.

10. If a slice (Shard) to stop or slow the time to initiate a query what would happen?
If a slice stopped, unless the query set "Partial" option, otherwise the query will return an error. If a slice response is very slow, MongoDB will wait for its response.

 

Difference >> Redis, Memcache and the MongoDB

From the following dimensions of redis, memcache, mongoDB do a comparison,

1, performance

Are high performance for us should not be a bottleneck

Overall, TPS aspects redis and memcache almost greater than mongodb

2, ease of operation

memcache single data structure

Rich redis some aspects of data manipulation, redis better, less network IO times

mongodb supports rich expression data, index, similar to most relational database query language supported by very rich

3 and the amount of data size, the size of memory space

After redis version 2.0 adds VM own characteristics, to break out of physical memory; you can set the expiration time for the key value (similar memcache)

memcache may modify the maximum available memory using an LRU algorithm

mongoDB suitable for large volume data storage, depending on the operating system memory management VM to do, eat memory is also more powerful, do not service and other services together

4. Availability (single-point problem)

For single-point problem,

Redis, rely on the client to implement a distributed read; from the copy master, the master node from each node reconnecting to be dependent entire snapshot, no incremental replication, due to the performance and efficiency,

So single-point problem is more complex; does not support auto-sharding, need to rely on the program to set a consistent hash mechanism.

An alternative is without redis own replication mechanisms, using their own active replication (multiple storage), or change the way of incremental copies (needs its own implementation), consistency and performance trade-offs

Memcache does not have data redundancy, it is not necessary; for failure prevention, use or cyclic dependency mature hash algorithm to solve the jitter problem caused by a single point of failure.

mongoDB support master-slave, replicaset (internal use paxos election algorithm, automatic failover), auto sharding mechanism to shield the client failover and segmentation mechanism.

5, the reliability (persistence)

For data persistence and data recovery,

redis support (snapshots, AOF): dependent snapshot persistence, aof the same time enhancing the reliability, have an impact on performance

memcache does not support, usually done in the cache to improve performance;

MongoDB version 1.8 from the start binlog way to support the use of persistent reliability

6, data consistency (transaction support)

Memcache in concurrency scenarios, to ensure consistency with cas

redis transaction support is relatively weak, only to ensure that each successive operations in the transaction execution

mongoDB does not support transactions

7, data analysis

mongoDB built-in data analysis functionality (mapreduce), others do not support

8, application scenarios

redis: a smaller amount of data and operate more performance computing

memcache: system for reducing the dynamic load on the database, to improve performance; as cache to improve performance (less suitable for reading and writing, to a greater amount of data can be used Sharding)

MongoDB: mainly to solve the problem of massive data access efficiency

Compare table:
memcache Redis

Type memory database memory database
data types When you define a data type does not require a fixed value would
have strings, lists, sets, and ordered set of
virtual memory support does not support
expiration policy support to support
distributed magent master-slave, a master-slave or a master multi-slave
store data do not support the use of secure storage to save the dump.rdb
disaster recovery is not supported append only file (aof) for data recovery
performance
1, redis type --memcache and all the data stored in the memory, it is Memory Database. Of course, memcache cache can also be used for other things, such as pictures and more.
2, when the data type --Memcache add data necessary to specify the byte length of data, and redis not required.
3, virtual memory - when the physical memory runs out, some of the long useless to the value you can swap to disk.
4, the expiration policy --memcache the designation in the set, for example, set key1 0 0 8, ie never expire. Redis can pass
through e.g. expire set, e.g. expire name 10.
5, distributed - memcache cluster set, using a magent made from multi-master; Redis can be done from a multi-master. Douke
with a master-slave.
6, storing data security --memcache power failure cut off, the data did not; redis can save to disk on a regular basis.
7, disaster recovery --memcache above, after redis lost can be restored by aof.
Memecache port 11211
the install the memcached -Y yum
yum the install PHP--Y-PECL memcache
/etc/init.d/memcached Start the memcached the memcached -d -p -m -u 11211 1024 64 -C -P /var/run/memcached/memcached.pid
-d start a daemon
-p port
-m allocated memory is M
-c -P memcache maximum number of concurrent running of pid
// 0 compression (if MEMCACHE_COMPRESSED) 30 Miao expiration time
// delete 5 is timeout <? PHP
$ memcache the memcache new new =; $ memcache -> Connect ( '127.0.0.1', 11211); $ memcache -> SET ( 'name', 'Yang', 0,30);
! IF ($ memcache-> the Add ( 'name' , 'Susan', 0, 30)) {
// echo 'exist Susan IS'; memcache} $ -> Replace ( 'name', 'Lion', 0, 300); echo $ memcache -> GET ( 'name' );
// $ memcache -> Delete ( 'name',. 5);
the printf "stats \ R & lt \ n-"| Nc 127.0.0.1 11211
the Telnet localhost 11211 stats quit quit
Redis configuration file port 6379
/etc/redis.conf start Redis
Redis-Server /etc/redis.conf insert a value
redis-cli set test "phper.yang" get key
redis-cli get test close Redis
Redis-cli the shutdown Close all
Redis-CLI the shutdown -p 6379 <PHP?
$ = Redis the Redis new new (); $ redis-> Connect ( '127.0.0.1', 6379); $ redis-> SET ( 'Test', 'the Hello World') ; echo $ redis-> GET ( 'Test'); Mongodb
APT-GET can enter the install Mongo Mongo shell command line
pecl install mongo Mongodb similar phpmyadmin platform RockMongo

 

 

 

Redis is a high-performance non-relational database key-value. It can play a very good complement to relational database in some situations. It provides Java, C / C ++, C #, PHP, JavaScript, Perl, Object-C, Python, Ruby, Erlang and other clients, very easy to use.

 

redis provide five data types: string, hash, list, set and zset (sorted set).

 

Well, did not talk much, install redis it. My version offered here are 64 of 3.2.1.00  https://files.cnblogs.com/files/wangjifeng23/Redis-x64-3.2.100.zip  , the rest can go to the official website version download  http: //download.redis .io / Releases /  .

 

After the download is good, the new folder, unzip the file.

After unpacking finished, redis begin installation.

  1. Type cmd

  2. Point redis installation path f: -> cd redis

       3.redis installation instructions redis-server redis.windows.conf, the following icon is installed successfully

 

Open redis client tools (redis-cli.exe)

Use set get acquired setting value, i.e., follows the successful use

 

Well, for ease of use, we can deploy to redis service above self-starting, and then use a third-party client software RedisDesktopManager (download link: https://pan.baidu.com/s/1DAWFwlZQK0AJphOQEHQaXA Password: jr5r) management, allows developers easier.

Use cmd command type shown above: redis-server --service-install redis.windows.conf

 

Open Client, create a connection, enter localhost (the machine service), before connecting to ensure redis service is on port 6379 (the master server)

 

As shown below proves that we have successfully connected friends, I left that store data of four key-value pairs.

 

 

Well, then we want to achieve in his store and access code.

 Use NuGet installation ServiceStack.Redis, which is provided by Microsoft has been packaged for redis action class. It contains four dll

 

Redis connection server, reading and storing

Copy the code
Copy the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace redis
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public static ServiceStack.Redis.RedisClient client = new ServiceStack.Redis.RedisClient("127.0.0.1", 6379);

        public void login(object sender, EventArgs e)
        {
            //读取
            string name = client.Get<string>("name");
            string pwd = client.Get<string>("password");

            //存储
            client.Set<string>("name1", username.Value);
            client.Set<string>("password1", userpwd.Value);
        }
    }
}
Copy the code
Copy the code

to sum up:

1, Redis only support simple k / v types of data, while also providing a storage list, set, zset, hash and other data structures.
2, Redis supports the backup data, i.e., data backup master-slave mode.
3, Redis supports data persistence, data in memory can be kept on disk, restart when you can load be used again.
4, Redis can achieve master-slave replication, failover and failback.
5, Redis Sharding the art: it is easy to be distributed to a plurality of data instances Redis

Guess you like

Origin www.cnblogs.com/Alex80/p/11597479.html