Overview and installation of Redis

Posted by hucklebezzer on Thu, 27 Jan 2022 16:28:37 +0100

Redis overview

What is Redis

Redis (Remote Dictionary Server), that is, remote dictionary service, is an open source log type and key value database written in ANSI C language, supporting network, memory based and persistent, and provides API s in multiple languages. Redis has largely compensated for its emergence memcached This kind of key/value storage is insufficient, which can play a good supplementary role to the relational database on some occasions.

Why learn Redis

It can be said that among major companies, redis is an essential service. In the era of big data, the database cannot support ultra-high QPS, and using redis as the intermediate cache can well solve this problem. When you need to query data, first request redis. If there is data in redis, take it out and return it. Otherwise, query the database. Redis can't get around the interview of major companies. The main purposes of redis are as follows:

  1. High efficiency for caching
  2. Publish subscribe system
  3. Map information analysis
  4. Timer, counter (Views)
  5. ...

characteristic

  1. The performance is extremely high. Some tests show that the reading speed is 110000 times / s and the writing speed is 81000 times / s.
  2. Various data structures, such as string, hash, list, set, sorted set, bitmap, hyperlog, geospatial index and stream
  3. Persistence: memory data can be persisted to the hard disk to avoid power failure and data loss.
  4. Cluster: master-slave node, with read-write separation, to achieve high availability of Redis.
  5. Transaction: execute multiple commands in one transaction.
  6. ...

Official website

  1. English official website: https://redis.io/

  2. Chinese official website: http://www.redis.cn/

  3. Windows version download:

    https://github.com/microsoftarchive/redis/releases (it's maintained by Microsoft and has been stopped for a long time)

    https://github.com/tporadowski/redis/releases

Windows setup

Microsoft maintained Redis version It hasn't been updated for a long time. We use it Another open source version Install Windows.

  1. Download installation package

Students with poor network can use the following link: https://pan.baidu.com/s/1aokx10S_Yk3YcPwavmXNOg Extraction code: 9kjs

  1. install

    Follow the screenshot below to install step by step.

Here, you can increase the memory according to your needs, such as 1024M.

  1. Verify availability

The directory we installed is D:/software/redis. Open this directory and you can see the Redis directory structure after installation as follows.

Double click to open Redis server and start Redis service. The interface flashes. At this time, open Task Manager and you can see that Redis is running in the service bar.

If you want to keep the redis server interface in the foreground, you can stop the service and then open redis server. You will see the following interface:

Then open Redis CLI and use the client to connect to Redis. Enter the PING command and see the PONG response, which proves that Redis is successfully installed and available.

Although the installation of Windows version is relatively simple, there may be some bug s due to poor maintenance. It is recommended to use Redis of Linux version for learning.

Linux Installation

Linux installation is also relatively simple. I use Tencent cloud server here. The operating system is CentOS 7.5 64 bit. You can buy cloud server for learning according to your needs (it is cheaper after Alibaba cloud and Tencent cloud student certification), or install virtual machines yourself.

// 1. Download the installation package
[root@VM-0-5-centos opt]# wget https://download.redis.io/releases/redis-6.2.4.tar.gz  

// 2. Decompression
[root@VM-0-5-centos opt]# tar -zxvf redis-6.2.4.tar.gz 

// 3. Enter the directory after decompression
[root@VM-0-5-centos opt]# cd redis-6.2.4/

// 4. make installation
[root@VM-0-5-centos redis-6.2.4]# make 

// 5. After completion, enter the src directory and run Redis
[root@VM-0-5-centos redis-6.2.4]# cd src/
[root@VM-0-5-centos src]# ./redis-server 

This operation mode uses the default configuration file. Redis server runs in the foreground. If you want to use the client connection, you need to open another window to connect, which is more troublesome. Therefore, we modify the configuration file to keep redis running in the background.

ctrl+c ends the current process, enters the upper directory, and modifies the configuration file. The steps are as follows:

// 1. Enter the parent directory from src
[root@VM-0-5-centos src]# cd ..

// 2. Copy a redis Conf configuration file, and then we use my Conf file
[root@VM-0-5-centos redis-6.2.4]# cp redis.conf my.conf

// 3. Modify the configuration file and change the default no to default yes, as shown in the screenshot below
[root@VM-0-5-centos redis-6.2.4]# vim my.conf 

// 4. Use my Conf configuration file to enable redis server
[root@VM-0-5-centos redis-6.2.4]# cd src 
[root@VM-0-5-centos src]# ./redis-server ../my.conf 

// 5. Check whether the Redis process is started
[root@VM-0-5-centos src]# ps aux | grep redis
root      9190  0.1  0.5 162508  9908 ?        Ssl  14:17   0:00 ./redis-server 127.0.0.1:6379
root      9389  0.0  0.0 112828   980 pts/0    R+   14:18   0:00 grep --color=auto redis

// 6. Connect client to server
[root@VM-0-5-centos src]# ./redis-cli 
127.0.0.1:6379> PING
PONG
127.0.0.1:6379> set zero hero
OK
127.0.0.1:6379> get zero
"hero"
127.0.0.1:6379> exit

OK, here we have completed the installation of Redis Linux version. Now we can learn happily.

About me

Personal blog address: https://lifelmy.github.io/

Topics: Redis