当前位置:网站首页>【Redis】通用命令
【Redis】通用命令
2022-08-02 08:55:00 【准Java全栈开发工程师】
通用命令
一、key 通用命令
在介绍和 key 相关的通用命令之前,我们需要清楚 key 是一个字符串,通过 key 来获取 Redis 中存储的数据。
1、删除指定 key
命令格式:del key
2、判断指定 key 是否存在
命令格式:exists key
3、获取 key 的类型
命令格式:type key
4、为 key 设置有效期
命令格式:expire key seconds
解释:seconds 用于设置有效时间,单位为秒
命令格式:pexpire key milliseconds
解释:milliseconds 用于设置有效时间,单位为毫秒
以下两种方式使用时间戳的方式设置有效时间
命令格式:expireat key timestamp
命令格式:pexpireat key milliseconds-timestamp
5、获取 key 有效时间
命令格式:ttl key
解释:单位为秒
命令格式:pttl key
解释:单位为毫秒
6、切换 key 从时效性转换为永久性
命令格式:persist key
解释:使得指定 key 永久存在
7、查询 key
命令格式:keys pattern
查询规则:
* 匹配任意数量的任意符号
? 匹配一个任意符号
[] 匹配一个指定符号
示例:
keys * 查询所有
keys n* 查询所有以 n 开头的
keys *e 查询所有以 e 结尾的
keys ??me 查询前两个为任意字符,后面以 me 结尾的
keys n[abc]me 查询以 n 开头,以 me 结尾,中间包含 1 个字母,该字母为 a 或 b 或 c
8、改名
命令格式:rename key newkey
解释:更改 key 的名字
命令格式:renamenx key newkey
解释:只有在新指定的 newkey 名字不存在时才能够将名字更改成功
9、排序
命令格式:sort key
解释:为 key 排序,但不会修改 key 中的数据,只是将排序后的内容打印出来
二、数据库通用指令
在介绍数据库通用指令之前,我们需要清楚 Redis 为每个服务提供有 16 个数据库,编号从 0 到 15,且每个数据库的大小并不是相等的,每个数据库之间的数据相互独立。
1、切换数据库
命令格式:select index
解释:index 的取值范围为 0 - 15,默认为 0
2、数据移动
命令格式:move key db
解释:将当前数据库中指定 key 移动到指定数据库 db 中
3、数据清除
命令格式:dbsize
解释:获取当前数据库中的 key 的数量
命令格式:flushdb
解释:清空当前数据库中所有的 key
命令格式:flushall
解释:清空所有数据库中的所有的 key
以上就是文章的全部内容啦,诸佬如果有任何建议都可以提哦。
创作不易,如果觉得对您有帮助的话,欢迎关注点赞收藏哦。
边栏推荐
- The packet capture tool Charles modifies the Response step
- PyCharm usage tutorial (detailed version - graphic and text combination)
- LeetCode_2357_使数组种所有元素都等于零
- What is the function of page directive contentPage/pageEncoding in JSP page?
- PyQt5安装配置(PyCharm) 亲测可用
- Codeforces Round #811 (Div. 3)无DF
- What attributes and methods are available for page directives in JSP pages?
- Redisson报异常attempt to unlock lock, not locked by current thread by node id解决方案
- Gorilla Mux 和 GORM 的使用方法
- 初学者怎么快速学会SQL
猜你喜欢
【C】关于柔性数组.简要的谈谈柔性数组
Rust 从入门到精通03-helloworld
百数应用中心——选择一款适合企业的标准应用
MySQL读写分离与主从延迟
shell脚本
Redisson报异常attempt to unlock lock, not locked by current thread by node id解决方案
Bigder:41/100生产bug有哪些分类
PyCharm usage tutorial (detailed version - graphic and text combination)
MySQL ODBC驱动简介
etcd implements large-scale service governance application combat
随机推荐
PyCharm usage tutorial (more detailed, picture + text)
边缘计算开源项目概述
动态规划每日一练(2)
2022牛客暑期多校训练营4(ADHKLMN)
Codeforces Round #811 (Div. 3)无DF
不用Swagger,那我用啥?
WebGPU 导入[1] - 入门常见问题与个人分享
tf.where使用
【论文阅读】Distilling the Knowledge in a Neural Network
USACO美国信息学奥赛竞赛12月份开赛,中国学生备赛指南
腾讯T8架构师,教你学中小研发团队架构实践PDF,高级架构师捷径
Technology Cloud Report: To realize the metaverse, NVIDIA starts from building an infrastructure platform
Rust from entry to master 03-helloworld
leetcode:81. 搜索旋转排序数组 II
Redis分布式锁入门
TiFlash 存储层概览
AttributeError: module ‘clr‘ has no attribute ‘AddReference‘
“蔚来杯“2022牛客暑期多校训练营4
Mysql Mac版下载安装教程
Detailed explanation of calculation commands in shell (expr, (()), $[], let, bc )