当前位置:网站首页>What are the five common data types of redis? What is the corresponding data storage space? Take you to learn from scratch
What are the five common data types of redis? What is the corresponding data storage space? Take you to learn from scratch
2022-07-18 12:05:00 【I am a cabbage】
Hello everyone , I'm cabbage . This article mainly explains Redis A brief introduction to the five common data types of database and their data storage space , If you get something after reading the article , You can support bloggers three times in a row ~, Hee hee .
List of articles
One 、 What is? Redis?
REmote DIctionary Server(Redis)It's akey-valueThe storage system . It is often referred to as a data structure server , Because of the value (value) It can be character string (String), Hash (Map), list (list), aggregate (sets) and Ordered set (sorted sets) Other types .- The data types to be introduced in this article , Is for value (value) Of , instead of key.
Two 、 Client connection Redis
- All the operations in this article are in Linux Under the system
- Use Redis Client operation Redis database , First of all, turn on Redis The service side , Then use the following command line to connect Redis The server :
[[email protected] redis-6.2.6]# cd /usr/local/bin/
[[email protected] bin]# redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> ping
PONG
3、 ... and 、Redis Data storage format
- redis
Itself is a Map, All of the data are based on key-value Form storage of - Data type refers to the type of data stored , That is to say value The type of part ,key Parts are always strings

Four 、 character string (String)
- Redis The related commands of string data type are used for
management redis A string value Stored data :Single data , The simplest type of data storage , It is also the most commonly used data storage typeThe format of data storage :One storage space holds one dataStore content :You usually use strings , If the string is presented as an integer , It can be used as a digital operation
The figure below lists redis Common commands for strings :


Be careful : These instructions must be typed by yourself , Practice makes perfect . For instruction operations that will not , You can see the official documents .
5、 ... and 、 Hash (hash)
- For the string type mentioned above , If you store object class data , The operation with frequent update requirements will be very troublesome , So you have a hash data structure .
New storage requirements :Grouping a series of stored data , Easy to manage , Typical applications store object information .The required storage structure :One storage space holds multiple key value pairs .hash type :The bottom layer uses hash table structure to realize data storage .

hash Precautions for type data operation :
- hash Type value Only strings can be stored , Storage of other data types is not allowed , There is no nesting . If the data is not available , The corresponding value is (nil)
- Every hash Can be stored 232 - 1 Key value pairs
- hash The type is very close to the data storage form of the object , And you can add and delete object attributes flexibly .
but hash It's not designed to store a lot of objects, Remember not to abuse , Not to mention hash Use as an object list - hgetall Operation can get all properties , If inside field Too much , The efficiency of traversing the whole data is very low , It may become the bottleneck of data access
The figure below lists redis Common instructions for hashing :


6、 ... and 、 list (list)
Data storage requirements :Store multiple data , And the order of data into the storage space is distinguished .The required storage structure :One storage space holds multiple data , And through the data can reflect the order of entry .list type :Save multiple data , The bottom layer uses bidirectional linked list storage structure .

list Type data operation considerations :
- list The data stored in is string Type of , The total data capacity is limited , most 232-1 individual .
- list With the concept of indexing , But when operating data, it is usually done in the form of queue , Or in the form of stack stack stack operation .
- Get all data operation end index set to -1
- list Data can be paged , Usually the information on the first page comes from list, The second page and more information is loaded in the form of a database .
The figure below lists redis Common instructions for lists :


7、 ... and 、 aggregate (Set)
New storage requirements :Store a lot of data , Provide more efficiency in queries .The required storage structure :Can hold a lot of data , Efficient internal storage mechanism , Easy to query .set type :And hash The storage structure is exactly the same , Just store the key , Are not stored value (nil), And the value is not allowed to repeat .

set Precautions for type data operation :
- set Type does not allow duplicate data , If the added data is in set There is already , Only one copy will be kept .
- set Although with hash The storage structure of is the same , But it can't be enabled hash Space to store values in .
The figure below lists redis aggregate set Common instructions for :


8、 ... and 、 Ordered set (sorted set)
New storage requirements :Data sorting is conducive to the effective display of data , Need to provide a way to sort according to their own characteristics .The required storage structure :New storage model , You can save sortable data .sorted_set type :stay set Add sortable fields based on the storage structure of .

sorted_set Precautions for type data operation :
- score The integer range of the saved data is :
-9007199254740992~9007199254740992 - score The stored data can also be a double precision double value , Characteristics based on double precision floating point numbers , Accuracy may be lost , Be careful when using
- sorted_set The underlying storage is still based on set Structural , So the data can't be duplicated ,
If you add the same data repeatedly ,score Values will be repeatedly overridden, Keep the result of the last modification
The figure below lists redis Common instructions for ordered sets :


Thank you for reading , Progress together , Hee hee ~
边栏推荐
- 普乐蛙4d5d动感影院|VR太空旅行设备|VR带你遨游太空
- YGG established a new subdao - YGG Japan
- Reverse linked list of C language force deduction question 206. Double fingered needle method, iterative recursion (three methods). Graphic nanny tutorial
- Add Tsinghua image in CONDA
- Kettle【实践 02】txt类型文件分类导入后执行SQL进行数据类型转换并入库(完整流程实例云资源分享:包含sql+kjb+ktr+测试文件)
- 深度学习------不同方法实现resnet-18、resnet34
- Unity(C#)获取文件的编码格式方法
- Jsd-2204-mvc-weibo project-day15
- UE4_UE5播放音频(播放、停止功能)(附工程)
- If the designer leaves, the iphone14 may become a brick, and using the iPhone is even more compelling
猜你喜欢

Delete After the idea directory, the SVN menu resumes operation

限制ASML给中国供应光刻机?其实它已经离不开中国市场了

Wireless communication safety operation 3

Power Bi ---- what is a measure?

解决 : ReferenceError: PubSub is not defined

Analysis of websocket hijacking

Gin框架的使用

Power BI----DAX讲解

WinForm + C GDI + programming to realize Photoshop, illustrator similar drawing toolbox

DDD Domain Driven Design
随机推荐
包含数字的字符串剔除字母根据步长递增
[load balancer does not contain an instance for the service mall coupling] and the project start normally but cannot register with Nacos
2022年7月16日CDGA/CDGP数据治理认证考试成绩出来啦!
深度学习------不同方法实现resnet-18、resnet34
Wireless communication safety operation 3
Four reasons for programmers' headaches | daily anecdotes
mysql原字段转驼峰命名
How to use jedis to operate redis database?
【YOLO】v5s 6.1版本LoadStreams类源码解读
Deep learning ----- verification code
Excel-VBA 快速上手(七、获取单元格对象)
YGG 成立了新的 SubDAO——YGG日本
screenWidth、clientWidth、offsetWidth、 scrollWidth的区别
如何在TIA 博途中计算终端设备(例如水泵)的运行时间(附FB库文件)?
为什么说大公司不是天堂,里面有哪些坑?
Overview of database system -- overview of data model
MySQL JSON field query
Résolution du format d'image
洛谷题单-高精度
Matlab drawing_ 1 draw attenuation oscillation curve