Getting started with redis, install stand-alone redis on Linux

Redis installation under Linux (super detailed version)
1. Environment configuration
Redis is developed by c, so the installation of redis requires a compilation environment of c language, that is, gcc needs to be installed

How to check if gcc is installed

gcc -v

1
If there is no gcc, you need to install it online. The command is as follows

yum install gcc-c++

1
2. Redis installation steps
2.1 Upload the redis compressed package to the server The
author here is operated through Xftp 6, as shown in the figure
Insert picture description here
2.2 Decompress the redis compressed package, the decompression command is as follows

tar zxf redis-3.0.0.tar.gz

2.3 Enter the redis-3.0.0 directory.
The decompressed file here is redis-3.0.0. You can rename it according to your needs or use other versions of redis
2.4. After entering the redis directory, ls opens the file in the directory, as shown below Show:
Insert picture description here
2.5 Check whether there is a Makefile file, if it exists, make directly compile the redis source code
Insert picture description here

2.6 is as follows, then the compilation is successful
Insert picture description here2.7 Install the compiled redis code to the specified directory, generally stored in the redis directory under /usr/local, the instructions are as follows

make install PREFIX=/usr/local/redis

As shown in the figure below, it means that the installation is successful.
Insert picture description hereCheck the /user/local directory. You can find that there is an additional redis directory.
Insert picture description here2.8 Check the files in the bin directory under the redis directory. As shown in
Insert picture description here
2.9, you can start redis. The default startup mode is front-end startup , The instructions are as follows

./redis-server

Insert picture description here
2.10 If the front-end is started, if the client is closed, the redis service will also stop, so you need to change to the background to start redis. The
specific method is divided into two steps -> the first step: copy the redis.conf file in the redis decompression file to the current Directory, the instructions are as follows

cp ~/redis-3.0.0/redis.conf .

Step 2: Modify the redis.conf file, daemonize no -> daemonize yes, so that the startup mode is modified to background startup

vim redis.conf

Insert picture description here
Then save the modification and exit, the instruction is as follows (four-step operation)
Esc ->: -> wq -> Enter (Enter)

2.11 Start redis -> start in background

./redis-server redis.conf

Insert picture description here
2.12 Check whether redis is running, the instructions are as follows

ps aux|grep redis

2.13 Open redis connection

./redis-cli

If the connection is successful, as shown below
Insert picture description here2.14 will connect to other ports, the command is as follows

./redis-cli -h 192.168.25.153 -p 6379

Insert picture description here
3.Redis commonly used commands (included)
3.1 String -> KV format to store data, such as storing K=str1, V=abc

set str1 abc

Get the value of key=str1

get str1

3.2 The operation of hash is similar to String, but hash is a mapping table of String type field and value

//存储数据
hset str2 field def
//获取数据
hget str2 field

3.3 View the validity period of the data -> ttl key

//查看str1的有效期
ttl str1

The result is equal to -1 -> the validity period is permanent

The result is equal to -2 -> the data does not exist

Result -> Any number greater than 0 -> The data validity period is the current number of seconds. For example, the result is 120, which means that the data validity period is 120 seconds.

3.4 Determine whether the key exists -> exits key

//判断是否存在str1这个key
exits str1

3.5 Get the type of the specified key -> type key

//获取str1的数据类型
type str1

Copyright statement: This article is the original article of the CSDN blogger "Cool Watermelon". It follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this statement for reprinting.
Original link: https://blog.csdn.net/qq_42815754/article/details/82832335

Guess you like

Origin blog.csdn.net/weixin_44887276/article/details/114981296