编程知识 cdmana.com

Redis2020's latest simple graphic tutorial (Part 1) [including learning video]

Redis Learning goals

Redis Introduction and installation of

Redis What is it? ?

 Redis It's open source (BSD The license ) Of , Memory Data structure storage system in , It can be used as database 、 Caching and message middleware . It supports multiple types of data structures , Such as character string (strings), hash (hashes), list (lists), aggregate (sets), Ordered set (sorted sets) And scope query , bitmaps, hyperloglogs and Geographical space (geospatial) Index radius query . Redis Built in copy (replication),LUA Script (Lua scripting),LRU Driving events (LRU eviction), Business (transactions) And different levels of Disk persistence (persistence), And pass Redis sentry (Sentinel) And automatic zoning (Cluster) Provide high availability (high availability)

performance

  Here is the official bench-mark data :

  The test is done 50 Individual concurrent execution 100000 A request .

  The values set and obtained are one 256 Byte string .

  result : The speed of reading is zero 110000 Time /s, The speed of writing is 81000 Time /s

Redis A brief history

 2008 year , An Italian startup Merzia The founder of Salvatore Sanfilippo for fear of MySQL Low performance of , Make a database by yourself , And in 2009 Development completed in , This is Redis.

  from 2010 year 3 month 15 The date of ,Redis Development work by VMware host .

  from 2013 year 5 Month begins ,Redis The development of the Pivotal sponsorship .

​ explain :Pivotal The company is made up of EMC and VMware A new joint venture .Pivotal Hope to provide a native foundation for the new generation of applications , Built on the transformational cloud and network companies with leadership IT On top of the characteristics .Pivotal Our mission is to implement these innovations , To provide to the enterprise IT Architects and independent software providers .

Support language

Supported data types

 stringhashlistsetsorted set

install

Download address

 http://redis.io/

Upload to server

decompression
tar zxvf redis-5.0.3.tar.gz
Installation dependency
yum -y install gcc-c++ autoconf automake

precompile

Switch to the unzip Directory

cd redis-5.0.3/
make

install

Create installation directory

mkdir -p /usr/local/redis

Don't use :make install(make install Default install to /usr/local/bin Under the table of contents )

Use : If you need to specify the installation path , Need to add PREFIX Parameters

make PREFIX=/usr/local/redis/ install

The installation is successful as shown in the figure

Redis-cli: client

Redis-server: Server side

start-up

Default target path for installation :/usr/local/redis/bin

start-up

./redis-server

The default is the foreground startup , Change to background start

Copy redis.conf Go to the installation path

cp redis.conf /usr/local/redis/bin/

Modify the installation path of redis.conf, take daemonize It is amended as follows yes

Startup time , Specify the configuration file path

adopt windows Client access

install Redis client

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-t4y9Ctm9-1608720091939)(Redis.assets/image13.png)]

Establishing a connection -> Failure

Modify the configuration file redis.conf

Comment out bind 127.0.0.1 Can make all of ip visit redis, If you want to specify more than one ip visit , But not all ip visit , Sure bind Set up

Turn off protection mode , It is amended as follows no

Add access authentication

After modification kill -9 XXXX Kill redis process , restart redis

Establish the connection again -> success

We can change the number of default databases Default 16

modify database 32 The default is 32 A database

After modification kill -9 XXXX Kill redis process , restart redis You can see the effect

Relational and non relational databases

Relational database

  A database that uses relational models to organize data , A relational model is a two-dimensional tabular model . The name of a two-dimensional table is relation , A row in a two-dimensional table is a record , A field in a two-dimensional table is a column .

advantage

  • Easy to understand
  • Easy to use , General purpose sql Language
  • Easy to maintain , Rich integrity ( Entity integrity 、 Referential integrity and user-defined integrity ) It greatly reduces the probability of data redundancy and data inconsistency

shortcoming

  • disk I/O It's the bottleneck of concurrency
  • Massive data query efficiency is low
  • It's difficult to scale horizontally , Can't simply add hardware and service nodes to expand performance and load capacity , When you need to upgrade and expand the database , Need downtime for maintenance and data migration
  • Multi table Association query and complex data analysis type sql Inquire about , Poor performance . Because to guarantee acid, It must be designed according to three paradigms .

database

 Orcale,Sql Server,MySql,DB2

Non relational database

Non relational , Distributed , It is generally not guaranteed that ACID Principle of data storage system . Key value pair storage , The structure is not fixed .

advantage

  • Add fields as needed , There is no need for multi table joint query . Only id Take out the corresponding value
  • Apply to SNS( Social network service software . such as facebook, Microblogging )
  • Strictly speaking, it's not a database , It's a collection of structured data storage methods

shortcoming

  • Only suitable for storing some simple data
  • Data not suitable for complex queries
  • Not suitable for persistent storage of massive data

database

  • K-V:Redis,Memcache
  • file :MongoDB
  • Search for :Elasticsearch,Solr
  • Scalability distributed :HBase

Compare

Content Relational database Non relational database
cost Some need to be charged (Orcale) It's basically open source
Query data It's stored on a hard disk , Slow speed The data is stored in the cache , Fast
Storage format Only base types are supported K-V, file , Pictures, etc
Extensibility There is a multi table query mechanism , Extend the difficult There is no coupling between the data , Easy to expand
persistence For persistent storage , Mass storage Not for persistent storage , Mass storage
Data consistency Strong business skills , Emphasize the strong consistency of data Weak business ability , Emphasize the ultimate consistency of the data

Redis-cli operation Redis

Redis-cli Connect Redis

-h: Is used to specify the ip

-p: Used to specify the port

-a: Used to specify the authentication password

PING Command return PONG

Appoint database

Redis-cli operation Redis

operation String

set: Add one String Type data

get: Get one String Type data

mset: Add more than one String Type data

mget: Get more than one String Type data

operation hash

hset: Add one hash Type data

hget: Get one hash Type data

hmset: Add more than one hash Type data

hmget: Get more than one hash Type data

hgetAll: Gets all of the specified hash Type data

hdel: Delete the specified hash Type data ( One or more )

operation list

lpush: Add left ( head )list Type data

rpush: Right add ( tail ) Type data

lrange: obtain list Type data start Start subscript end End subscript Inclusion relation

llen: Get the number of pieces

lrem: Delete several specified in the list list Type data

operation set

sadd: add to set Type data

smembers: obtain set Type data

scard: Get the number of pieces

srem: Delete data

operation sorted set

sorted set It's sorted by fractional value , The bigger the score is , More backward .

zadd: add to sorted set Type data

zrange: obtain sorted set Type data

zcard: Get the number of pieces

zrem: Delete data

zadd Need to put Float perhaps Double Type fraction, numerical parameter , Before the value parameter

Redis There is a hierarchical relationship between China and Israel 、 Data is stored in the form of a directory

Set up key The expiration time of

Redis There are four different commands that can be used to set the lifetime of the key ( How long can the key last ) Or expiration time ( When will the key be deleted ) :

EXPlRE <key> <ttl> : Used to put the key key The lifetime of is set to ttl second .

PEXPIRE <key> <ttl>: Used to put the key key The lifetime of is set to ttl millisecond .

EXPIREAT <key> < timestamp>: Used to put the key key The expiration time for is set to timestamp The time stamp of the specified number of seconds .

PEXPIREAT <key> < timestamp > : Used to put the key key The expiration time for is set to timestamp The specified number of milliseconds timestamp .

TTL: The value obtained is -1 Illustrate this key No expiration date set , The duty of -2 It is proved that the period of validity has expired .

Method 1

Method 2

Method 3

  The first parameter :key

  The second parameter :value

  The third parameter :NX It's when it doesn't exist set,XX It's only when it exists set

  Fourth parameter :EX Is the second ,PX Is ms

Delete

del: Used to delete data ( Universal , For all data types )

hdel: Used to delete hash Type data

tips: The order is java Chinese legal name , Parameters : Remove brackets , quotes , Just change the comma into a space

zadd Need to put Float perhaps Double Type parameter , Before the value parameter


Redis Learning video !!!

版权声明
本文为[Technical house Xiaobai]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224160209123h.html

Scroll to Top