当前位置:网站首页>[redis] Introduction to NoSQL database and redis

[redis] Introduction to NoSQL database and redis

2022-07-06 07:42:00 Decade0712

One 、NoSQL database

1、NoSQL The definition of
NoSQL Meaning for Not Only SQL( not only SQL), Non relational database in general
Different from relational databases , It does not rely on business logic to store associated data , But rather key-value Data storage in the form of key value pairs , It greatly increases the expansion ability of the database

2、NoSQL The role of database

  • Use as cache , Improve access speed , Reduce IO Read operation
  • Reduce CPU and IO The pressure of the , Read data directly from memory

3、NoSQL The characteristics of database

  • Non compliance SQL Standards for
  • I won't support it ACID
    A (Atomicity) Atomicity
    C (Consistency) Uniformity
    I (Isolation) independence
    D (Durability) persistence
  • Far exceed SQL Performance of

4、 Applicable scenario

  • High concurrency of data reading and writing , For example, the second kill operation of e-commerce
  • Need to read and write massive amounts of data
  • High scalability requirements for data

5、 Not applicable to the scene

  • Need transaction support
  • be based on sql Structured query storage of , Dealing with complex relationships , You need to make an ad hoc inquiry ( Ad hoc inquiry (Ad Hoc) Users according to their own needs , Flexible selection of query conditions )

6、 common NoSQL database

  • Redis
  • MongoDB

Two 、redis Database introduction

1、 Concept
redis It's open source key-value The storage system
It stores value Five data formats are supported : Include string( character string )、list( Linked list )、set( aggregate )、zset(sort set, Ordered set ) and hash( Hash type )

2、redis You can store data in memory , You can also write data to disk periodically ( Persistence ), In addition, it also realizes master-slave( Master-slave ) Sync

3、 install redis
Get into redis Official website : Download address
Find the latest stable version redis, Download to local , Then upload the compressed package to Linux In the virtual machine , Then start our installation

  • install C Language compiling environment , Use command
    yum install gcc
    After installation , Command view gcc edition
    gcc --version
     Insert picture description here

  • Use the unzip command to unzip the compressed package to the specified path
     Insert picture description here
    Be careful Here's one -C This parameter , Otherwise, there may be Not found in archive This mistake
     Insert picture description here

  • Use make Command to compile
     Insert picture description here

  • Use make PREFIX=xxx( Specify the path ) install Command to install
     Insert picture description here

  • Go to the installation directory bin View under the path
    reids-benchmark: Performance testing tools
    redis-check-aof: Fix the problem aof file
    redis-check-dump: Fix the problem dump.rdb
    redis-sentinel:redis Cluster use
    redis-server:redis Server start command
    redis-cli:redis client

  • Try the foreground startup redis( Not recommended , Because after exiting redis The server will also shut down )
    If an error is reported
     Insert picture description here
    At this time, you have to enter the command , Build a /usr/bin/redis-server To /opt/decade/redis/bin/redis-server The soft links , You're running /usr/bin/redis-server Is running /opt/decade/redis/bin/redis-server
    ln -s /opt/decade/redis/bin/redis-server /usr/bin/redis-server
    Can start normally redis 了
     Insert picture description here

  • Try to start in the background redis
    First we will redis Extract... From the directory redis.conf Copy a copy and put it in a path , I am here /opt/decade/
    cp redis.conf /opt/decade/redis.conf
    Use vi redis.conf Modify the copied one redis.conf, adjustment daemonize Configuration item , from NO Change it to YES( Input vi redis after , have access to / What to look for To quickly find what you are looking for )
    daemonize Is used to specify redis Do you want to start it as a daemonic thread , thus redis It will run in the background
     Insert picture description here
    Then we go back to redis Installation directory , Start... With the specified profile redis, You can see ,redis Running in the background
     Insert picture description here

  • Try starting the client
    Use redis-cli Command start client  Insert picture description here

  • close redis
    Use it directly kill -9 redis Process number
    Input at the client shutdown
    Use redis-cli shutdown
    Use redis-cli -p redis Port number shutdown
     Insert picture description here

If there is a mistake , Welcome to correct !

原网站

版权声明
本文为[Decade0712]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060734498731.html