Basic knowledge
1. Redis data type:
Strings, lists, sets, ordered sets, hashs
2. The uniqueness of Redis and memcache:
(1) Redis can be used for storage (storge), while memcache is used for cache (cache). This feature is mainly because it has the function of "persistence"
(2) The stored data has a "structure". For memcache, there is only one type of stored data - "string", while redis can store strings, linked lists, collections, ordered sets, and Has-order structures
3. Two ways to persist:
Redis stores data in memory or is configured to use virtual memory.
There are two ways to achieve data persistence:
(1) Use screenshots to continuously write data in memory to disk (high performance, but may cause a certain degree of data loss)
(2) Use a method similar to mysql to record the logs updated every time
4. Redis's master-slave synchronization: very beneficial for improving read performance
5. The default port of Redis server is 6379
Next, let's install Redis
1. First download the redis installation package from Redis official website (redis.io)
2. Download it to my /lamp directory
3. Unzip and enter its directory
4. Compile the source program
The code copy is as follows:
Make
cd src
make install PREFIX=/usr/local/redis
5. Move the configuration file to the redis directory
6. Start the redis service
7. By default, Redis is not run in the background, we need to run redis in the background
The code copy is as follows:
vim /usr/local/redis/etc/redis.conf
Change the value of daemonize to yes
8. Client connection
The code copy is as follows:
/usr/local/redis/bin/redis-cli
9. Stop the redis instance
The code copy is as follows:
/usr/local/redis/bin/redis-cli shutdown
or
The code copy is as follows:
pkill redis-server
10. Let Redis start automatically
The code copy is as follows:
vim /etc/rc.local
join in
The code copy is as follows:
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis-conf
11. Next, let’s take a look at the several files in the /usr/local/redis/bin directory.
The code copy is as follows:
redis-benchmark: redis performance testing tool
redis-check-aof: Tool to check aof log
redis-check-dump: a tool for checking rdb logs
redis-cli: the client used to connect
redis-server: redis service process
Redis configuration
daemonize: If you need to run in the background, change the value of this item to yes
pdifile: Put the pid file in /var/run/redis.pid, and you can configure it to other addresses
bind: Specify that redis only receives requests from this IP. If not set, all requests will be processed. It is best to set this item in the production process
port: listen to the port, default is 6379
timeout: Set the timeout time when the client connects, in seconds
loglevel: The levels are divided into 4 levels, debug, revbose, notice and warning. In production environment, notice is generally enabled
logfile: Configure the log file address, use standard output by default, that is, print on the port of the command line terminal
database: Set the number of databases, the default database is 0
save: Set the frequency of redis for database mirroring
rdbcompression: Whether to compress when mirroring backup
dbfilename: The file name of the mirror backup file
dir: the path to the file placement of the database mirror backup
slaveof: Set this database to another database's slave database
masterauth: When the main database connection requires password verification, set here
requirepass: Set the password you need to use before making any other specifications after the client is connected
maxclients: Limit the number of clients connected simultaneously
maxmemory: Set the maximum memory that redis can use
appendonly: After turning on appendonly mode, redis will append each received write operation to appendonly.aof file. When redis restarts, the previous state will be restored from the file.
appendfsync: Set the frequency of synchronizing appendonly.aof file
vm_enabled: Whether to enable virtual memory support
vm_swap_file: Set the path to the swap file in virtual memory
vm_max_momery: Set the maximum physical memory size that redis will use after turning on virtual memory, default is 0
vm_page_size: Set the size of the virtual memory page
vm_pages: Set the total number of pages for swap files
vm_max_thrrads: Set the number of threads used simultaneously in vm IO