1. Redis
Introduction
1.1. What isRedis
Redis
( Remote Dictionary Server
), that is, the remote dictionary service, is an open-source ANSI C
language-written, network-enabled, memory-based and persistent log-type Key-Value
database, and provides multiple languages API
.
Redis
It is completely open source, complies with BSD
the agreement, and is a high-performance key-value
database.
Redis
Compared with other key - value
caching products, it has the following three characteristics:
Redis
Supports data persistence, can save the data in the memory to the disk, and can be loaded again for use when restarting.Redis
It not only supports simplekey-value
types of data, but also provides storage of data structures such aslist
,set
,zset
, and so on.hash
Redis
Support data backup, that is,master-slave
mode data backup.
1.2. Redis
Advantages
- High performance.
Redis
The speed at which you can read is110000次/s
, and the speed at which you can write is81000次/s
. - Rich data types. Supports the , , , and data type operations
Redis
for the binary case .Strings
Lists
Hashes
Sets
Ordered Sets
- atom.
Redis
All operations on are atomic, meaning they either succeed or fail at all. Individual operations are atomic. Multiple operations also support transactions, ie atomicity, by wrapping themMULTI
with instructions.EXEC
- Rich features.
Redis
Also supportspublish/subscribe
, notification,key
expiration and other features.
1.3. How is it different Redis
from other key-value
storages?
-
Redis
Having more complex data structures and providing atomic operations on them is a different evolution path than other databases.Redis
The data types are based on the basic data structure and are transparent to the programmer without additional abstraction. -
Redis
It runs in memory but can be persisted to disk, so memory needs to be weighed when performing high-speed reading and writing of different data sets, because the amount of data cannot be larger than the hardware memory. Another advantage of having an in-memory database is that it is very simple to operate in-memory compared to the same complex data structure on disk, whichRedis
can do a lot of things with a lot of internal complexity. Also, they are compact in terms of on-disk format and are append-generated, since they do not require random access.
2. Linux
Stand-alone installation
2.1. Download Redis
the installation package
Log in to the official website to download Redis
the installation package, redis official website
2.2. Installation Redis
dependencies
First you need to install Redis
the required dependencies:
yum install -y gcc tcl
2.3. Redis
Installation package upload server
Redis
Then upload the installation package downloaded from the official website to Linux
any directory of the server, for example to /home
the directory:
2.4. Unzip Redis
the installation package
Use the unzip command to unzip Redis
the installation package
tar -xvf redis-6.2.4.tar.gz
After decompression:
2.5. Compile and install
Enter redis
the directory:
cd redis-6.2.4
Run the compile command:
make && make install
If there are no errors, the installation should be successful.
Then modify redis.conf
some configurations in the file:
# 绑定地址,默认是127.0.0.1,会导致只能在本地访问。修改为0.0.0.0则可以在任意IP访问
bind 0.0.0.0
# 数据库数量,设置为1
databases 1
# 设置redis认证密码
requirepass 123456
2.6. StartupRedis
start Redis
:
./src/redis-server redis.conf
After the command window is closed, Redis
the service will also be closed, which does not meet business needs, so it needs to be Redis
started in the background.
Modify redis.conf
file configuration:
# 设置redis认证密码
daemonize yes
Restart Redis
the service after modification:
2.7. TestingRedis
Redis Desktop Manager
Test with visualization tools