Redis is a common NoSQL database or non-relational database: Redis does not use tables, and her database is not pre-defined or forced to require users to correlate different data from Redis storage.
Common Database Comparisons:
Compared to high-performance key-value cache server memcached:
Both Redis and mencached can be used to store key-value mappings and have similar performance to each other, but ①. Redis can automatically write data to the hard disk for persistence in two different ways, ②. In addition to storing normal string keys, Redis can store four other data structures, while memcached can only store normal string keys; ③. The Redis database can be used either as a primary database (primary db) or as a secondary database for other storage systems (auxiliary).
Redis Additional Features:
1. Persistence method:
As a memory database, when the server shuts down, where does the stored data go? Redis has two different forms of persistence that can write data stored in memory to the hard disk in a small, compact format: The first persistence method is a point-in-time dump (Point-in-time dump), and the dump operation can be executed in a specified number of write operations over a specified period of time. This condition is fulfilled when executed, and can be executed by invoking any one of the two dumps to the hard disk (dump-to-disk) command; the second persistence method has seen that commands that have modified the database are written to an append-only (append-only) file. Depending on how important the data is, the user can set the append-only write to never sync (sync), synchronize once per second, or synchronize once with each command written.
2. Avoid centralized access:
Because of the Redis memory storage design, using only one Redis server may not be able to handle all requests, so in order to extend the read performance of Redis and provide failover (failover) support for Redis, Redis implements the master-slave replication feature: the slave server that performs the replication connects to the primary server, receives the initial copy (copy) of the entire database sent by the primary server, and the write command executed by the master server is sent to all connected slave servers to update the data set from the server in real time. Therefore, you can send read requests from the server to any one, avoiding centralized access to the primary server.
Reasons to use Redis
memcached database, users can only add data to the end of an existing string with the append command. The memcached document declares that you can use the Append command to manage the list of elements. The user can append an element to the end of a string and use that string as a list. For how to remove these elements,memcached uses the Blacklist (blacklist) to hide the elements in the list, thereby avoiding operations such as reading, updating, writing to the element (including Memcached writes after a database query). In contrast,Redis's list and set allow the user to add or remove elements directly .
Using Redis instead of memcached to solve the problem not only makes the code shorter, easier to understand, easier to maintain, but also makes the code run faster (because users do not need to read the database to update the data). In addition, in many other cases, Redis's efficiency and ease of use are much better than relational databases.
A common use of a database is to store long-term reporting data and use these report data as aggregated data over a fixed time range (aggregates). A common practice for collecting aggregated data is to insert individual rows into a report table before they are scanned to collect aggregated data and to update the rows that are already in the aggregation table based on the aggregated data that is collected. The insert row is used for storage because the insert row operation is very fast for most databases (the Insert row is written only at the end of the hard disk file). However, updating the rows in a table is a fairly slow operation, because this update may cause a random write, in addition to a random read, which can cause an arbitrary reading. In Redis, users can compute aggregated data directly using the Atomic (atomic) INCR command and its variants, and because Redis stores the data in memory , and Command requests sent to Redis do not need to be processed by a typical Query Analyzer (parser) or the query optimizer (optimizer) , so it is always very fast to perform random writes on redis-stored data.
Using Redis instead of relational databases or other hard disk storage databases avoids the need to write unnecessary temporary data, eliminates the hassle of scanning or deleting temporary data , and ultimately improves the performance of the program. While these are some simple examples, they are a good testament to the fact that "tools can dramatically change the way people solve problems."
Redis vs. remaining databases