当前位置:网站首页>Basic understanding of initial redis
Basic understanding of initial redis
2022-04-21 23:51:00 【·Plum blossom thirteen】
One 、 understand Redis
Redis It's open source (BSD The license ) Of , Data structure storage system in memory , It can be used as a 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 Partition (Cluster) Provide high availability (high availability)
Two 、 Master the basics
1、redis The default is 16 A database ( Default No 0 individual )
—— How to view ?
- Get into /usr/local/etc Under the table of contents : cd /usr/local/etc
- see redis Profile view :vim redis.conf
notes : Or directly enter the directory through visit , Open with text editor

Can pass select Command to switch databases
127.0.0.1:6379> select 3 # Switch to 3 The database
OK
127.0.0.1:6379[3]> set name wpf # set set key value
OK
127.0.0.1:6379[3]> set age 21
OK
127.0.0.1:6379[3]> dbsize # see DB( library ) size
(integer) 2
127.0.0.1:6379[3]>
2、 Why? redis The default port number for is 6379
6379 It's on the Jiugongge button of the mobile phone ‘ MERZ ’ The corresponding number , and MERZ From the Italian singer Alessia Merz Name .MERZ For a long time Redis author antirez And his friends as a byword for stupidity . later Redis The author is developing Redis This port is selected when
3、redis It's single threaded !
Redis It's based on memory operations ,Redis The performance bottleneck is not CPU, But according to the memory and network bandwidth of the machine , Since a single thread is easy to implement , and CPU Not a bottleneck , So use a single thread !
Redis yes C Written language , The official data is 100000+ Of QPS, It's no better than using the same key-value Of Memecache Bad !
Single thread cannot play multi-core CPU performance , You can open multiple... In a single machine Redis Examples to improve !
4、redis Why is single thread so fast ?
myth 1: High performance servers must be multithreaded ?
myth 2: Multithreading must be more efficient than single thread !( Ignored CPU Context switch of )
—— Speed from high to low :CPU > Memory > Hard disk
- Memory based , Memory is very fast in reading and writing ;
- Single thread , Save a lot of context switching time ;( And locking consumption , And deadlock problems )
- redis Using multiplexing technology , Can handle concurrent connections . Non blocking IO Internal implementation adoption epoll, Adopted epoll+ Simple event framework implemented by ourselves .epoll Reading in Chinese 、 Write 、 close 、 Connections are converted to events , And then use it epoll Multiplexing characteristics of , Never in io Waste a little time .
The core :Redis Is to put all the data in memory , Using a single thread to operate is the most efficient !( Multithreading exists CPU Context switch back : Time consuming operations !), For memory systems , If there is no context switching, the efficiency is the highest ! Read and write many times in the same CPU On —— Best solution !
5、IO Multiplexing technology
redis Using the network IO Multiplexing technology to ensure multiple connections , High throughput of the system .Redis Use non blocking IO,IO Multiplexing , Single thread used to poll descriptor , Open database 、 Turn off 、 read 、 Write all converted to events , Reduce context switching and competition during thread switching .
- multiple : multiple socket ( The Internet ) Connect
- Reuse : To reuse a thread .
summary : Multiplexing allows a single thread to efficiently process multiple connection requests ( Minimize the network IO Time consumption of ), And Redis It's very fast to manipulate data in memory ( Operations in memory will not be a performance bottleneck here ), The above two main factors contribute to Redis With high throughput .
Common orders
1、 Switch database
select [ index ]2、 View all key
keys *3、 Get a single key Value
get [key name ]4、 Clear all key values of the current library
flushdb5、 Clear all library key values
flushall6、 Judge key Whether there is ( Equate to sql Of =, Instead of like; for example where name=' Zhang San ')
exists [ key name ]7、 Remove a from the current library key(1 Represents the current library , Used in test select Switch to Library 3, Remove or 1 Instead of 3)
move [ key name ] 1 —— grammar :move [ key name ] db8、 Set up key The expiration time of , The unit is in seconds ( example :expire name 10)
expire [ key name ] [ Number of seconds ]9、 View the current key The remaining expiration time of
ttl [ key name ]10、 View the current key The type of (string、int、map....)
type [ key name ]
版权声明
本文为[·Plum blossom thirteen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211817228718.html
边栏推荐
- leetcode:271.字符串的编码与解码
- 6、协议层次化和服务模型(重点)
- warning: LF will be replaced by CRLF in composer. json.
- leetcode:386. 字典序排数
- JMeter association parameters
- A list of the latest changes in Mandelbrot set -- mandelbox, mandelbulb, burning ship, nebulabrot
- 信噪比和信干噪比
- 分布式gns3
- Redis high availability (HA)
- 基于apache集合工具包的并集、交集、差集工具类
猜你喜欢

存储组 物理量 实体 路径

CentOS7使用yum安装MySQL——指定版本

MYSQL 为什么不要使用SELECT * 作为查询条件?(持续更新)

leetcode:440. 字典序的第K小数字

7.6 thread properties

vmware-vmx. Exe could not end the process

Necessary skills for large factory interview, Android audio and video framework

leetcode:386. 字典序排数

C language topic 1: three digits that can be composed of 1,2,3,4

Prompt, can you do it or not?
随机推荐
1143 longest common subsequence
Click the imported file or click the component to enter the corresponding component page for editing
leetcode - 329. Longest increasing path in matrix
leetcode:443. 压缩字符串
7.6 thread properties
GAN网络笔记 MATLAB实现
[MySQL optimization 1] MySQL optimization ideas
【acwing】1125. 牛的旅行***(floyd)
【MYSQL优化1】mysql优化思路
Redis high availability (HA)
[transfer] differences and relations between collection set map vector list
【MYSQL优化3】观察mysql进程状态
MySQL存储过程用法--含练习题
How JMeter sets parameterization
Man machine verification reCAPTCHA V3 complete instructions
SolidWorks怎么设置运动行程和角度
LeetCode_ 70 climb stairs
Prompt, can you do it or not?
SolidWorks hold down Ctrl and drag to copy entities
Solution of mountain torrent disaster monitoring and early warning system