Redis database installation

Redis database Introduction

Redis database is a typical non-relational databases,

There are several advantages redis

Data read and write speeds with high
support rich data types
supported data backup
support data persistence
atomicity

Install and use Redis database

Environmental and Experimental Materials

A centos7 can, Rdis package,

Packages link below
link : https://pan.baidu.com/s/1kV6shNMC9dPHFYwwjQf8hQ&shfl=sharepset
extraction code: x3jo

1.Redis installation and deployment

1) Installation

The bag drag Xshell
[CentOS7-02 the root @ ~] # the tar-3.2.9.tar.gz zxf Redis
[CentOS7-02 the root @ ~] # CD-Redis 3.2.9
[@ CentOS7-02 the root-Redis 3.2. 9] # the make the make install && ( the package without performing ./configure)

(I just show command, if you do not change the path do not execute this command)
the following command can be used to change the installation path,
[root @ CentOS7-02 Redis-3.2.9] # the make PREFIX = / usr / local / install

The default script file does not start, there is a default package, available through this script set the relevant configuration file
[root @ CentOS7-02 ~] # cd /root/redis-3.2.9/utils/
[root @ CentOS7-02 utils] # ./install_server.sh
Here Insert Picture Description
[root @ CentOS7-02 utils] # netstat -anpt | grep Redis
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 4263/redis-server 1

2) Start the service shut down

[CentOS7-02 the root @ ~] # /etc/init.d/redis_6379 STOP (off)
Stopping ...
Redis stopped

[root @ CentOS7-02 ~] # /etc/init.d/redis_6379 Start (open)
Starting Redis server...

[root @ CentOS7-02 ~] # /etc/init.d/redis_6379 Status
Redis is running (4280) If it is turned off, it will display the running, but behind the figures do not show that (process ID)

[CentOS7-02 the root @ ~] # /etc/init.d/redis_6379 the restart (restart)

2.Redis command tool

1) Redis command-line tool

[root @ CentOS7-02 ~] # Redis-cli (landing native Redis database)
127.0.0.1:6379> the ping (test Redis service is started, the following represents the start)
PONG

Other remote login Redis database, this demonstration on the use of their IP
remote, then you need to modify the configuration file, add your own IP address, can make yourself or someone else connected
127.0.0.1:6379> Exit
[root @ CentOS7-02 ~] # vim / etc / Redis / 6379.conf
Here Insert Picture Description
[root @ CentOS7-02 ~] # /etc/init.d/redis_6379 restart
[root @ CentOS7-02 ~] # Redis-cli 192.168.100.102 -p 6379 -h
192.168.100.102:6379>
192.168.100.102:6379> exit (exit the database)
Of course, if you are above have a second Redis server can also be replaced by a second connection to the IP

Use the help command help
[root @ CentOS7-02 ~] # Redis-cli
127.0.0.1:6379> help set (see help set command)
SET key value [EX seconds] [PX milliseconds] [NX|XX]
summary: Set the string value of a key
since: 1.0.0
group: string

2) redis-benchmark testing tools

This tool official tool that can effectively test Redis database performance,

1. The address to the IP 192.168.100.102 I (that is, its own the IP), the port 6379, the Redis server sends 100 concurrent connections, the test request 100000

[root@CentOS7-02 ~]# redis-benchmark -h 192.168.100.102 -p 6379 -c 100 -n 100000

2. Test Access packet size performance 4MB

[root@CentOS7-02 ~]# redis-benchmark -h 192.168.100.102 -p 6379 -q -d 4MB

3.Redis database commonly used commands

Redis database using key-value (key-on) is stored in the form of

set: storage of data, formats Key valuse the SET
GET: get data, get key format

127.0.0.1:6379> set aaa bbb
OK

127.0.0.1:6379> get aaa
"bbb"

key related commands

1)keys

Use command keys take the key list matching the rule, binding*
127.0.0.1:6379> A1. 1 SET
the OK

127.0.0.1:6379> set a2 2
OK

127.0.0.1:6379> set a3 3
OK

127.0.0.1:6379> set v1 22
OK

127.0.0.1:6379> set v2 4
OK


127.0.0.1:6379> Keys * (current library display all keys)
1) "v2"
2) "key:__rand_int__"
3) "a2"
4) "mylist"
5) "a3"
6) "k1"
7) "counter:__rand_int__"
8) "aaa"
9) "k2"
10) "a1"
11) "v1"


127.0.0.1:6379> v Keys * (v to show all of the key head open)
1) "v2"
2) "v1"


127.0.0.1:6379> V22 8 the SET
OK
127.0.0.1:6379> Keys v? (v display keys begin with and is behind only one character)
1) "v2"
2) "v1"


127.0.0.1:6379> Keys ?? v (v display key and begin with the two characters behind only)
1) "v22"

2)exists

This command can be determined whether there is a key
127.0.0.1:6379> EXISTS V1
(integer) 1 (. 1 indicates that the bond is present)

127.0.0.1:6379> U EXISTS
(integer) 0 (0 indicates that the bond is absent)

3) of the

Delete keys
127.0.0.1:6379> get a1
"1"

127.0.0.1:6379> a1 del
(integer) 1 (deleted successfully)

127.0.0.1:6379> a1 GET
(nil) (Tip has no)

4)type

Type command value can be acquired using a value corresponding to the type of key type A2
127.0.0.1:6379>
string

5)rename

rename command is a rename an existing key, regardless of whether there are certain key rename, and source key value overrides the value of the target key
127.0.0.1:6379 > SET S1. 1
OK

127.0.0.1:6379> set s2 2
OK

127.0.0.1:6379> set s3 3
OK

127.0.0.1:6379> keys s*
1) "s2"
2) "s1"
3) "s3"

127.0.0.1:6379> The rename S3 s2 (s2 rename the original value s3, s3 s2 becomes a value coverage)
OK

127.0.0.1:6379> keys s*
1) "s1"
2) "s3"

127.0.0.1:6379> GET S3 (key-values are s2)
"2"

6)renamenx

Renamenx command role is to rename an existing key, and detect new name exists, if the target key exist, not rename

127.0.0.1:6379> get s1
"1"

127.0.0.1:6379> get s3
"2"

127.0.0.1:6379> S1 S3 renamenx
(integer) 0 (which failed display)

127.0.0.1:6379> get s1
"1"
127.0.0.1:6379> get s3
"2"

127.0.0.1:6379> S1 S5 renamenx (This)
(integer) 1

127.0.0.1:6379> S5 GET
"1" (s1 which is the key)

127.0.0.1:6379> s1 GET
(nil) (no longer exists)

Multi-database commonly used commands

Between 1) switching multiple databases

Redis supports multiple databases, without any change Redis default database contains 16, using the number represented by 0 to 15
[CentOS7-02 the root @ ~] # Redis-CLI
127.0.0.1:6379> (default is 0 into a database, not shown)

127.0.0.1:6379> SELECT 10 (switch 10 to the database)
OK

127.0.0.1:6379[10]> (In front of a display 10 indicates the current database is 10)

127.0.0.1:6379[10]> 16 the SELECT
(error) ERR invalid DB index (and no more than 16 databases)

2) a number of mobile data database

Redis data in multiple databases are independent, for example, on a key aaa 0, there is no other databases to
127.0.0.1:6379> GET aaa
"bbb"

127.0.0.1:6379> select 1
OK

127.0.0.1:6379[1]> aaa GET (no show)
(nil)

Redis database provides a move command to move the data in the database, rather than copying, the original key position can not
127.0.0.1:6379[1]> select 0
OK

127.0.0.1:6379> get aaa
"bbb"

127.0.0.1:6379> Move aaa 1 (the key to move to a database aaa)
(integer) 1

127.0.0.1:6379> aaa GET (original position already gone)
(nil)

127.0.0.1:6379> SELECT 1 (switching to 1 in)
OK

127.0.0.1:6379[1]> aaa GET (has come)
"bbb"

3) Clear data content

127.0.0.1:6379[1]>flushdb (clear the current location, 1 database content)

127.0.0.1:6379[1]> flushall (Empty all contents of the database, 16)
OK

Here, the basic use of the database would be no problem

Published 54 original articles · won praise 57 · views 20000 +

Guess you like

Origin blog.csdn.net/weixin_45308292/article/details/102682487