The initial Redis
-
REmote DIctionary Server(Redis) is a key-value storage system written by Salvatore Sanfilippo that is a cross-platform non-relational database.
-
Redis is an open source ANSI C language, BSD protocol compliant, network-enabled, memory based, distributed, optional persistence key-value database storage, and provides a multi-language API.
-
Redis is often referred to as a data structure server because values can be strings, hashes, lists, sets, and sorted sets.
Recommend a blog about Redis: The easy to understand Introduction to Redis
Redis Installation (on Linux)
The installation
- Download the Redis installation package from the official website
- Move the installation package to the opt directory
Sudo mv redis - 6.2.2. Tar. Gz/optCopy the code
- Unzip the Redis installation package
Sudo tar - ZXVF redis - 6.2.2. Tar. GzCopy the code
- Access the decompressed Redis file and view the Redis configuration file
cdRedis - 6.2.2 lsCopy the code
- Install the base environment command (install GCC) and check whether the installation was successful
yum install gcc-c++
gcc -v
Copy the code
- Precompile and compile installation
make # precompiled
make install # build install
Copy the code
- And because the default Redis installation directory is
/usr/local/bin
Go to the directory and create a foldermyconfig
sudo mkdir myconfig
Copy the code
- Copy the Redis configuration file to
myconfig
Sudo cp /opt/redis-6.2.2 /redis.conf myconfigCopy the code
- Modify the redis.conf configuration to enable Redis to start in the background (redis does not start in the background by default)
vim redis.conf
Copy the code
Use the test
- Start the service from the specified configuration file
redis-server myconfig/redis.conf
Copy the code
- Client access
redis-cli -p 6379
Copy the code
- through
ping
Test the connection
- through
Set Attribute name Attribute value
Store value - through
The get property name
The values
- Check whether the Redis process is started
ps -ef|grep redis
Copy the code
- Stop the Redis service
shutdown
exit
ps -ef|grep redis # Check again to confirm closing
Copy the code
There is a bug in the installation
–> < p style = “max-width: 100%; clear: both; min-height: 1em
The performance testredis-benchmark
- This command is executed in the redis directory, not in the Redis client
- Performance test tool parameters
- The instance test
- Test content: 100 concurrent processing of 100,000 requests
- After the service is enabled, enter a value on the terminal
redis-benchmark -c 100 -n 100000
Basic knowledge of
- Redis has 16 databases installed by default and uses database 0 by default
- Set a value to the database, value
- Query all values of the database
keys *
- Conversion database
Select the database to which you want to convert
- Deletes a value from the database
flushdb
Clearing the current database
flushall
Clearing all databases
Extracurricular supplementary
Redis is single-threaded:
With Redis, there is almost no CPU bottleneck; Redis is largely limited by memory and network. On a normal Linux system, for example, Redis can handle a million requests per second using Pipelining, so if the application uses mainly O(N) or O(log(N)) commands, it hardly consumes much CPU.
- In fact, Redis is based on memory operation, redis is to put all the data in memory.
- High maintainability after using single thread.
- Although multithreaded model has excellent performance in some aspects, it introduces the uncertainty of program execution order, brings a series of problems of concurrent read and write, increases the system complexity, and may cause performance loss caused by thread switching, even locking and unlocking, deadlock.
- Redis has very high processing performance through AE event model and IO multiplexing, so there is no need to use multithreading. The single-threaded mechanism greatly reduces the complexity of the internal implementation of Redis. Lazy Rehash, Lpush and other “thread-unsafe” commands of Hash can be executed without locking.
Multithreading was introduced after Redis6.0
The reason:
-
Redis keeps all the data in memory, and the memory response time is about 100 nanoseconds. For small packets, the Redis server can handle 80,000 to 100,000 QPS, which is the limit of Redis processing. For 80% of companies, single-threaded Redis is sufficient.
-
Twenty percent of companies, with increasingly complex business scenarios that may require hundreds of millions of transactions, need larger QPS.
-
Using multiple threads can make full use of server CPU resources, currently the main thread can only use one core
-
Multithreading tasks can share the load of Redis synchronous IO reads and writes
Although Redis introduces multithreading, it is turned off by default.
There is also a blog about default multithreading initialization parameters.