当前位置:网站首页>redis数据类型有哪些
redis数据类型有哪些
2022-04-23 04:46:00 【xmh-sxh-1314】
String(字符串)
string 是 redis 最基本的类型,你可以理解成与 Memcached 一模一样的类型,一个 key 对应一个 value。
string 类型是二进制安全的。意思是 redis 的 string 可以包含任何数据。比如jpg图片或者序列化的对象。
string 类型是 Redis 最基本的数据类型,string 类型的值最大能存储 512MB。
常用命令:set、get、decr、incr、mget等。
注意:一个键最大能存储512MB。
Hash(哈希)
Redis hash 是一个键值(key=>value)对集合;是一个 string 类型的 field 和 value 的映射表,hash 特别适合用于存储对象。
每个 hash 可以存储 232 -1 键值对(40多亿)。
常用命令:hget、hset、hgetall等。
应用场景:存储一些结构化的数据,比如用户的昵称、年龄、性别、积分等,存储一个用户信息对象数据。
List(列表)
Redis 列表是简单的字符串列表,按照插入顺序排序。你可以添加一个元素到列表的头部(左边)或者尾部(右边)。
list类型经常会被用于消息队列的服务,以完成多程序之间的消息交换。
常用命令:lpush、rpush、lpop、rpop、lrange等。
列表最多可存储 232 - 1 元素 (4294967295, 每个列表可存储40多亿)。
Set(集合)
Redis的Set是string类型的无序集合。和列表一样,在执行插入和删除和判断是否存在某元素时,效率是很高的。集合最大的优势在于可以进行交集并集差集操作。Set可包含的最大元素数量是4294967295。
集合是通过哈希表实现的,所以添加,删除,查找的复杂度都是O(1)。
应用场景:
1、利用交集求共同好友。
2、利用唯一性,可以统计访问网站的所有独立IP。
3、好友推荐的时候根据tag求交集,大于某个threshold(临界值的)就可以推荐。
常用命令:sadd、spop、smembers、sunion等。
集合中最大的成员数为 232 - 1(4294967295, 每个集合可存储40多亿个成员)。
zset(sorted set:有序集合)
Redis zset 和 set 一样也是string类型元素的集合,且不允许重复的成员。
不同的是每个元素都会关联一个double类型的分数。redis正是通过分数来为集合中的成员进行从小到大的排序。
zset的成员是唯一的,但分数(score)却可以重复。
sorted set是插入有序的,即自动排序。
常用命令:zadd、zrange、zrem、zcard等。
当你需要一个有序的并且不重复的集合列表时,那么可以选择sorted set数据结构。
应用举例:
(1)例如存储全班同学的成绩,其集合value可以是同学的学号,而score就可以是成绩。
(2)排行榜应用,根据得分列出topN的用户等。
版权声明
本文为[xmh-sxh-1314]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_57763462/article/details/124357307
边栏推荐
- Record the blind injection script
- What's the difference between error and exception
- A heavy sword without a blade is a great skill
- Recommended scheme of national manufactured electronic components
- zynq平台交叉编译器的安装
- Pixel mobile phone brick rescue tutorial
- 拼了!两所A级大学,六所B级大学,纷纷撤销软件工程硕士点!
- Leetcode008 -- implement strstr() function
- Leetcode002 -- inverts the numeric portion of a signed integer
- Small volume Schottky diode compatible with nsr20f30nxt5g
猜你喜欢

New terminal play method: script guidance independent of technology stack

Ali's ten-year technical experts jointly created the "latest" jetpack compose project combat drill (with demo)

Installation of zynq platform cross compiler

Mysql50 basic exercises

Chapter 4 - understanding standard equipment documents, filters and pipelines

Coinbase: basic knowledge, facts and statistics about cross chain bridge

Summary of Android development posts I interviewed in those years (attached test questions + answer analysis)

Druid -- JDBC tool class case

View analysis of scenic spots in ArcGIS
![解决ValueError: Argument must be a dense tensor: 0 - got shape [198602], but wanted [198602, 16].](/img/99/095063b72390adea6250f7b760d78c.png)
解决ValueError: Argument must be a dense tensor: 0 - got shape [198602], but wanted [198602, 16].
随机推荐
Differences among electric drill, electric hammer and electric pick
Mysql50 basic exercises
補:注解(Annotation)
Unity camera rotation with sliding effect (rotation)
The last day of 2021 is the year of harvest.
Custom switch control
MySQL time function query
Use recyclerview to realize left-right side-by-side classification selection
[paper reading] [3D target detection] point transformer
Better way to read configuration files than properties
2020 is coming to an end, special and unforgettable.
L2-011 玩转二叉树(建树+BFS)
js 判断数字字符串中是否含有字符
JS generates a specified number of characters according to some words
POI export message list (including pictures)
Record the blind injection script
Recommended scheme for national production of electronic components of wireless keyboard
Ali's ten-year technical experts jointly created the "latest" jetpack compose project combat drill (with demo)
Last day of 2017
zynq平臺交叉編譯器的安裝