当前位置:网站首页>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
边栏推荐
- Flink case - Kafka, MySQL source
- Create VPC in AWS console (no plate)
- 做数据可视化应该避免的8个误区
- AWS eks add cluster user or Iam role
- Record the blind injection script
- Custom switch control
- Spark case - wordcount
- 解决ValueError: Argument must be a dense tensor: 0 - got shape [198602], but wanted [198602, 16].
- What's the difference between error and exception
- QML进阶(四)-绘制自定义控件
猜你喜欢
Painless upgrade of pixel series
Recommended scheme of national manufactured electronic components
Spark FAQ sorting - must see before interview
Arduino UNO r3+LCD1602+DHT11
Recommended scheme for national production of electronic components of wireless keyboard
Introduction to raspberry pie 3B - system installation
[paper reading] [3D object detection] voxel transformer for 3D object detection
拼了!两所A级大学,六所B级大学,纷纷撤销软件工程硕士点!
test
[paper reading] [3D target detection] point transformer
随机推荐
Leetcode008 -- implement strstr() function
The perfect combination of collaborative process and multi process
Eksctl deploying AWS eks
Unity攝像頭跟隨鼠標旋轉
Customize the navigation bar at the top of wechat applet (adaptive wechat capsule button, flex layout)
229. Find mode II
Spark small case - RDD, spark SQL
io. Platform. packageRoot; // ignore: deprecated_ Member_ use
補:注解(Annotation)
ApplicationContext injection bean
Use recyclerview to realize left-right side-by-side classification selection
Recommended scheme of national manufactured electronic components for intelligent electronic scales
Supplément: annotation
leetcode004--罗马数字转整数
FAQ of foreign lead and alliance Manager
Spark FAQ sorting - must see before interview
敏捷实践 | 提高小组可预测性的敏捷指标
Better way to read configuration files than properties
Pixel 5 5g unlocking tutorial (including unlocking BL, installing edxposed and root)
Record the ThreadPoolExecutor main thread waiting for sub threads