Redis installation and configuration of the Windows version of Redis01

Table of contents

0. Learning URL

https://www.w3cschool.cn/redis/https://www.w3cschool.cn/redis/

1. Introduction to Redis  

2. Download

3. Installation and configuration

3.1 window (slightly...) 

3.2 Linux (CentOS)

4. Redis supports five data types

5. Operate redis through commands


0. Learning URL

https://www.w3cschool.cn/redis/ https://www.w3cschool.cn/redis/

1. Introduction to Redis  

   Redis is an open source (BSD licensed), in-memory data structure server that can be used as a database, cache and message queue broker.
   It supports strings, hash tables, lists, sets, sorted sets, bitmaps, hyperloglogs and other data types. Built-in replication, Lua scripts, LRU reclamation, transactions, and disk persistence functions at different levels, while providing high availability through Redis Sentinel and automatic partitioning through Redis Cluster 

   Learning website:

   https://www.w3cschool.cn/redis/
   www.redis.cn
   www.redis.net.cn

  Redis usage:

1. Database

2. Cache
cluster: sentinel, master-slave, sharding

2. Download

redis-5.0.0.tar.gz(linux)
 Redis-x64-3.2.100.msi(window安装版)
Redis-x64-3.2.100.zip(window解压版) 

3. Installation and configuration

3.1 window (slightly...) 

3.2 Linux (CentOS)

        3.2.1. Decompress redis

$ tar -zxvf redis-5.0.0.tar.gz -C /usr/local/
$ tar -zxf redis-5.0.0.tar.gz -C /usr/local/
$ cd redis-5.0.0

        3.2.2. Install gcc

$ yum install gcc

        3.2.3. Compile redis

$ cd /redis-5.0.0
$ make

        3.2.4. Check the installation

$ make install

        3.2.5. Modify the redis.conf file

Change daemonize no to daemonize yes

        3.2.6. Start redis

./redis-server /lky/redis-5.0.0/redis.conf

Check the redis process: ps -ef | grep redis
Kill the redis process: kill -9 process pid

        3.2.7. Test whether the redis startup is successful

ping

        3.2.8. Configured as a system service

1) Configure redis log file path (optional)

logfile "redis安装目录/logs/redis.log"

2) Create a new redis.service file and configure it as a system service

vi /usr/lib/systemd/system/redis.service

For specific redis.service file content configuration, see redis.service for details

        3.2.9. Overloading system services

systemctl daemon-reload

        3.2.10. Start redis

       systemctl start redis  #启动redis服务
       systemctl stop redis   #停止redis服务
       systemctl status redis #查看redis状态
       systemctl restart redis #重启redis服务
       systemctl enable redis #注册服务
       systemctl disable redis #注销服务

4. Redis supports five data types

string (string)

hash

list (list)

set (collection)

zset (sorted set: ordered collection)

5. Operate redis through commands

There are 16 default databases for redis and 3 for mongodb: admin/local/test

5.1 Basic commands:

# redis-cli //Open the redis terminal
Note: After the password is configured, after logging in, use the following command to log in with the password

redis-cli -h 127.0.0.1 -p 6379 -a 123456

# ping //Test whether redis is installed successfully
# select index //Select the specified database

5.2 Redis String (String)

# set key // save
# get key // get
# type key // view type
# keys * or keys key // view all or specified keys

5.3 Redis hash (Hash)

Redis hash is a mapping table of string type field and value, and hash is especially suitable for storing objects.

# hset key field1 value1 [field2 value2] #Set multiple field-values ​​to the hash table key at the same time
# hget key field #Get the specified field value
# hdel key field #Delete the specified field value
# hgetall key #Query specified All fields of the
key# hexists key field #Query whether the field in the specified key exists
# hlen key #Get the length in the specified key

5.4 Redis list (List)

Redis lists are simply lists of strings, sorted by insertion order. You can add an element to the head (left) or tail (right) of the list

# lpush key value1 value2 value3 #Insert one or more values ​​into the head of the list
# llen key #Get the length of the list
# lindex key index #Get the elements in the list according to the index
# lrange key start sop #View elements within the specified range

5.5 Redis collection (Set)

Redis's Set is an unordered collection of String types. Set members are unique, which means that no duplicate data can appear in the set.

# sadd key value1 [value2] #Add one or more elements to the collection
# scard key #Get the number of elements in the collection
# sscan key cursor [MATCH pattern] [COUNT count] #Iterate the elements in the collection
# exists key #Is there
 

The above is the relevant operation of Redis!

Guess you like

Origin blog.csdn.net/m0_62246061/article/details/128531337