Redis Introduction and Getting Started Installation and Use


title: Redis Introduction and Getting Started Installation and Use
author: MegaSlark
DATE: 2019-10-01 12:52:17
the Summary: Introduction and Getting Started Redis installation and use of
the Categories: Redis
Tags:

  • Redis
  • CentOS7

Redis Introduction and Getting Started Installation and Use

What is Redis

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster。

Redis according to the official website, we can see that Redis has the following functions and features:

  • Redis is an open source, memory-based data structure stored BSD protocol, may be used as a database, cache, the message broker .
  • Supported data formats include: strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries, streams.
  • Redis itself provides copy, Lua script, LRU clear, transactions, and persistence mechanisms at different levels, through Sentinel and Cluster to ensure high availability.

Why choose Redis

  • Excellent performance, the official certification Redis Redis performance under different CPU, the interested student venue, https://redis.io/topics/benchmarks , 10W + per read or write operation is entirely a piece of cake, of course, in practice, because the service server CPU / environment out there was a little, but enough to cope with that most complex scenarios.
  • Support complex data structures, in addition to the usual KEY -Value, also supports a variety of other complex data structures, such as Set, Lists, bitmaps, hyperloglogs, geospatial, stream.
  • It provides persistence function to facilitate rapid recovery of data.
  • Support separate read and write, copy from the master, Sentinel mode, cluster mode, to ensure high availability.
  • No content restrictions on the size of the storage of Value. Convenience store large data.

Installation Redis

The latest stable version of the official website is: [ Redis 5.0.6 IS stable at The Latest Version ]: HTTP: //download.redis.io/releases/redis-5.0.6.tar.gz.

Redis installation

$ wget http://download.redis.io/releases/redis-5.0.6.tar.gz
$ tar xzf redis-5.0.6.tar.gz
$ cd redis-5.0.6
$ make

If there are mistakes in the implementation of make command:

/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/opt/software/redis/redis-5.0.6/src'
make: *** [all] Error 2

Description is not installed gcc, because Redis is implemented in C, so it is necessary to install gcc to compile.

Gcc installation instructions:

yum install gcc

After installation the following operations:

# 删除上次安装的Redis目录及子目录
$ rm -rf redis-5.0.6
# 重新解压和编译
$ tar xzf redis-5.0.6.tar.gz
$ cd redis-5.0.6
$ make

Start the server

# 启动服务端
[enjoyitlife@localhost redis-5.0.6]$ src/redis-server 
# 启动成功会显示如下信息
[enjoyitlife@localhost redis-5.0.6]$ src/redis-server 
11872:C 20 Nov 2019 07:13:57.586 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
11872:C 20 Nov 2019 07:13:57.586 # Redis version=5.0.6, bits=64, commit=00000000, modified=0, pid=11872, just started
11872:C 20 Nov 2019 07:13:57.586 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
11872:M 20 Nov 2019 07:13:57.589 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
11872:M 20 Nov 2019 07:13:57.590 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
11872:M 20 Nov 2019 07:13:57.590 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.6 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 11872
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

11872:M 20 Nov 2019 07:13:57.594 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
11872:M 20 Nov 2019 07:13:57.595 # Server initialized
11872:M 20 Nov 2019 07:13:57.595 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
11872:M 20 Nov 2019 07:13:57.595 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
11872:M 20 Nov 2019 07:13:57.595 * Ready to accept connections

Client connections

# 新开一个Shell 窗口 
[enjoyitlife@localhost ~]$ cd /opt/software/redis/redis-5.0.6
[enjoyitlife@localhost redis-5.0.6]$ src/redis-cli
# 表示连接成功
127.0.0.1:6379>

Command to test

127.0.0.1:6379> set name enjoyitlife
OK
127.0.0.1:6379> get name
"enjoyitlife"
127.0.0.1:6379> 

Set Redis running in the background

# 修改redis.conf 中 daemonize no 改成 yes
daemonize yes
# 可以先将文件改下名,然后在启动的时候 以指定的文件启动 
 [enjoyitlife@localhost redis-5.0.6]$ cp redis.conf redis6379.conf 
[enjoyitlife@localhost redis-5.0.6]$ src/redis-server redis6379.conf 

# 此时就不会出现Redis的Logo图片了,而是如下说明, 表明后台启动Redis成功
[zpenjoy@localhost redis-5.0.4]$ src/redis-server redis6379.conf 
11920:C 20 Nov 2019 07:21:21.021 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
11920:C 20 Nov 2019 07:21:21.022 # Redis version=5.0.6, bits=64, commit=00000000, modified=0, pid=11920, just started
11920:C 20 Nov 2019 07:21:21.022 # Configuration loaded

Stop Redis service

# 可以通过关闭进程的方式 强制关闭 不建议使用该方式
[enjoyitlife@localhost ~]$ ps -ef|grep redis
[enjoyitlife@localhost redis-5.0.6]$ ps -ef|grep redis
enjoyit+  11921      1  0 07:21 ?        00:00:00 src/redis-server 127.0.0.1:6379
enjoyit+  11929  11898  0 07:23 pts/1    00:00:00 src/redis-cli
enjoyit+  11956  11933  0 07:25 pts/0    00:00:00 grep --color=auto redis

[enjoyitlife@localhost redis-5.0.6]$ kill -9 11921
# 推荐方式
./src/redis-cli shutdown

Well, Redis basic introduction and installation described here, thank you read.

Guess you like

Origin www.cnblogs.com/enjoyitlife/p/11901995.html