What is Redis? Two sentences can be summarized as follows:
1. It is a completely open-source and free key-value memory database.
2. It is generally considered as a data structure server, mainly because it has a wide range of data structures, such as strings, map, list, sets, and sorted sets.
What is Redis? The comparison is also made from two aspects:
1. It is not a relational database such as SQL server or mySQL because:
. Currently, redis can only store all the data in the memory as small data volumes.
The design and implementation methods are quite different. Relational databases store data through tables and query data through SQL. Redis stores data through the above five data structures and queries data through commands
2. It is not a cache system such as Memcached. The main reasons are as follows:
In terms of network I/O model: Memcached is a multi-thread, divided into listening thread and worker thread. The introduction of locks leads to performance loss. Redis uses a single-thread IO multiplexing model to maximize its speed advantage and provides simple computing functions.
. Memory Management: Memcached uses a pre-allocated memory pool, which results in a certain amount of space waste. When the memory is still large, new data may also be removed, redis uses on-site memory application to store data without removing any non-temporary data. Redis is more suitable for storage than cache.
. Data Consistency: Memcached provides the cas command to ensure. Redis provides the transaction function, which can ensure the atomicity of a string of commands without being interrupted by any operation.
. Storage Method: Memcached only supports simple key-value storage, does not support enumeration, does not support persistence, replication, and other functions
A summary: Redis is a high-performance key-value database. The emergence of redis largely compensates for the shortage of key/value storage such as memcached. In some cases, it can play a good complementary role for relational databases.
What is the use of Redis? Only by understanding what features it has can we use it to foster strengths and circumvent weaknesses:
1. High Speed: Use Standard C writing, all data is completed in the memory, and the read/write speed reaches 0.1 million/0.2 million respectively.
2. persistence: data update adopts the Copy-on-write technology and can be asynchronously saved to the disk. There are two main policies: one is based on time, snapshot save 300 10 for the number of updates) 2. Statement-based Append (Append-only file, aof)
3. Automatic Operation: all operations on different data types are automatic and safe.
4. Quick master-Slave replication. The official website provides a data record. Slave completes the replication of the 10G key set on the Amazon website in 21 seconds.
5. sharding technology: it is easy to distribute data to multiple Redis instances. database expansion is an eternal topic. In relational databases, however, with the rise of web, mobile Internet, cloud computing, and other applications, this scaling mode is not suitable for users. In recent years, Sharding has been widely used to distribute loads to multiple special nodes, such as master-slave configuration and database replication.
Here is a summary of the Redis database:
1. To improve the database scalability, you only need to put the newly added data on the newly added server.
2. improves the availability of the database and only affects the users of data on the shard server to be accessed.
3. the maintainability of the database is improved, and the upgrade and configuration of the system can be performed one by one based on shard, which has little impact on the service.
4. the query pressure of small data inventory is small, the query is faster, and the performance is better
If I write it here, someone may be eager to use it. How can I use it? You can directly go to the official documentation to help us sort out the clients in various language environments, including Ruby, Python, PHP, Perl, Lua, Java, C #.... there are several languages that I have never met, so I won't say much, you know ....
Finally, I will summarize some of my experiences and lessons in the use process:
1. You need to configure Master-slave. You can switch between them in case of service failure.
2. Disable data persistence on the master side. You only need to configure data persistence on the slave.
3. The physical memory + virtual memory is insufficient. At this time, the dump remains dead and the machine crashes after a long time. This is a disaster!
4. When the Redis physical memory usage exceeds 3/5 of the total memory capacity, it will start to be dangerous. Then we will start to do swap, with a large memory fragmentation.
5. When the maximum memory size is reached, the key with the expiration time is cleared even if the key has not reached the expiration time.
6. For synchronization between redis and DB, write the database first and then redis, because there is basically no problem in writing memory.
This article is from the "ceecy column" blog, please be sure to keep this source http://ceecyj.blog.51cto.com/1640670/1262267