[Redis 1] Redis database learning and practices-installation and deployment, redis learning and practices
Redis database learning and practice-installation and deployment 1: Redis database introduction:
Redis-Remote DictionaryServer can be directly understood as a Remote dictionary service.
Here, I will extract a section on the official Redis website, which seems to give a more accurate overview of the meaning of Redis: Redis is an open source, BSD licensed, advancedKey-valuecacheAndStore. It is often referred to asDatastructure serverSince keys can containstrings, hashes, lists, sets, sorted sets, bitmapsandhyperlogs.
Redis database is a high-performance key-value database. Redis is completely open-source and free of charge. It complies with the BSD Protocol and is an advanced key-value persistence product. It is usually called a Data Structure server, because values can be strings, maps, lists, sets) and sorted sets. These data types support push/pop, add/remove, intersection and Union operations, and richer operations. Redis supports sorting in different ways. To ensure efficiency, the data is cached in the memory. It can also periodically write the updated data to the disk or write the modification operation to the append record file.
Ii. Redis database usage:
At present, the world's largest Redis user is Sina Weibo. There are more than 200 physical machines in Sina, and more than 400 ports are running this Redis, there are more than 4 GB of data available in Redis to provide services for Sina Weibo users.
There are many deployment scenarios for Sina Weibo Redis, which are roughly divided into the following two types:
1: applications directly access the Redis database;
2: The application directly accesses Redis. MySQL is accessed only when Redis access fails.
Apsaradb for Redis provides a variety of flexible data structures and operations to build different data structures for different big data.
Specific application scenarios:
1: requests for retrieving the latest N data;
2: Ranking application, top n operation;
3: applications that need to precisely set the expiration time;
4: Counter application;
5: Uniq operation to obtain the values of all data records in a certain period of time;
6: Real-Time System and Anti-Spam system;
7. Build a Real-Time Message System Using Pub/Sub (subscription/publish;
8: Build a queue system;
9: cache.
Comparison of Redis, Mysql, and MongoDB databases:
Different \ Databases |
Redis |
Mysql |
MongoDB |
1 |
Library |
Library |
Library |
2 |
None |
Table |
Set |
3 |
None |
Field/row/column |
None |
Iii. Redis installation and deployment:
1: Download, decompress, and install:
After being compiled on the official website, it is applicable to 64-bit linuxlinuxlinuxsystem's redis-2.8.13.tar.gz, then copied to the Linux system, and executed the following command:
# Step 1 $ Tar zxvf redis-2.8.13.tar.gz $ Mv redis-2.8.13 redis $ Cd redis $ Make # Step 2 $ Cd redis/src $ Make install |
2: Start Redis:
The default port of Redis is 6379.
# Start the redis Service $ Cd redis $ Cd redis/src $ Redis-server # Setting the redis configuration file $ Cd redis $ Sudo vim redis. conf |
3: modify the configuration file and set the background to run:
First, modify the redis. conf file:
Modify the configuration option daemonize to yes and save and exit.
Start redis and set the configuration file:
$ Redis-server/home/djy/toolkit/redis. conf |
Verify whether the setting is successful:
The running result is as follows:
Djy 6262 2972 0 00:00:00 pts/1 redis-server *: 6379 Djy 9539 2972 0 00:00:00 pts/1 grep redis |
View the status of port 6379:
$ Netstat-tunpl | grep 6379 |
4: Enter the Redis client redis-cli
The running result is as follows, indicating that the client is successfully entered:
Djy @ ubuntu :~ /Toolkit/redis/src $ redis-cli Wagner. 0.0.1: 6379> Wagner. 0.0.1: 6379> Wagner. 0.0.1: 6379> Wagner. 0.0.1: 6379> |
5. Disable redis-server.
# Method 1 $ Pkill redis-server # Method 2 $ Redis-cli shutdown |
Redis cache Problems
Redis does not have this function. It is only a key-value database, and the cache must be stored in redis using programs.
Redis: Why didn't I save data when I installed redis in windows?
No persistence Mechanism
Redis is a memory database, so it is not saved to the hard disk by default.