Detailed explanation of how to install and configure Redis (Linux environment)
How to installRedis? The following article will introduce to you how to install and configure Redis in a Linux environment.
[Related recommendations: Redis video tutorial]
1. Prepare the gcc environment
yum install gcc-c++
The following log appears, which means the installation is successful. Package gcc-c -4.8.5-39.el7.x86_64 already installed and latest version
Loaded plugins: fastestmirror Determining fastest mirrors base | 3.6 kB 00:00:00 docker-ce-stable | 3.5 kB 00:00:00 epel | 4.7 kB 00:00:00 extras | 2.9 kB 00:00:00 nginx | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/7): epel/x86_64/group_gz | 95 kB 00:00:00 (2/7): epel/x86_64/updateinfo | 1.0 MB 00:00:00 (3/7): docker-ce-stable/x86_64/primary_db | 45 kB 00:00:00 (4/7): extras/7/x86_64/primary_db | 205 kB 00:00:00 (5/7): updates/7/x86_64/primary_db | 3.0 MB 00:00:00 (6/7): epel/x86_64/primary_db | 6.8 MB 00:00:00 (7/7): nginx/x86_64/primary_db | 55 kB 00:00:02 Package gcc-c++-4.8.5-39.el7.x86_64 already installed and latest version Nothing to do [root@root ~]#
2. Download and install Redis
Execute command: wget http://download.redis.io/releases/redis-5.0.7.tar.gz
. Unzip it after the download is complete. Then execute the make
and make install
commands successively.
[root@root /]# cd usr/java [root@root java]# mkdir redis [root@root java]# cd redis/ [root@root redis]# wget http://download.redis.io/releases/redis-5.0.7.tar.gz [root@root redis]# tar -zxvf redis-5.0.7.tar.gz [root@root redis]# cd redis-5.0.7 [root@root redis-5.0.7]# make [root@root redis-5.0.7]# make install
3. Start
Enter the command: redis-server redis.conf
, start Redis
. Seeing the following page means the startup is successful.
[root@root redis-5.0.7]# redis-server redis.conf _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 5.0.7 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 12513 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-'
But this kind of startup cannot do any operations under this tab
page, because after using Ctrl c at this time, it becomes like this. That is to say, Redis
is closed. This method is started in the foreground.
^C13082:signal-handler (1594381754) Received SIGINT scheduling shutdown... 13082:M 10 Jul 2020 19:49:14.132 # User requested shutdown... 13082:M 10 Jul 2020 19:49:14.132 * Saving the final RDB snapshot before exiting. 13082:M 10 Jul 2020 19:49:14.135 * DB saved on disk 13082:M 10 Jul 2020 19:49:14.135 * Removing the pid file. 13082:M 10 Jul 2020 19:49:14.135 # Redis is now ready to exit, bye bye...
4. Background startup
Open the redis.conf
file. This is also the configuration file of Redis
.
[root@root redis-5.0.7]# vim redis.conf #打开之后,在命令窗口按下/输入daem然后回车
Change to yes
daemonize yes
Redis does not run as a daemon process by default. You can modify it through this configuration item and use yes to enable the daemon. Process, after enabling the daemon process, Redis will write the pid to a pidfile in the /var/run/redis_6379.pid file.
Start again
[root@root redis-5.0.7]# redis-server redis.conf 13352:C 10 Jul 2020 19:54:34.301 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 13352:C 10 Jul 2020 19:54:34.301 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=13352, just started 13352:C 10 Jul 2020 19:54:34.301 # Configuration loaded
5. Connect to Redis
[root@root redis-5.0.7]# redis-cli 127.0.0.1:6379> ping PONG 127.0.0.1:6379> config get requirepass #查看密码 1) "requirepass" 2) "" 127.0.0.1:6379>
Set password
We found that we can enter Redis
without a password. So how to set it up?
requirepass foobared
: Set the Redis
connection password. If the connection password is configured, the client needs to pass AUTH when connecting to
Redis The password
command provides a password, which is turned off by default.
1. Temporary setting
config set requirepass 123456
2. Permanent setting
[root@root redis-5.0.7]# vim redis.conf #打开之后,在命令窗口按下/输入 requirepass 然后回车
Find the content as shown in the picture, release the comment and set your own password.
Then restart Redis
.
[root@root redis-5.0.7]# redis-server redis.conf [root@root redis-5.0.7]# redis-cli 127.0.0.1:6379> ping (error) NOAUTH Authentication required. 127.0.0.1:6379> auth xxx OK 127.0.0.1:6379> ping PONG 127.0.0.1:6379>
You can see that when I ping
for the first time, I am prompted that I need to authenticate. auth xxx
This is to enter the password after connecting. You can also enter when connecting:
[root@root redis-5.0.7]# redis-cli -p 6379 -a xxx
Online experience: try.redis.io/
This article is reproduced from: https://juejin.cn /post/6979019298543140901#heading-4
Author: Programmer Xiaojie
For more programming-related knowledge, please visit: Programming Teaching! !
The above is the detailed content of Detailed explanation of how to install and configure Redis (Linux environment). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Redis cluster mode deploys Redis instances to multiple servers through sharding, improving scalability and availability. The construction steps are as follows: Create odd Redis instances with different ports; Create 3 sentinel instances, monitor Redis instances and failover; configure sentinel configuration files, add monitoring Redis instance information and failover settings; configure Redis instance configuration files, enable cluster mode and specify the cluster information file path; create nodes.conf file, containing information of each Redis instance; start the cluster, execute the create command to create a cluster and specify the number of replicas; log in to the cluster to execute the CLUSTER INFO command to verify the cluster status; make

Redis uses hash tables to store data and supports data structures such as strings, lists, hash tables, collections and ordered collections. Redis persists data through snapshots (RDB) and append write-only (AOF) mechanisms. Redis uses master-slave replication to improve data availability. Redis uses a single-threaded event loop to handle connections and commands to ensure data atomicity and consistency. Redis sets the expiration time for the key and uses the lazy delete mechanism to delete the expiration key.

To view all keys in Redis, there are three ways: use the KEYS command to return all keys that match the specified pattern; use the SCAN command to iterate over the keys and return a set of keys; use the INFO command to get the total number of keys.

The best way to understand Redis source code is to go step by step: get familiar with the basics of Redis. Select a specific module or function as the starting point. Start with the entry point of the module or function and view the code line by line. View the code through the function call chain. Be familiar with the underlying data structures used by Redis. Identify the algorithm used by Redis.

Using the Redis directive requires the following steps: Open the Redis client. Enter the command (verb key value). Provides the required parameters (varies from instruction to instruction). Press Enter to execute the command. Redis returns a response indicating the result of the operation (usually OK or -ERR).

The following two methods can be used to clear data in Redis: FLUSHALL command: Delete all keys and values in the database. CONFIG RESETSTAT command: Reset all states of the database (including keys, values, and other statistics).

The steps to start a Redis server include: Install Redis according to the operating system. Start the Redis service via redis-server (Linux/macOS) or redis-server.exe (Windows). Use the redis-cli ping (Linux/macOS) or redis-cli.exe ping (Windows) command to check the service status. Use a Redis client, such as redis-cli, Python, or Node.js, to access the server.

Redis counter is a mechanism that uses Redis key-value pair storage to implement counting operations, including the following steps: creating counter keys, increasing counts, decreasing counts, resetting counts, and obtaining counts. The advantages of Redis counters include fast speed, high concurrency, durability and simplicity and ease of use. It can be used in scenarios such as user access counting, real-time metric tracking, game scores and rankings, and order processing counting.
