what is it
Remote Dictionary Server (remote dictionary service) is completely open source, written in ANSIC language and complies with BSD protocol, and is a high-performance Key-Value database . Provides rich data structures, such as String, Hash, List, Set, SortedSet, etc. Data exists in memory, and Redis supports multiple functional features such as transactions, persistence, LUA scripts, publish/subscribe, cache elimination, streaming technology, etc. It provides master-slave mode, Redis Sentinel and Redis Cluster cluster architecture solutions.
It has been more than ten years since Redis was released, and it has always followed its own naming rules:
If the second digit of the version number is an odd number, it is an unstable version such as 2.7, 2.9, 3.1
If the second digit of the version number is an even number, it is a stable version such as 2.6, 2.8, 3.0 , 3.2
Source code of historical releases: https://download.redis.io/releases/
What can I do?
● Distributed cache, a guard with a knife in front of the Mysql database (shared and coordinated use, non-competitive relationship)
○
● Memory storage and persistence (RDB+AOF), redis supports asynchronously writing data in memory to hard disk, At the same time, it does not affect the continued service
● High availability architecture collocation
○ Standalone
○ Master-
slave ○ Sentinel
○ Cluster
● Cache penetration, breakdown, avalanche
● Distributed lock
● Queue
● Ranking plus likes
● …
Advantage
● Extremely high performance – Redis can read at 110,000 seconds/time, and write at 81,000 times/second.
Redis has rich data types, not only supporting simple key-value data, but also providing list, set, and zset , hash and other data structure storage
● Redis supports data persistence, which can keep the data in the memory on the disk, and can be loaded again for use when restarting
● Redis supports data backup, that is, data backup in master-slave mode
The new features of Redis7
are generally consistent and stable with the previous redis version, mainly due to the optimization and improvement of its own underlying performance and resource utilization.
2. Redis installation and configuration
1. Installing Redis on Linux To install Redis, you must first have a gcc compilation environment
(Redis is developed in C language. To install Redis, you need to compile the source code downloaded from the official website first. Compilation depends on the gcc environment. If there is no gcc environment, you need to install gcc)
gcc -v #查看版本
yum -y install gcc-c++ #安装c++库环境
附:
安装gcc
gcc的安装很简单,首先要确保root登录,其次就是Linux要能连外网:
yum -y install gcc automake autoconf libtool make
注意:运行yum时出现/var/run/yum.pid已被锁定,
PID为xxxx的另一个程序正在运行的问题解决:
rm -f /var/run/yum.pid
2. Download Redis through the command line
#查看系统多少位,返回是多少就是几位
getconf LONG_BIT
wget http://download.redis.io/releases/redis-7.0.0.tar.gz
3. Unzip redis under the /opt directory
mv redis-7.0.0.tar.gz /opt/
cd /opt
tar -zxvf redis-7.0.0.tar.gz && cd redis-7.0.0
4. Compile and install, execute in the redis-7.0.0 directory
make && make install
Check the redis version command
redis-server -v
5. View the default installation directory /usr/local/bin
cd /usr/local/bin && ls -l
#redis-benchmark:性能测试工具,服务启动后运行该命令,看看自己本子性能如何
#redis-check-aof:修复有问题的AOF文件,rdb和aof后面讲
#redis-check-dump:修复有问题的dump.rdb文件
#redis-cli:客户端,操作入口
#redis-sentinel:redis集群使用
#redis-server:Redis服务器启动命令
6. Copy the default redis.conf to a path defined by yourself, such as /myredis
mkdir /myredis
cp /opt/redis-7.0.0/redis.conf /myredis/
7. Modify the redis.conf configuration file in the /myredis directory to make initialization settings
vim /myredis/redis.conf
redis.conf configuration file, make sure it takes effect after modification, remember to restart, remember to restart
Daemonize process, the default daemonize no is changed to daemonize yes
Protected mode, the default protected-mode yes is changed to protected-mode no
Change the default bind 127.0.0.1 to directly comment out (the default bind 127.0.0.1 can only be accessed locally) or change the local IP address, otherwise it will affect the remote IP connection
Add the redis password to requirepass The password you set yourself requirepass 123456
8. Run redis-server in the /usr/local/bin directory and enable the /myredis directory
redis7conf
cd /usr/local/bin
redis-server /myredis/redis.conf
9. Connection service
redis-cli -a set password -p 6379
[root@VM-4-17-centos bin]# redis-cli -a 123456 -p 6379
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set k1 hellowrold
OK
127.0.0.1:6379> get k1
"hellowrold"
10. Close the service
#Single instance shutdown
redis-cli -a 123456 shutdown
#Multiple instances are closed, and the specified port number is closed
redis-cli -p 6379 shutdown
Warning: Using a password with ‘-a’ or ‘-u’ option on the command line interface may not be safe.
The solution is to remove the standard error, add 2>/dev/null, and discard the standard error, and there will be no annoying warnings.
redis-cli -a 123456 2>/dev/null
Why is the Redis port 6379?
The default port of Redis is 6379, which is determined by the position of the letter MERZ on the phone keyboard. MERZ is synonymous with "stupid and silly B" in the language of Antirez's circle of friends. It originated from the Italian advertising girl Alessia Merz who said a bunch of stupid things on TV shows. The father of redis had a "special" impression of her, so he gave She made it into a port number
Redis7 uninstall step
1, stop redis-server service
pe -ef | grep redis
redis-cli shutdown
2. Delete the redis-related files in the /usr/local/lib directory
ls -l /usr/local/bin/redis-*
rm -rf /usr/local/bin/redis-*