Article Directory
1. What is Redis
Redis: REmote DIctionary Server (remote dictionary server)
is completely open source and free. It is written in C language and complies with the BSD protocol. It is a high-performance (key/value) distributed memory database that runs on memory and supports persistence. NoSQL database is currently one of the most popular NoSql databases, and is also called a data structure server
2. Redis features
- The performance is extremely high. Redis can read 110,000 times/s and write 81,000 times/s.
- Redis supports data persistence, which can keep the data in the memory on the disk, and load it again for use when restarting.
- Redis not only supports simple key-value data, but also provides storage for list, set, zset, hash and other data structures.
- Redis supports data backup, that is, data backup in master-slave mode.
3. What can Redis do
- Memory storage and persistence: Redis supports asynchronous writing of data in memory to the hard disk without affecting the continued service.
- The operation of fetching the latest N data, such as: you can put the IDs of the latest 10 comments in the Redis List collection.
- The simulation is similar to the function of HttpSession which needs to set the expiration time.
- Publish and subscribe message system
4. Install redis
Chinese official website: Http://www.redis.cn/ For
Redis development in the enterprise, 99% are the use and installation of Linux version.
The first step is to download redis
wget http://download.redis.io/releases/redis-4.0.6.tar.gz
Step 2: Unzip the compressed package
tar -zxvf redis-4.0.6.tar.gz
[root@iZwz991stxdwj560bfmadtZ local]# tar -zxvf redis-4.0.6.tar.gz
The third step yum installs gcc dependencies
yum install gcc
[root@iZwz991stxdwj560bfmadtZ local]# yum install gcc
When you encounter a choice, enter y
The fourth step is to jump to the redis decompression directory
cd redis-4.0.6
[root@iZwz991stxdwj560bfmadtZ local]# cd redis-4.0.6
The fifth step is to compile and install
make MALLOC=libc
[root@iZwz991stxdwj560bfmadtZ redis-4.0.6]# make MALLOC=libc
Add the files in the /usr/local/redis-4.0.6/src directory to the /usr/local/bin directory
cd src && make install
[root@iZwz991stxdwj560bfmadtZ redis-4.0.6]# cd src && make install
CC Makefile.dep
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
5. Start redis
Method 1: Start redis directly
./redis-server
[root@iZwz991stxdwj560bfmadtZ src]# ./redis-server
18685:C 13 Dec 12:56:12.507 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
18685:C 13 Dec 12:56:12.507 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=18685, just started
18685:C 13 Dec 12:56:12.507 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0.6 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 18685
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
18685:M 13 Dec 12:56:12.508 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
18685:M 13 Dec 12:56:12.508 # Server initialized
18685:M 13 Dec 12:56:12.508 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
18685:M 13 Dec 12:56:12.508 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
18685:M 13 Dec 12:56:12.508 * Ready to accept connections
As shown in the figure above: redis is successfully started, but this startup method needs to keep the window open and other operations cannot be performed, which is not convenient.
Press ctrl + c to close the window.
Method two start redis as a background process
The first step: modify the redis.conf file
will
daemonize no
change into
daemonize yes
Step 2: Specify the redis.conf file to start
redis-server /usr/local/redis-4.0.6/redis.conf
ps -aux | grep redis查看redis进程
In this way, redis is successfully installed on linux