A study of NoSQL everyone loves Redis: (1) Introduction to Redis and simple installation

Source: Internet
Author: User
Tags cassandra memcached redis windows

Http://www.cnblogs.com/edisonchou/p/3821228.html One, the wind of NoSQL

The development requirement of 1.1 post-Web2.0 era

With the rise of the internet Web2.0 website, the traditional relational database in coping with Web2.0 website, especially the super-large-scale and high-concurrency SNS type Web2.0 Pure dynamic website has appeared to be inadequate, exposing a lot of difficult to overcome problems:

(1) high concurrency and read-write requirements for databases

Web site based on user personalized information to generate dynamic pages in real-time and provide dynamic information, so basically can't use dynamic page static technology, so the database concurrency load is very high, often to achieve tens of thousands of reads and writes requests per second. The relational database is barely able to cope with tens of thousands of SQL queries, but with tens of thousands of requests for SQL write data, hard disk IO is already unbearable.

(2) The need for efficient storage and access to massive amounts of data

For the large-scale SNS website, the daily user generates a huge amount of user dynamics, taking foreign friendfeed as an example, one months to reach 250 million user dynamics, for the relational database, in a 250 million records of the surface of the SQL query, the efficiency is extremely low even intolerable.

(3) high scalability and high availability requirements for the database

In the Web-based architecture, the database is the most difficult to scale out, when the number of users and access to an application system is increasing, your database is not as simple as the Web server and application server to add more hardware and service nodes to expand performance and load capacity. For many websites that need to provide 7 * 24 hours uninterrupted service, it is very painful to upgrade and extend the database system, which often requires downtime maintenance and data migration, why can the database not be extended by constantly adding server nodes?

In the face of the above-mentioned " three high " demand, the relational database has encountered insurmountable obstacles, and for the Web2.0 site, many of the main features of the relational database are often useless, for example:

(1) database transaction Consistency Requirements

Many web real-time systems do not require strict database transactions, the requirements for read consistency is very low, and some occasions write consistency requirements are not high. Therefore, database transaction management becomes a heavy burden under the high load of database.

(2) The realistic and real time demand of the database

For a relational database, a query is made immediately after inserting a piece of data, and it is certainly possible to read the data. Does not require such high real-time nature.

(3) requirements for complex SQL queries, especially multi-table associated queries

Any large data volume of the Web system, are very taboo of multiple large tables of related queries, as well as complex data analysis types of complex SQL report query, especially the SNS type of Web site, from the requirements and product design perspective, to avoid the emergence of this situation. Often more than just a single table of primary key query, as well as single table simple conditional paging query, SQL function has been greatly weakened.

Therefore, the relational database is less suitable in these more and more application scenarios, and the non-relational database to solve this kind of problem arises . NoSQL is a generalized definition of non-relational data storage. It breaks the unification of long-term relational database and acid theory . NoSQL data storage does not require a fixed table structure (for example, stored as key-value pairs, its structure is not fixed, each tuple can have a different field, each tuple can add some of its own key-value pairs, so that it is not limited to fixed structure, can reduce some time and space overhead), There is usually no connection operation.

1.2 NoSQL's unparalleled features

The performance benefits of relational databases are unmatched in big data access, such as:

(1) easy to expand

There are a variety of NoSQL databases, but one common feature is the relationship-based nature of relational databases. there is no relationship between the data , so it is very easy to expand. Also invisible, at the level of architecture brings the ability to expand.

(2) large data volume, high performance

NoSQL databases have very high read and write performance, especially in the case of large data volumes. This is due to its non-relational nature, the database structure is simple.

(3) Flexible data Model

NoSQL can store custom data formats at any time without having to create fields in advance for the data to be stored. In the relational database, adding or deleting fields is a very troublesome thing. If it is a table with very large amounts of data, adding fields is simply a nightmare. This is especially true in the Web2.0 era of large data volumes.

(4) High Availability

NoSQL can easily implement a highly available architecture without compromising performance. For example, the Cassandra,hbase model can also be highly available by copying the model.

  In summary, the non-relational nature of NoSQL makes it the darling of the post-Web2.0 era, and it is a new revolutionary movement of the database to help the large Web2.0 website take off again.

Second, Redis's stand out

As applications increase in demand for high performance, NoSQL is increasingly rooted in the system architecture of each name enterprise. Today, there are many types of nosql products, such as Membase, MongoDB, Apache Cassandra, COUCHDB, and so forth. However, at home and abroad internet giants such as social giants such as Sina Weibo, media giant Viacom and picture-sharing leader Pinterest , and other companies have adopted the Redis as its NoSQL database choice, Where exactly is Redis? Can let so many famous enterprises for it and crazy.

According to the official statement, Redis is an open source, written in C, for "key/value" (key/value) type data-based distributed NoSQL database system, characterized by high performance , persistent storage , adapt to high concurrency of the application scenario . Therefore, it can be said that Redis is purely for the application, it is a high-performance Key-value database, and also provides a variety of language APIs (including our Big C #). Well, maybe we'll ask: What's the performance? The following is the official Bench-mark data:

the test completed 50 concurrent executions of 100,000 requests .  The set and get value is a 256-byte string.  Linux box is running Linux 2.6, which is X3320 Xeon 2.5 GHz.  Text execution uses the loopback interface (127.0.0.1). Result: The reading speed is 110,000 times/s, the write speed is 81,000 times/s . (Different server configuration performance varies, of course).

Similar to memcached, Redis supports storing more value types, including string (string), list (linked list), set (set), Zset (sorted set-ordered collection), and hash (hash type). These data types support Push/pop, Add/remove, and intersection-set and difference sets, and richer operations, and these operations are atomic. Based on this, Redis supports sorting in a variety of different ways. As with memcached, data is cached in memory to ensure efficiency. The difference is that Redis periodically writes the updated data to disk or writes the modification to the appended record file, and Master-slave (Master-Slave) synchronization is implemented on this basis (data can be synchronized from the primary server to any number of slave servers. From the server can be associated with other primary servers from the server. )。

Therefore, theemergence of Redis, to a large extent, compensates for the lack of memcached such key/value storage, in some cases can be a good complement to the relational database .

Iii. installation and configuration of Redis on Windows

Before the introduction of a large pile, and now start real DAO hard work! First of all, it must be the installation of Redis, here we choose the more familiar Windows platform to install. Since it's the Windows platform, it's definitely a Windows version of the Redis installation package (in fact NoSQL is mostly deployed on Linux servers, what's the reason?). We all know, open source + Free = Mature server solution).

(1) Redis related package on GitHub download page: Https://github.com/MSOpenTech/redis

Of course, this address is also available: Https://github.com/dmajkic/redis/downloads

(2) Select the corresponding version, I choose here is the version 2.6, click the Download zip button to download;

(3) Open the compressed package, you can see that we download is actually a complete Redis-2.6 package, contains the bin, src folder, SRC is the source code, and bin is compiled to execute the file, is also our main use of Dongdong. Into the bin directory, you can see that there are two more directories, one for the 32-bit operating system, and the other for the 64-bit operating system.

(4) I am using a 64-bit system, so I will redisbin64.zip copy out, unzip and move to my D:/redis directory, you can see the extracted content contains the following executable EXE files:

Let's see what these executable exe files are for?

redis-server.exe: Service program, is also the most core of a program. In the final analysis, Redis is a service that runs on our server systems, even a process.

②redis-check-dump.exe: Local Database check

③redis-check-aof.exe: Update log check

④redis-benchmark.exe: Performance test to simulate the simultaneous sending of M-Sets/gets queries by n clients. The test results mentioned above are used by the program.

⑤redis-cli.exe: After the server is turned on, our clients can enter various commands to test, such as get, set and other operations;

Also, copy the redis.conf default profile from the package you just downloaded into your working directory (my D:/redis), Redis.conf is primarily a default service configuration for some Redis, including the default port number (typically default 6379).

(5) Since we know that Redis-server.exe is the core of a program, then we first to open it. This needs to be opened in the Windows command line interface, first in the Run window input cmd into the command window, using the CD command to switch to the specified directory (I have just unzipped the file in the D:/redis folder)

(6) Finally, it is thrilling to open the service of Redis, enter a simple command:redis-server.exe redis.conf

It is important to note that the Command Line window does not close after the Redis service is turned on, and the Redis service shuts down as soon as it is turned off. Therefore, we will typically change it to a Windows service and set it to boot automatically, just like the SQL Server service in our database server and the IIS service in the Web server.

(7) is our Redis installed yet? We can open it by new (remember to open a new one instead of turning it off) a CMD window using Redis-cli.exe to test: redis-cli.exe-h Server ip–p Port

(8) Since each time you need to turn on the Redis service in the command window, let's change it to a Windows service and start it automatically. By looking online, I found a batch file and a redisservice executable file in Csdn and copied the two files to the specified Redis directory (my is D:/redis):

Where the code for this batch of install-service files is as follows:

@echo Offset CUR_PATH=%CD%SC Create redis-instance binpath= "\"%cur_path%\redisservice.exe\ "%cur_path%\redis.conf" start= "Auto" displayname= "Redis"

This means creating a Redis service instance in our Windows, specifying the path of the program to start and the path to the configuration file. Note here: Redisservice is another exe, not the one we have just downloaded, this RedisService.exe is: http://pan.baidu.com/s/1sjrvmTf. The startup mode is set to Auto to start, and the service name shown is Redis. In this way, a bat file is ready, and once clicked, a Redis Windows service appears in our list of Windows services, as shown in:

Iv. Summary

With the Sina, the market these large sites at the same time the traffic is soaring, but they can make the user smooth access, the use of REDIS data optimization processing technology. As a result, Redis has been tested by various companies and is a high-performance NoSQL database with a variety of practical uses. So, we. NET developers can use Redis to solve the problem of high concurrency encountered in daily development, the answer is yes. Next, we'll familiarize ourselves with the APIs that Redis provides for our. NET developers, and the common data types (many) that are available in Redis, among others. Finally, I would like to thank the reference author of this article, especially the Wang Chengwei teacher of the Preach Wisdom Podcast, this article is based on its public course video learning organized, thanks to it provides such a good public course tutorial!

Reference documents

(1) Wang Chengwei, http://bbs.itcast.cn/thread-26525-1-1.html, public lessons for Redis podcast

(2) NoSQL Baidu Encyclopedia, http://baike.baidu.com/view/2677528.htm

(3) Bodkin, "NoSQL begins-Why use NoSQL", http://www.infoq.com/cn/news/2011/01/nosql-why/

(4) Redis Baidu Encyclopedia, http://baike.baidu.com/view/4595959.htm

(5) Ruthless, "Installing Redis under Windows", http://www.cnblogs.com/linjiqin/archive/2013/05/27/3101694.html

(6) Zhang Shanyu, "Running Redis on Windows as a service", http://www.cnblogs.com/shanyou/archive/2013/01/17/redis-on-windows.html

Accessories download

(1) Redis-2.6 Service Pack: Http://pan.baidu.com/s/1dDEKojJ

(2) Redis registered batch file for Windows service: Http://pan.baidu.com/s/1jGJtNXs

(3) Startup program for Redis registered Windows services (RedisServcie.exe): http://pan.baidu.com/s/1sjrvmTf

Zhou Xurong

Source: http://www.cnblogs.com/edisonchou/

The copyright of this article is owned by the author and the blog Park, welcome reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to give the original link.

A study of NoSQL everyone loves Redis: (1) Introduction to Redis and simple installation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.