惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
有赞技术团队
有赞技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
Threat Research - Cisco Blogs
L
LangChain Blog
Simon Willison's Weblog
Simon Willison's Weblog
Project Zero
Project Zero
Latest news
Latest news
S
Schneier on Security
Cisco Talos Blog
Cisco Talos Blog
MyScale Blog
MyScale Blog
C
Check Point Blog
IT之家
IT之家
P
Palo Alto Networks Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
G
Google Developers Blog
T
Tor Project blog
T
Threatpost
D
DataBreaches.Net
博客园 - 【当耐特】
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Troy Hunt's Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Vercel News
Vercel News
云风的 BLOG
云风的 BLOG
NISL@THU
NISL@THU
P
Privacy & Cybersecurity Law Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
Cisco Blogs
博客园_首页
S
Securelist
T
The Exploit Database - CXSecurity.com
Last Week in AI
Last Week in AI
量子位
U
Unit 42
Know Your Adversary
Know Your Adversary
Hugging Face - Blog
Hugging Face - Blog
S
Security Affairs
Google Online Security Blog
Google Online Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
S
SegmentFault 最新的问题
Engineering at Meta
Engineering at Meta
N
News and Events Feed by Topic
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志

Liu Zijian's Blog | 一个技术博客

使用Certbot自动续签HTTPS证书 使用Filebeat采集Nginx日志到ES Python的协程 Python中的异常 Python中的类和对象 Python的函数 Python的数据结构,推导式、迭代器和生成器 Spring AI集成多模态模型 LangChain4j多模态 LangChain Tools工具使用 Python中的模块和包 Python全局环境和虚拟环境(venv) LangChain Prompt提示词工程 LangChain4j Tools工具使用 基于Dify搭建AI智能体应用 LangChain4j RAG检索增强生成 Spring AI实现MCP Server Spring AI集成MCP Client LangChain4j Prompt提示词工程 Spring AI使用知识库增强对话功能 Spring AI实现一个智能客服 Spring AI实现一个简单的对话机器人 实现MinIO数据的每日备份 自己实现一个DNS服务 简单理解AI智能体 大模型和大模型应用 LangChain开篇 LangChain4j开篇 一个解析Excel2007的POI工具类 DataPermissionInterceptor源码解读 TenantLineInnerInterceptor源码解读 BaseMultiTableInnerInterceptor源码解读 Spring AI开篇 SQL解析工具JSQLParser 芋道源码解读之多租户 芋道源码解读之数据权限 芋道源码解读开篇 Java实现将数据导出为Word文档 OA系统的天数该怎样计算 安装MySQL8 安装MySQL5.7 RockyLinux9环境下编译MySQL8 MySQL字符集及底层原理 Java实现LDAP登录 Docker Compose IPv4和IPv6 使用虚拟机安装一个K8s集群 使用GraalVM原生编译打包SpringBoot工程 Nginx防止目录穿越 Java线程的状态 Nginx防盗链设置 使用python将excel表格转换为SQL INSERT Redis数据结构之Bitfleid Redis数据结构之Bitmap Redis数据结构之GEO Redis数据结构之Hash Redis数据结构之HyperLogLog Redis数据结构之List Redis数据结构之Set Redis数据结构之Stream Redis数据结构之String Redis数据结构之ZSet 使用python压缩图片 利用Python实现Hexo站点的持续集成 Nginx设置HTTPS监听 firewalld防火墙工具的使用 Linux信号(signal)机制 MySQL5.7x 主从复制 用IP自签发一个HTTPS证书 基于Hexo实现一个静态的个人博客 RockyLinux9环境下编译MySQL5.7 Docker离线安装 MySQL数据定义语言 Docker与联合文件系统 Docker的网络 Docker的镜像操作 MySQL存储过程 MyBatis-Plus开篇 MySQL变量 MySQL视图 MySQL事务 MySQL插入修改和删除 MySQL查询 MySQL系统命令 Docker的容器操作 Docker的安装和配置 Docker容器数据卷 浅谈OAuth2.0授权原理 JVM开篇 浅谈Linux(Unix)的I/O模型 一个通用的CloseableHttpClient工厂类 JUC可重入锁ReentrantLock JUC读写锁ReadWriteLock Java的单例 Java泛型 Java8的新特性 最近最少使用算法(LRU) MySQL函数 SpringBoot配置和启动 volatile作用分析
Redis的公共操作命令
Liu Zijian · 2024-10-16 · via Liu Zijian's Blog | 一个技术博客

1.Key操作命令

Redis是Key-Value数据库,Key都是字符串且区分大小写,关于Redis的key操作,主要有常见的以下几个

Redis的命令是不区分大小写的

1.1 keys *

查看当前库所有的Key,类似于数据库的select * from tb_xxx

127.0.0.1:6379> keys *
1) "k1"
2) "k2"

1.2 exists <key]>

Key是否存在,返回bool,1代表true,0代表false

127.0.0.1:6379> exists k1
(integer) 1
127.0.0.1:6379> exists k2
(integer) 1
127.0.0.1:6379> exists k3
(integer) 0

Redis的底层使用C语言实现,很多命令返回bool时,多用0和1表示

1.3 type <key>

key对应的value是什么类型

127.0.0.1:6379> type k1
string

1.4 del <key>

删除数据,返回bool

127.0.0.1:6379> del k2
(integer) 1

非阻塞删除,仅仅将key从keyspace元数据中删除,真正的数据删除将在后续异步进行,返回bool

127.0.0.1:6379> unlink k1
(integer) 1

1.6 ttl <key>

查看key还有多少秒过期,-1代表永不过期,-2代表已过期,通常和expire命令搭配使用

127.0.0.1:6379> ttl k1
(integer) -1

1.7 expire <key> <秒数>

为指定的key设置过期时间

127.0.0.1:6379> expire k1 100
(integer) 1
127.0.0.1:6379> ttl k1
(integer) 90
127.0.0.1:6379> ttl k1
(integer) 86

1.8 move <key> <index>

将当前key移动到指定的数据库中,返回bool

127.0.0.1:6379> move k1 2
(integer) 1

2.库操作命令

2.1 select <index>

选中几号仓库。redis.conf配置文件默认Redis共16个数据库(0-15),默认选中0号库

127.0.0.1:6379> select 2
OK
127.0.0.1:6379[2]> select 3
OK
127.0.0.1:6379[3]> 

2.2 dbsize

查看当前库有多少key

127.0.0.1:6379[3]> dbsize
(integer) 0
127.0.0.1:6379[3]> set k1 v1
OK
127.0.0.1:6379[3]> dbsize
(integer) 1
127.0.0.1:6379[3]> 

2.3 flushdb

清空当前库中的所有key

127.0.0.1:6379> flushdb
OK

2.4 flushall

清空整个Redis中的所有key

127.0.0.1:6379> flushall
OK

3.其他命令

3.1 help @<type>

命令行下输入help @<type>命令,redis服务器会返回该数据类型的所有用法

127.0.0.1:6379> help @string

APPEND key value
summary: Appends a string to the value of a key. Creates the key if it doesn't exist.
since: 2.0.0

DECR key
summary: Decrements the integer value of a key by one. Uses 0 as initial value if the key doesn't exist.
since: 1.0.0

DECRBY key decrement
summary: Decrements a number from the integer value of a key. Uses 0 as initial value if the key doesn't exist.
since: 1.0.0

GET key
summary: Returns the string value of a key.
since: 1.0.0

GETDEL key
summary: Returns the string value of a key after deleting the key.
since: 6.2.0

GETEX key [EX seconds|PX milliseconds|EXAT unix-time-seconds|PXAT unix-time-milliseconds|PERSIST]
summary: Returns the string value of a key after setting its expiration time.
since: 6.2.0

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

GETSET key value
summary: Returns the previous string value of a key after setting it to a new value.
since: 1.0.0

INCR key
summary: Increments the integer value of a key by one. Uses 0 as initial value if the key doesn't exist.
since: 1.0.0

INCRBY key increment
summary: Increments the integer value of a key by a number. Uses 0 as initial value if the key doesn't exist.
since: 1.0.0

INCRBYFLOAT key increment
summary: Increment the floating point value of a key by a number. Uses 0 as initial value if the key doesn't exist.
since: 2.6.0

LCS key1 key2 [LEN] [IDX] [MINMATCHLEN min-match-len] [WITHMATCHLEN]
summary: Finds the longest common substring.
since: 7.0.0

MGET key [key ...]
summary: Atomically returns the string values of one or more keys.
since: 1.0.0

MSET key value [key value ...]
summary: Atomically creates or modifies the string values of one or more keys.
since: 1.0.1

MSETNX key value [key value ...]
summary: Atomically modifies the string values of one or more keys only when all keys don't exist.
since: 1.0.1

PSETEX key milliseconds value
summary: Sets both string value and expiration time in milliseconds of a key. The key is created if it doesn't exist.
since: 2.6.0

SET key value [NX|XX] [GET] [EX seconds|PX milliseconds|EXAT unix-time-seconds|PXAT unix-time-milliseconds|KEEPTTL]
summary: Sets the string value of a key, ignoring its type. The key is created if it doesn't exist.
since: 1.0.0

SETEX key seconds value
summary: Sets the string value and expiration time of a key. Creates the key if it doesn't exist.
since: 2.0.0

SETNX key value
summary: Set the string value of a key only when the key doesn't exist.
since: 1.0.0

SETRANGE key offset value
summary: Overwrites a part of a string value with another by an offset. Creates the key if it doesn't exist.
since: 2.2.0

STRLEN key
summary: Returns the length of a string value.
since: 2.2.0

SUBSTR key start end
summary: Returns a substring from a string value.
since: 1.0.0

127.0.0.1:6379>