I. Introduction:
In the past few years, nosql databases have become synonymous with high concurrency and massive data storage solutions, and their corresponding products have sprung up. However, only a few products stand out, such as redis, MongoDB, berkeleydb, and couchdb. Because each product has different features, there are also some differences in their application scenarios. The following is a simple description:
1 ). berkeleydb is a very popular open-source embedded database that can be used for storage engines in more cases. For example, berkeleydb was used as the storage engine of MySQL before it was acquired by Oracle, Which is foreseeable, this product has excellent concurrency scalability, supports transactions and nested transactions, massive data storage and other important features, and has extremely high availability value in the storage of real-time data. However, it should be noted that the license of this product is GPL, which means that it is not used for free in all cases.
2) MongoDB is defined as the oriented-document database server. Unlike berkeleydb, this database can run independently and provide related data services as other relational database servers. We can learn from the official documentation of this product that MongoDB is mainly applicable to highly concurrent forums or blog websites, these websites have the following features: High concurrent access, multi-read and less-write, large data volumes, simple logical relationships, and document data as the main data source. Like berkeleydb, the License of this product is GPL.
3). redis, a typical nosql database server, can serve as a service compared with berkeleydb Program Runs independently on your server host. In many cases, redis is regarded as a key/value database server, but this is not the case. In the current version, in addition to key/value, redis also supports data structures such as list, hash, set, and ordered set. Therefore, redis is more widely used. The official redis website also clarified this misunderstanding. Different from the above two products, redis's license is Apache license, which is completely free for the moment.
4). memcached: data cache server. Why should we explain this product here? It is very simple, because I think it is most similar to redis in use. After all, this is a blog on redis Technology series. In view of this, we will briefly compare the two products. First, let's talk about the biggest difference between them. memcached only provides the data cache service. Once the server goes down, all the data cached in the memory will also disappear, therefore, we can see that memcached does not provide any form of data persistence, while redis provides such a function. In addition, redis provides a richer data storage structure, such as hash and set. There are two main similarities between them. One is completely free, and the other is that they provide extremely similar command forms.
Ii. Advantages of redis:
1 ). compared with other nosql products, redis is extremely easy to use. Therefore, for developers who have experience using similar products, one or two days, you can even use redis to build your own platform in a few hours.
2) while solving many general problems, it also provides related solutions for some personalized problems, such as index engines, statistics rankings, and Message Queue services.
Iii. Main Problems in the current version of redis:
1). the official version does not support the Windows platform. The published official version only supports UNIX and MacOSX platforms.
2). No cluster support is provided. However, according to the official website, this feature is expected to be added to version 2.6.
3) in the publication/subication function, if the master node is down, the slave cannot be automatically upgraded to the master node.
Iv. Comparison with relational databases:
In redis of the current version (2.4.7), five different data types are supported. Only one type is supported. The string type can be considered as the key-value structure, other data types are applicable to scenarios with their respective features. For details, we will describe them in the blog post on this series.
compared with relational databases, redis does not provide good support for complex logical relationships because of its relatively simple storage structure. However, in redis scenarios, we can achieve a significant improvement in efficiency. Even so, redis still provides some basic concepts that databases should possess. For example, you can choose to open different databases in the same connection. However, the difference is that, databases in redis are named by numbers. By default, the opened database is 0. If the program intends to switch the database during running, you can use the SELECT command of redis to open other databases, such as select 1. If you want to switch back to the default database, you only need to execute select 0.
in terms of data storage, redis follows the mainstream idea of the existing nosql database, that is, the key is the unique identifier of data retrieval, we can simply think of it as the index key in a relational database, while value is the primary object of data storage. Each value has a key associated with it, this is like the location where the physical data in the index is stored in the data table. In redis, value is treated as a binary byte stream used to store data in any format, such as JSON, XML, and serialized object byte streams, therefore, we can think of it as a blob field in RDB. It can be seen that during data query, we can only use the key as the condition for our query. Of course, we can also use some techniques in redis to use the value as the key of other data, we will introduce this knowledge in our blog.
5. How to persist memory data:
by default, redis will refer to the number of data changes in the current database. After reaching a certain threshold, it will store the database snapshots to the disk, you can set this threshold through the configuration file. In general, we can also set redis to be regularly saved. If more than 1000 of the key data is modified, redis performs data persistence every 60 seconds. By default, if there are nine or less data changes, redis will persist every 15 minutes.
from the above solution, we can see that if this method is used, redis will run very efficiently, that is, whenever new data changes occur, only the cache data in the memory changes, and such changes will not be immediately persisted to the disk, thus avoiding disk IO in most modification operations. However, things often have two sides. In this method, we have indeed improved the efficiency, but have lost the data reliability. If the server where redis is located goes down before the memory snapshot is persisted to the disk, the modified data not written to the disk will be lost. To ensure high data reliability, redis also provides another data persistence mechanism-append mode. If the redis server is configured with this method, it will be immediately persisted to the disk whenever any data modification occurs.
I believe you have a general understanding of redis after reading this blog. OK. Now let's start learning redis. Continue to follow the blogs behind this series. :)