Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Redis知识总结

Redis知识总结

作者头像
芈亓
发布于 2022-06-17 07:07:36
发布于 2022-06-17 07:07:36
31700
代码可运行
举报
文章被收录于专栏:笔记2022笔记2022
运行总次数:0
代码可运行

Redis

常用命令LINUX

set key value 添加 get key 获取 select 5 切换数据库 flushdb 清除当前数据库 FLUSHALL 清除全部数据库的内容 keys * 获取所有的 EXPIRE key time 设置key的过期时间,单位为秒 ttl key 查看当前key的剩余时间 EXISTS key 查看该key是否存在 move key 移除当前key type key 查看key的类型 12 clear 清楚屏幕数据 help @String 查看String相关命令 incr xxxx 增加 带NX的命令 有就不赋值,没有则赋值

Redis五大数据类型

String(字符串) List(列表) Set(集合) Hash(哈希) zset(有序集合)

结构类型

结构存储的值

结构的读写能力

String

可以是字符串、整数或者浮点数

对整个字符串或者字符串的其中一部分执行操作;对象和浮点数执行自增(increment)或者自减(decrement)

List

一个链表,链表上的每个节点都包含了一个字符串

从链表的两端推入或者弹出元素;根据偏移量对链表进行修剪(trim);读取单个或者多个元素;根据值来查找或者移除元素

Set

包含字符串的无序收集器(unorderedcollection),并且被包含的每个字符串都是独一无二的、各不相同

添加、获取、移除单个元素;检查一个元素是否存在于某个集合中;计算交集、并集、差集;从集合里卖弄随机获取元素

Hash

包含键值对的无序散列表

添加、获取、移除单个键值对;获取所有键值对

Zset

字符串成员(member)与浮点数分值(score)之间的有序映射,元素的排列顺序由分值的大小决定

添加、获取、删除单个元素;根据分值范围(range)或者成员来获取元素

String
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  APPEND key value
  summary: Append a value to a key
  since: 2.0.0

  BITCOUNT key [start end]
  summary: Count set bits in a string
  since: 2.6.0

  BITFIELD key [GET type offset] [SET type offset value] [INCRBY type offset increment] [OVERFLOW WRAP|SAT|FAIL]
  summary: Perform arbitrary bitfield integer operations on strings
  since: 3.2.0

  BITOP operation destkey key [key ...]
  summary: Perform bitwise operations between strings
  since: 2.6.0

  BITPOS key bit [start] [end]
  summary: Find first bit set or clear in a string
  since: 2.8.7

  DECR key
  summary: Decrement the integer value of a key by one
  since: 1.0.0

  DECRBY key decrement
  summary: Decrement the integer value of a key by the given number
  since: 1.0.0

  GET key
  summary: Get the value of a key
  since: 1.0.0

  GETBIT key offset
  summary: Returns the bit value at offset in the string value stored at key
  since: 2.2.0

  GETRANGE key start end
  summary: Get a substring of the string stored at a key
  since: 2.4.0

  GETSET key value
  summary: Set the string value of a key and return its old value
  since: 1.0.0

  INCR key
  summary: Increment the integer value of a key by one
  since: 1.0.0

  INCRBY key increment
  summary: Increment the integer value of a key by the given amount
  since: 1.0.0

  INCRBYFLOAT key increment
  summary: Increment the float value of a key by the given amount
  since: 2.6.0

  MGET key [key ...]
  summary: Get the values of all the given keys
  since: 1.0.0

  MSET key value [key value ...]
  summary: Set multiple keys to multiple values
  since: 1.0.1

  MSETNX key value [key value ...]
  summary: Set multiple keys to multiple values, only if none of the keys exist
  since: 1.0.1

  PSETEX key milliseconds value
  summary: Set the value and expiration in milliseconds of a key
  since: 2.6.0

  SET key value [EX seconds] [PX milliseconds] [NX|XX]
  summary: Set the string value of a key
  since: 1.0.0

  SETBIT key offset value
  summary: Sets or clears the bit at offset in the string value stored at key
  since: 2.2.0

  SETEX key seconds value // 设置值同时设置时间
  summary: Set the value and expiration of a key
  since: 2.0.0

  SETNX key value
  summary: Set the value of a key, only if the key does not exist
  since: 1.0.0

  SETRANGE key offset value // 从第几个偏移量开始覆盖
  summary: Overwrite part of a string at key starting at the specified offset
  since: 2.2.0

  STRLEN key
  summary: Get the length of the value stored in a key
  since: 2.2.0
List
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 BLPOP key [key ...] timeout
  summary: Remove and get the first element in a list, or block until one is available
  since: 2.0.0

  BRPOP key [key ...] timeout
  summary: Remove and get the last element in a list, or block until one is available
  since: 2.0.0

  BRPOPLPUSH source destination timeout
  summary: Pop a value from a list, push it to another list and return it; or block until one is available
  since: 2.2.0

  LINDEX key index
  summary: Get an element from a list by its index
  since: 1.0.0

  LINSERT key BEFORE|AFTER pivot value
  summary: Insert an element before or after another element in a list
  since: 2.2.0

  LLEN key
  summary: Get the length of a list
  since: 1.0.0

  LPOP key
  summary: Remove and get the first element in a list
  since: 1.0.0

  LPUSH key value [value ...]
  summary: Prepend one or multiple values to a list
  since: 1.0.0

  LPUSHX key value
  summary: Prepend a value to a list, only if the list exists
  since: 2.2.0

  LRANGE key start stop
  summary: Get a range of elements from a list
  since: 1.0.0

  LREM key count value
  summary: Remove elements from a list
  since: 1.0.0

  LSET key index value
  summary: Set the value of an element in a list by its index
  since: 1.0.0

  LTRIM key start stop
  summary: Trim a list to the specified range
  since: 1.0.0

  RPOP key
  summary: Remove and get the last element in a list
  since: 1.0.0

  RPOPLPUSH source destination
  summary: Remove the last element in a list, prepend it to another list and return it
  since: 1.2.0

  RPUSH key value [value ...]
  summary: Append one or multiple values to a list
  since: 1.0.0

  RPUSHX key value
  summary: Append a value to a list, only if the list exists
  since: 2.2.0

先进先出 队列 左进左出 栈

消息队列 最新列表 均可实现

Set
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 SADD key member [member ...]
  summary: Add one or more members to a set
  since: 1.0.0

  SCARD key
  summary: Get the number of members in a set
  since: 1.0.0

  SDIFF key [key ...]
  summary: Subtract multiple sets
  since: 1.0.0

  SDIFFSTORE destination key [key ...]
  summary: Subtract multiple sets and store the resulting set in a key
  since: 1.0.0

  SINTER key [key ...]
  summary: Intersect multiple sets
  since: 1.0.0

  SINTERSTORE destination key [key ...]
  summary: Intersect multiple sets and store the resulting set in a key
  since: 1.0.0

  SISMEMBER key member
  summary: Determine if a given value is a member of a set
  since: 1.0.0

  SMEMBERS key
  summary: Get all the members in a set
  since: 1.0.0

  SMOVE source destination member
  summary: Move a member from one set to another
  since: 1.0.0

  SPOP key [count]
  summary: Remove and return one or multiple random members from a set
  since: 1.0.0

  SRANDMEMBER key [count]
  summary: Get one or multiple random members from a set
  since: 1.0.0

  SREM key member [member ...]
  summary: Remove one or more members from a set
  since: 1.0.0

  SSCAN key cursor [MATCH pattern] [COUNT count]
  summary: Incrementally iterate Set elements
  since: 2.8.0

  SUNION key [key ...]
  summary: Add multiple sets
  since: 1.0.0

  SUNIONSTORE destination key [key ...]
  summary: Add multiple sets and store the resulting set in a key
  since: 1.0.0
Hash
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
HDEL key field [field ...]
  summary: Delete one or more hash fields
  since: 2.0.0

  HEXISTS key field
  summary: Determine if a hash field exists
  since: 2.0.0

  HGET key field
  summary: Get the value of a hash field
  since: 2.0.0

  HGETALL key
  summary: Get all the fields and values in a hash
  since: 2.0.0

  HINCRBY key field increment
  summary: Increment the integer value of a hash field by the given number
  since: 2.0.0

  HINCRBYFLOAT key field increment
  summary: Increment the float value of a hash field by the given amount
  since: 2.6.0

  HKEYS key
  summary: Get all the fields in a hash
  since: 2.0.0

  HLEN key
  summary: Get the number of fields in a hash
  since: 2.0.0

  HMGET key field [field ...]
  summary: Get the values of all the given hash fields
  since: 2.0.0

  HMSET key field value [field value ...]
  summary: Set multiple hash fields to multiple values
  since: 2.0.0

  HSCAN key cursor [MATCH pattern] [COUNT count]
  summary: Incrementally iterate hash fields and associated values
  since: 2.8.0

  HSET key field value
  summary: Set the string value of a hash field
  since: 2.0.0

  HSETNX key field value
  summary: Set the value of a hash field, only if the field does not exist
  since: 2.0.0

  HSTRLEN key field
  summary: Get the length of the value of a hash field
  since: 3.2.0

  HVALS key
  summary: Get all the values in a hash
  since: 2.0.0
zset
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
ZADD key [NX|XX] [CH] [INCR] score member [score member ...]
  summary: Add one or more members to a sorted set, or update its score if it already exists
  since: 1.2.0

  ZCARD key
  summary: Get the number of members in a sorted set
  since: 1.2.0

  ZCOUNT key min max
  summary: Count the members in a sorted set with scores within the given values
  since: 2.0.0

  ZINCRBY key increment member
  summary: Increment the score of a member in a sorted set
  since: 1.2.0

  ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]
  summary: Intersect multiple sorted sets and store the resulting sorted set in a new key
  since: 2.0.0

  ZLEXCOUNT key min max
  summary: Count the number of members in a sorted set between a given lexicographical range
  since: 2.8.9

  ZRANGE key start stop [WITHSCORES]
  summary: Return a range of members in a sorted set, by index
  since: 1.2.0

  ZRANGEBYLEX key min max [LIMIT offset count]
  summary: Return a range of members in a sorted set, by lexicographical range
  since: 2.8.9

  ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
  summary: Return a range of members in a sorted set, by score
  since: 1.0.5

  ZRANK key member
  summary: Determine the index of a member in a sorted set
  since: 2.0.0

  ZREM key member [member ...]
  summary: Remove one or more members from a sorted set
  since: 1.2.0

  ZREMRANGEBYLEX key min max
  summary: Remove all members in a sorted set between the given lexicographical range
  since: 2.8.9

  ZREMRANGEBYRANK key start stop
  summary: Remove all members in a sorted set within the given indexes
  since: 2.0.0

  ZREMRANGEBYSCORE key min max
  summary: Remove all members in a sorted set within the given scores
  since: 1.2.0

  ZREVRANGE key start stop [WITHSCORES]
  summary: Return a range of members in a sorted set, by index, with scores ordered from high to low
  since: 1.2.0

  ZREVRANGEBYLEX key max min [LIMIT offset count]
  summary: Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings.
  since: 2.8.9

  ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
  summary: Return a range of members in a sorted set, by score, with scores ordered from high to low
  since: 2.2.0

  ZREVRANK key member
  summary: Determine the index of a member in a sorted set, with scores ordered from high to low
  since: 2.0.0

  ZSCAN key cursor [MATCH pattern] [COUNT count]
  summary: Incrementally iterate sorted sets elements and associated scores
  since: 2.8.0

  ZSCORE key member
  summary: Get the score associated with the given member in a sorted set
  since: 1.2.0

  ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]
  summary: Add multiple sorted sets and store the resulting sorted set in a new key
  since: 2.0.0
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
redis之list核心命令演示与细节探索
BLMOVE source destination LEFT|RIGHT LEFT|RIGHT timeout summary: Pop an element from a list, push it to another list and return it; or block until one is available since: 6.2.0
九转成圣
2024/09/08
1090
Redis基础
Redis(全称:Remote Dictionary Server 远程字典服务)是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。 Redis 是一个高性能的key-value非关系型数据库。 redis的出现,很大程度补偿了memcached这类key/value存储的不足,在部 分场合可以对关系数据库起到很好的补充作用。它提供了Java,C/C++,C#,PHP,JavaScript,Perl,Object-C,Python,Ruby,Erlang等客户端,使用很方便。
GH
2020/02/13
8530
redis list命令操作
9.向list中添加一个或多个value,后加入的值,index在前(将元素压入栈顶)
周小董
2019/03/25
1.8K0
Redis命令详解:Sorted Sets
Sorted Set(也称ZSET)和Set一样也是string类型的集合,你可以将它理解为Java中SortedSet和HashMap的集合体,一方面它是一个set,保证了元素的唯一性,另一方面它给每个value赋予了一个权重score,用来进行排序。集合中成员的最大个数为232-1个。
Jackeyzhe
2020/03/11
1.4K0
Redis详解
1.关于关系型数据库和nosql数据库 关系型数据库是基于关系表的数据库,最终会将数据持久化到磁盘上,而nosql数据 库是基于特殊的结构,并将数据存储到内存的数据库。从性能上而言,nosql数据库 要优于关系型数据库,从安全性上而言关系型数据库要优于nosql数据库,所以在实 际开发中一个项目中nosql和关系型数据库会一起使用,达到性能和安全性的双保证。
用户5927264
2019/07/31
8620
新人入坑Redis必会的吐血总结
Redis是一个使用C语言开发的开源的高性能的key-value存储系统,我们可以把它近似理解为Java Map。简单来讲,Redis是一种NOSQL内存数据库,小伙伴们可不要把它理解为NO SQL(不是SQL),它的全称是Not Only SQL(不仅仅是SQL),换个层面来讲,它是一种非关系型的数据库,它是作为关系型数据库的良好补充,它与传统的MySQL,Oracle不同之处在于,它是通过在内存中读写数据,大大提高了读写速度。可以说,Redis是为了解决网站高并发、高可用、高可扩展、大数据存储等一系列问题而产生的数据库解决方案,不可或缺的一部分。
Angel_Kitty
2018/09/21
4.2K0
新人入坑Redis必会的吐血总结
Redis学习(1)——概述和常用命令
优点:数据之间有关系、进行数据的增删改查时非常方便、关系型数据库有事务操作,保证数据的完整性。
sunonzj
2022/06/21
4180
Redis学习(1)——概述和常用命令
Redis 缓存中间件
一个网站演变的过程中,用户量的增加引起了并发量提高,如果不做处理,则频繁的查询数据库,结果是页面显示的慢,服务器、数据库不堪重负。如果网站页面所展示的数据的更新不是特别频繁,想提高页面显示的速度,减轻服务器的负担,此时应该考虑使用缓存。
架构探险之道
2023/03/04
8270
Redis 缓存中间件
Redis 数据类型
Redis支持五种数据类型:String(字符串),Hash(哈希),List(列表),Set(集合)及Zset(sorted set:有序集合)。
星哥玩云
2022/09/15
9360
【Redis】五种数据类型及其使用场景
存储的数据:单个数据,最简单的数据存储类型,也是最常用的数据存储类型 存储数据的格式:一个存储空间保存一个数据 存储内容:通常使用字符串,如果字符串以整数的形式展示,可以作为数字操作使用(但是仍是字符串)
全栈程序员站长
2022/07/25
1.1K0
【Redis】五种数据类型及其使用场景
[Redis]Redis 概述及基本使用规范.
1 nosql的简介 1.1 nosql简介 随着互联网Web2.0网站的兴起,传统的关系数据库在应付Web2.0网站,特别是超大规模和高并发的SNS类型的Web2.0纯动态网站已经显得力不从心,暴露了很多难以克服的问题,如: 1.1.1 对数据库高并发读写的需求 网站要根据用户个性化信息来实时生成动态页面和提供动态信息,所以基本上无法使用动态页面静态化技术,因此数据库并发负载非常高,往往要达到每秒上万次读写请求。关系数据库应付上万次SQL查询还勉强顶得住,但是应付上千万次SQL写数据请求,硬盘IO就已经
一枝花算不算浪漫
2018/05/18
1.3K0
Redis从青铜到王者,从环境搭建到熟练使用,看这一篇就够了,超全整理详细解析,赶紧收藏吧!!!
一、常见的非关系型数据库NOSQL分类 二、了解Redis 三、Redis的单节点安装教程 四、Redis的常用命令 1、Help帮助命令 2、SET命令 3、过期命令 4、查找键命令 5、操作键命令 6、GET命令 7、步长命令 8、登录不同的库命令 9、清除当前库数据命令 10、清除所有库中的数据命令 五、BITMAP位图 1、位图常用命令 2、位操作命令 3、统计指定位区间上值为1的个数 六、Redis的数据模型 1、Redis的 key 键 2、Redis的 Value 值 1、String字符串 2、 List列表 3、 Hash散列 4、Set集合 5、SortedSet有序集合 七、Redis持久化 1、Redis持久化-RDB (1)RDB使用策略 (2)SAVE命令 (3)BGSAVE命令 (4)SAVE 和 BGSAVE 命令的区别 (5)RDB持久化的优缺点 2、Redis持久化-AOF (1)AOF写入机制 (2) 写入磁盘的策略 (3)AOF重写机制 (4)AOF重写触发 (5)AOF持久化的优缺点 八、idea使用Jedis连接Redis
全栈程序员站长
2022/08/25
4950
Redis从青铜到王者,从环境搭建到熟练使用,看这一篇就够了,超全整理详细解析,赶紧收藏吧!!!
Redis-各数据类型常用命令(含使用示例)
Redis的全部命令详情可以在官网查询。 点此Redis系列文章专栏 命令不自己敲一遍,都是白搭,就算忘了也可以翻这篇博客。
唔仄lo咚锵
2020/09/15
4720
redis学习教程之一基本命令
参阅redis中文的 互动教程(interactive tutorial)的学习笔记。 全局操作: #查看所有key keys * 或 keys "*" #查看匹配前缀的keys keys "miao*" #清空redis flushdb #随机取出一个key randomkey #查看key的类型 type key #查看数据库中key的数量 dbsize #查看服务器信息 info #查看redis正在做什么 monitor #注意,有高手的文章说这个会急剧降低redis性能,只能
Ryan-Miao
2018/03/13
1.1K0
redis学习教程之一基本命令
redis全面解析
Redis 是开源免费的,遵守BSD协议,是一个高性能的key-value非关系型数据库。
Java架构师必看
2021/05/14
4970
redis全面解析
Redis 有序集合
有序集合是给每个元素设置一个分数(score)作为排序的依据这一概念的集合,其也是不能有重复元素的。有序集合提供了获取指定分数和元素范围查询、计算成员排名等功能。
三产
2021/01/12
9700
YCSB测试Redis方法总结
https://github.com/brianfrankcooper/YCSB/tree/master/redis
mingjie
2022/05/12
1K0
Redis基础知识(一)
Redis 是一个开源的使用 ANSI C 语言编写、遵守 BSD 协议、支持网络、可基于内存亦可持久化的日志型、Key-Value 数据库,并提供多种语言的 API。 它通常被称为数据结构服务器,因为值(value)可以是 字符串(String), 哈希(Map),列表(list),集合(sets)和 有序集合(sorted sets)等类型。
没有故事的陈师傅
2019/12/11
1.4K0
Redis使用场景总结
九转成圣
2024/04/10
1440
认识redis数据类型
Redis hash 是一个string类型的field和value的映射表,hash特别适合用于存储对象。
老雷PHP全栈开发
2020/07/02
1.5K0
相关推荐
redis之list核心命令演示与细节探索
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验