Redis Installation and simple application

Source: Internet
Author: User
Tags benchmark redis version install redis redis server


1. System Environment: CENTOS7.2--X86_64

[email protected] ~]# Cat/etc/centos-release

CentOS Linux release 7.2.1511 (Core)

[email protected] ~]# uname-a

Linux salt1 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 22:10:57 UTC x86_64 x86_64 x86_64 gnu/linux



2. Installing Redis

Prerequisites: First install Epel-release (Epel source)

[email protected] ~]# yum-y Install Epel-release

Then install Redis

[email protected] ~]# yum-y Install Redis

[email protected] ~]# rpm-q Redis

Redis-2.8.19-2.el7.x86_64

[email protected] ~]# redis-

redis-benchmark redis-check-aof redis-check-dump redis-cli redis-sentinel redis-server Redis-shut Down


Redis-server : Daemon Boot program for Redis server

redis-cli : Redis command-line client Operation tool, when it is allowed to use Telnet according to its plain text protocol to operate;

Redis-benchmark : Redis Performance testing tool to test the read and write performance of Redis in your system and in your configuration;

redis-check-aof : For update log appendonly.conf Check, is available, similar to check MySQL Binlog tool;

Redis-check-dump : For the local database Rdb file check;



3. Start the Redis service

Back up your Redis profile (personal habits, back up and Operation first)

[email protected] ~]# Cp/etc/redis.conf{,.bak}

Redis is best to specify its configuration file when booting, because almost all of Redis's control is in its configuration file;

Redis-server : Daemon Boot program for Redis server

/etc/redis.conf : Redis configuration file

& : Background Boot

[email protected] ~]# redis-server/etc/redis.conf &

[1] 9462

[email protected] ~]# ps-ef | grep redis

Root 9462 2767 0 03:59 pts/0 00:00:00 redis-server 127.0.0.1:6379

Root 9466 2767 0 03:59 pts/0 00:00:00 grep--color=auto Redis

And then look at the log.

[email protected] ~]# Tail-30/var/log/redis/redis.log

[9462] 03:59:54.037 * Increased maximum number of open files to 10032 (it is originally set to 1024).

_._

_.-' __ '-._

      _.-``    `.  `_. "-._ Redis 2.8.19 (00000000/0)

.-`` .-```. ' \ \ _.,_ '-._

(',.-' | ',) Running in Stand alone mode

| '-._ '-...-' __...-. '-._| '     ' _.-' | Port: 6379

|     '-._ '. _/_.-' | pid:9462

'-._ '-._ '-./_.-' _.-'

| '-._ '-._ '-.__.-' _.-' _.-' |

|           '-._ '-._ _.-' _.-' | Http://redis.io

'-._ '-._ '-.__.-' _.-' _.-'

| '-._ '-._ '-.__.-' _.-' _.-' |

| '-._ '-._ _.-' _.-' |

'-._ '-._ '-.__.-' _.-' _.-'

'-._ '-.__.-' _.-'

'-._ _.-'

'-.__.-'

[9462] 03:59:54.038 # Server started, Redis version 2.8.19

background save may fail under low memory condition sysctl vm.overcommit_memory=1 "for the" take effect.

you has Transparent Huge Pages (THP) support for enabled in your kernel Span style= "Font-size:16px;background-color:rgb (255,0,0);" >/etc/rc.local

[9462] 03:59:54.040 # WARNING: The TCP backlog setting of 511 cannot be enforced because /pro C/sys/net/core/somaxconn is set to the lower valueof.

[9462] 03:59:54.040 * The server is now ready to accept connections on port 6379


The yellow font is : The problem

the red font is : Solutions



Yellow Font Interpretation:

1. Background save may fail in low memory

vm.overcommit_memory Parameters

The default value is 0

0: When the user space requests more memory, the kernel attempts to estimate the remaining available memory;

1: The kernel allows excessive use of memory until the end of use, mainly for scientific calculation;

2: The kernel will use an algorithm that does not use excessive memory, that is, the entire memory address space of the system cannot exceed swap+50% 's RAM value, and the 50% parameter setting is set in Overcommit_ratio;

2. Enable THP (page memory transparency) in your kernel specific explanation look at the back of the URL, explained in more detail http://os.51cto.com/art/201103/249821.htm

The 3.tcp backlog is set to 511 and cannot be performed because /proc/sys/net/core/somaxconn a lower value

Backlog is the network connection process, a certain state of the queue length, if the concurrency is high, it will cause the backlog queue is full, the server will lose the incoming connection, and then there will be a customer point connection failure situation;

Http://jingyan.baidu.com/article/84b4f565e60f8560f6da3227.html


so the bottom starts . perform the corresponding action

Note: The blue font is where you need to be aware

echo "vm.overcommit_memory = 1" >>/etc/sysctl.confsysctl-p echo "echo Never >/sys/kernel/mm/transparent_hugep age/enabled ">>/etc/rc.localecho" echo 511 >/proc/sys/net/core/somaxconn ">>/etc/rc.local


The following is a companion that needs to be compared

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/85/DA/wKioL1esWQiSVojLAAAVz69F0L0158.png-wh_500x0-wm_3 -wmp_4-s_1212191668.png "title=" Clipboard.png "alt=" Wkiol1eswqisvojlaaavz69f0l0158.png-wh_50 "/>


believe that after 3 lines of configuration, your Redis will not report a similar warning, of course, you also need to specify in the redis.conf file the size of the Redis allowed memory (described in the following chapter), or your server won't last two days



4. Turn off Redis service

1) redis-shutdown#默认会保存后关闭

2) redis-cli shutdown save#



5. Connect to Redis

[Email protected] ~]# redis-cli

127.0.0.1:6379>



6. Simple operation

127.0.0.1:6379> Set ID 001#创建key-vlaue

Ok

127.0.0.1:6379> get ID#查找key

"001"

127.0.0.1:6379> del id#删除key

(integer) 1

127.0.0.1:6379> Get ID

(nil)

127.0.0.1:6379> exists ID#查询id是否存在

(integer) 1

127.0.0.1:6379> del ID

(integer) 1

127.0.0.1:6379> exists ID

(integer) 0

127.0.0.1:6379> keys *#获取所有key

127.0.0.1:6379> Set K1 v1

Ok

127.0.0.1:6379> Set K2 v2

Ok

127.0.0.1:6379> Set K3 v3

Ok

127.0.0.1:6379> keys *#获取所有key

1) "K2"

2) "K3"

3) "K1"

127.0.0.1:6379> dbsize#获取所有key-value number

(integer) 3



Redis defaults to 16 libraries, but cannot see (how many libraries can be configured in redis.conf)

127.0.0.1:6379> Select 1#切换到第二个库 (starting from 0)

Ok

127.0.0.1:6379[1]> Keys *

(empty list or set)

127.0.0.1:6379[1]> Set name 123

Ok

127.0.0.1:6379[1]> keys *

1) "Name"

127.0.0.1:6379[1]> Select 0

Ok

127.0.0.1:6379> keys *

1) "K2"

2) "K3"

3) "K1"

127.0.0.1:6379> Select

Ok

127.0.0.1:6379> Select

(Error) ERR Invalid DB Index


Okay, so the Redis installation is here first.


This article is from the "Rslinux" blog, make sure to keep this source http://readshlinux.blog.51cto.com/9322509/1837039

Redis Installation and simple application

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.