Redis-related shell commands
I. Overview
1 Introduction
Redis (Remote Dictionary Server) is a remote dictionary service.
It is an open-source log-type and key-value database written in ANSI C language, supports network, can be memory-based or persistent, and provides APIs in multiple languages. At the same time, it periodically writes updated data to disk or writes modification operations to additional record files, and on this basis realizes master-slave (master-slave) synchronization, also known as a structured database.
2. Function
(1) Memory storage, persistence, and memory are lost when power is off, so persistence is very important (rdb, aof).
(2) High efficiency and can be used for cache.
(3) Publish and subscribe system
(4) Map information analysis
(5) Timers, counters (views)
, etc.
3. Features
(1) Diverse data types
(2) Persistence
(3) Clusters
(4) Transactions
, etc.
4. Official website
Official website (English): Redis official website
Chinese website: Redis Chinese website
Redis is recommended to use on Linux
2. Redis-related tests and commands on remote service Docker
1. Redis installation and mounting
1.1 Find all about Redis
docker search redis
1.2 Pull the highest version of Redis
docker pull redis
1.3 Connect to remote server via xftp
For the redis.conf file, you can download the compressed package from the official website first, then put the redis.conf file in your own redis location, and create an empty folder data
1.4 mount
docker run -p 6379:6379 --name redis --restart=always --log-opt max-size=100m --log-opt max-file=2 -v /myredis/redis/redis.conf:/etc/redis/redis.conf -v /myredis/redis/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes
You can read it together with other bloggers on the Internet correspondingly, I will write it simply
1.5 Open the port of the remote server
Open the corresponding port of the remote server so that the machine can connect to this port number
1.6 Modify the configuration file
首先修改peotected-mode yes
改为:protected-mode no
再注释掉bind 127.0.0.1, 或者修改bind 0.0.0.0,表示允许所有ip地址访问
然后重启redis服务就可以了
2. Start using Redis
2.1 Open the Redis client
(1) Method 1
Open the redis client directly
docker exec -it redis redis-cli
(2) Method 2
Enter the container
docker exec -it redis的容器ID /bin/bash
After entering the container, run the redis client
redis-cli
2.2 After opening successfully, check the password
config get requirepass
2.3 Set Redis password
config set requirepass 密码
2.4 Authentication
auth 密码
2.5 Restart Redis
docker restart redis
3. Test Redis
3.1 Ping
127.0.0.1:6379> ping
Indicates a successful connection
3.2 Test set, get
127.0.0.1:6379> set name ww
OK
127.0.0.1:6379> get name
"ww"
127.0.0.1:6379> keys *
1) "name"
4. Stress test
4.1 Test performance
redis-benchmark is a stress testing tool
that comes with the official performance testing tool
redis-benchmark -h localhost -p 6379 -c 100 -n 100000
result
3. Basic knowledge of Redis
1. View the number of Redis databases
1.1 Introduction
Redis has 16 databases by default.
The contents of the redis.conf file are as follows
1.2 shell commands
# 切换数据库
127.0.0.1:6379> select 3
2. View all key values in a database
2.1 shell commands
127.0.0.1:6379> keys *
3. Clear the current database
3.1 shell command
127.0.0.1:6379> flushdb
4. Redis is single-threaded
The speed of Redis is very fast, it is based on memory operation, CPU is not the performance bottleneck of Redis, the bottleneck of Redis is based on the memory and network bandwidth of the machine, because the single thread is already very fast, it is written in C language.
Speed: CPU>Memory>Hard Disk
Redis puts all data in memory. If multi-threading is used, context switching is a time-consuming operation for redis. Without context switching, the efficiency is the highest.