当前位置:网站首页>Redis introduction and installation
Redis introduction and installation
2022-07-18 07:04:00 【Hokwok18】
1.NoSql summary
Why use Nosql
1、 stand-alone Mysql years

90 years , There are not many business visits , A single database of a basic website is completely enough
2、Memcached( cache )+Mysql+ Split Vertically ( Read / write separation )
Website 80% The situation is reading , It's very troublesome to get and query the database every time ! To reduce data pressure , We use caching to ensure efficiency .
Development process : Optimize data structures and indexes -> File cache (IO)->Memcached( The hottest technology at that time )
3、 Sub database and sub table + Horizontal split +Mysql colony
Technology and business are developing at the same time , People are more and more demanding
The essence : Database read and write
Earlier years MyISAM: Table locks ,( When reading and writing , The table is locked , It greatly affects concurrency )
Innodb: Row lock 
Now a basic Internet Project

Why use NoSQL
User's personal information , Social networks , Location . User generated data , User logs and so on exploded !
And that's where we need to use it NoSQL database ,NoSQL Can handle the above situation well !
What is? NoSql
NoSql
NoSql = Not Only Sql( not only Sql)
Relational database : form , That's ok , Column
Non relational database in general , Traditional relational databases are difficult to deal with web2.0 Time , Especially large scale and high concurrency community .NoSql In today's big data environment, it is developing very rapidly ,Redis It's the fastest growing , And it's a technology that we have to master right now !
A lot of data types, user's personal information , Social networks , Location . These data types do not need a fixed format , No extra operations are needed to scale out ! Use key value pairs to store .
NoSql characteristic — decoupling
1、 Easy to expand ( There's no relationship between the data , Good extension )
2、 Large data volume and high performance (NoSql Cache record level of , It's a fine-grained cache , The performance will be relatively high )
3、 Data types are diverse ( No need to design database , Take it and use it )
4、 Conventional RDBMS and NoSql
Conventional RDBMS( Relational database )
- Structured organization
- SQL
- Data and relationships exist in separate tables
- Operating language , Define language
- Strict consistency
- ...
Nosql
- It's not just data
- There is no fixed query language
- Key value pair storage , Document storage , Graphic database ( social connections )
- Final consistency
- CAP Theorem and BASE ( Different live )
- High performance , High availability , Highly expandable
- ...
understand :3V+3 high
● In the era of big data 3V: It's mainly about describing the problem
1、 Massive Volume
2、 diverse Variety
3、 real time Velocity
● Internet needs 3 high : It's mainly about the requirements of procedures
1、 High concurrency (Java JUC)
2、 Gao Ketuo ( Split horizontally at any time , There are not enough machines , Expand the machine to solve )
3、 High performance ( Guaranteed user experience and performance )
Alibaba evolution analysis
Alibaba Chinese website architecture design practice
Recommended articles : Alibaba cloud's crazy people —- Throw in the towel , Is really lost
NoSql The four major categories of
KV Key value pair
- Sina :Redis
- Meituan :Redis+Tair
- Ali 、 Baidu :Redis+MemCache
Document database :(bson Format and json equally )
- MongoDB
- mongodb Database based on distributed file storage ,C++ To write , It is mainly used to process a large number of documents
- MongoDB It's a product between relational database and non relational database ,MongoDB Yes no relational database has the most functions , Most like a relational database .
- ConthDB
Column store database
- HBase
- distributed file system
Graph relational database ( Not saving graphics , It's about relationships )
- neo4j
- InfoGrid
- redisgraph
2.Redis introduction
summary
Redis What is it? ?
Redis(Remote Dictionary Serve), Remote dictionary service
Redis What can I do? ?
1、 Memory storage , Persistence , In memory, power is lost , So persistence is important (rdb、aof)
2、 Efficient , Can be used for caching
3、 Publish subscribe system
4、 Map information analysis
5、 timer 、 Counter ( Browse volume ! )
…
characteristic
1、 A variety of data types
2、 Persistence
3、 colony
4、 thing
…
Things used in learning
Official website :https://redis.io/
Chinese net :http://www.redis.cn/
Windows Lower installation
download
https://github.com/tporadowski/redis/releases

The extracted directory is as follows

The file is introduced
- redis-server.exe: Server program , Provide Redis service .
- redis-cli.exe: Client program , Connect through it Redis Service and operate .
- redis-check-dump.exe:RDB File repair tool .
- redis-check-aof.exe:AOF File repair tool .
- redis-benchmark.exe: Performance testing tools , Used to simulate simultaneous N Clients send M individual SETs/GETs Inquire about ( Be similar to Apache Of ab Tools ).
- redis.windows.conf: The configuration file , take Redis Configuration used as general software , When the command line is closed Redis close .
- redis.windows-service.conf: The configuration file , take Redis Configuration as a system service .
Use
double-click redis-server.exe, A pop-up window will flash by , If you don't want the window to disappear , Can be in cmd Open in .

What's starting up here is Redis The service side , Used to provide services .
double-click redis-cli.exe

What's starting up here is Redis The client of , For connecting services .
Test use

This means Redis It can be used normally. .
Windows Under the installation and use of Redis It's very simple , But the official does not recommend it

Official recommended use Linux Deployment .
Redis It can work in other operating systems , But this support is best .Windows The version is not officially supported .
Linux Lower installation
Here we use CentOS 7 System as an example
Environmental preparation
because Redis from ANSI C To write , install Redis Installation is required C Language environment .yum install gcc-c++
Some bring their own c Environmental Science , No need to install
adopt gcc -v View installed c Environment version , See if it already exists
download
visit Redis official :https://redis.io/
decompression
tar -zvxf redis-6.2.6.tar.gz
Move
In general, I will redis Put the directory in /usr/local/redis Here will be at present /home/kwok In the catalog redis-6.2.6 Folder change directory , Also change the folder name to redis.mv /home/kwok/redis-6.2.6 /usr/local/redis
compile
Jump to /usr/local/redis Next make
Finally, the following contents are output, which means that the compilation is successful 
install
make PREFIX=/usr/local/redis install
Here's an extra keyword PREFIX=
This keyword is used to specify the path where the program is stored at compile time .
For example, we have designated redis It must be stored in /usr/local/redis Catalog .
Suppose you don't add the keyword Linux The executable file will be stored in /usr/local/bin Catalog .
The directory number is specified here to facilitate subsequent unloading , Follow up direct rm -rf /usr/local/redis You can delete redis.
start-up
We usually need to start in the background Redis :
There are two ways : Command band & and Modify the configuration file .
The way 1: Command band &
./bin/redis-server& ./redis.conf
[[email protected] redis]# ./bin/redis-server& ./redis.conf
[1] 11953
-bash: ./redis.conf: Permission denied
[[email protected] redis]# 11953:C 15 Mar 2022 16:15:10.803 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
11953:C 15 Mar 2022 16:15:10.803 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=11953, just started
11953:C 15 Mar 2022 16:15:10.803 # Warning: no config file specified, using the default config. In order to specify a config file use ./bin/redis-server /path/to/redis.conf
11953:M 15 Mar 2022 16:15:10.803 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._ _.-`` `. `_. ''-._ Redis 6.2.6 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 11953
`-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | https://redis.io `-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-'
`-.__.-' 11953:M 15 Mar 2022 16:15:10.804 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 11953:M 15 Mar 2022 16:15:10.804 # Server initialized 11953:M 15 Mar 2022 16:15:10.804 # 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.
11953:M 15 Mar 2022 16:15:10.804 * Ready to accept connections
This method needs to be marked with & Talent , Not very convenient , It is usually achieved by modifying the configuration file .
The way 2: Modify the configuration file
take redis.conf from daemonize no Change it to daemonize yes that will do .
After modification, there is no & It can also be started in the background . stay redis Under the path ./bin/redis-server ./redis.conf
Because I copied one redis.conf Files in /usr/local/bin/kwokconfig The following the , So the startup is :/usr/local/redis/bin/redis-server /usr/local/bin/kwokconfig/redis.conf Some versions do not prompt after startup
see
View the process mode ps -ef|grep redis
[[email protected] redis]# ps -ef|grep redis
root 11953 3410 0 16:15 pts/1 00:00:02 ./bin/redis-server *:6379
Check the port mode
Redis The default port is 6379, It doesn't usually change , You can query through this port Redis Allowable conditions .netstat -lanp | grep 6379
[[email protected] redis]# netstat -lanp | grep 6379
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 11953/./bin/redis-s
Environment variable configuration
For ease of use , It is recommended to configure first Redis Environment variables of .vim /etc/profile
source /etc/profile
Performance testing
bin In the catalog redis-benchmark Performance testing can be carried out
- -c(clients): The concurrency of the client ( Default 50).
- -n(num): Number of client requests ( Default 100000).
- -q: Just show redis-benchmark Of requests per second Information .
- -r(random): towards Redis Insert more random values .
- -P : Each request pipeline The amount of data ( The default is 1).
- -k : Whether the client uses keepalive,1 For the use of ,0 For not using , The default value is 1.
- -t: Benchmark the specified command .
- –csv: According to csv Format output .
redis-benchmark -h localhost -p 6379 -c 100 -n 100000
Use
redis-cli Local connection redis A command of the service , After this command, you can enter redis Script console .
After configuring the environment variables, enter in any directory redis-cli You can enter .
[[email protected] etc]# redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set hello Hello World
(error) ERR syntax error
127.0.0.1:6379> set hello "Hello World"
OK
127.0.0.1:6379> get hello
"Hello World"
such Redis stay Linux Installation is completed on .
sign out redis Client and shutdown redis Server side 
direct ctrl c Only the client can exit , The server has not returned 
Test performance
redis-benchmark It's a stress testing tool
The official comes with its own performance testing tool
Test it :
# test : 100 concurrent ,100000 request
redis-benchmark -h localhost -p 6379 -c 100 -n 100000

边栏推荐
- Design and implementation of fingertip Roulette Games (uniapp implements wechat applet)
- Exploration of yolact model structure
- MySQL pymysql module
- Drive free USB to serial port billboard chip (ldr2001)
- Redis installation & startup
- 非对称加密RSA与对称加密AES项目应用
- 数据库存IP地址,用什么数据类型
- 60岁开发者的建议,尝试改变一下吧!
- Thumbnailator 图片处理类库
- 7. MySQL -- 基础语法(三) DCL
猜你喜欢
随机推荐
Swin transformer, the best paper model of iccv 2021, finally started video
TP5在线显示图片出现乱码问题
Pd-qc-afc multi protocol decoy chip "ldr6328s"
The most important diagram of machine learning, how to select the model sklearn structure diagram
Redis installation & startup
ClickHouse SQL 的十项优化规则
布尔代数值
Array and string assignment problem (not initialized when defining)
7. MySQL -- basic syntax (III) DCL
Latest idea reset method
Flex & bison advanced calculator
Ten optimization rules of Clickhouse SQL
联想电源管理下载
Implementation of sequence table in C language stack
[300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (4)
How to save using OpenCV Mp4 format file
Chapter 10 pointer of C language
RuntimeWarning: overflow encountered in long_ scalars h = 12.0 / (totaln * (totaln + 1)) * ssbn - 3
(一)MATLAB基础知识
MySQL autoincrement, index, foreign key, other operations









