redis 查找key使用正在表达式与java的区别

redis与java的正则表达式语法有些区别,需要特别注意一下。

Redis支持的正则表达式规则如下‌:

  • *:匹配任意数量的字符。
  • ?:匹配零或一个字符。
  • []:匹配指定范围内的字符‌12。

Redis中使用正则表达式的命令和示例‌:

  • KEYS pattern:该命令可以返回与指定模式匹配的所有键名。例如,KEYS user*可以获取所有以"user"开头的键‌3。
  • SCAN:这是一个迭代器命令,用于逐步遍历键空间。它支持使用正则表达式,但需要注意的是,SCAN命令本身不支持直接使用正则表达式,而是通过模式匹配来实现类似的功能。例如,SCAN 0 MATCH *pattern*可以逐步返回匹配指定模式的键‌。

Keys

Another way to iterate over the keyspace is to use the KEYS command, but this approach should be used with care, since KEYS will block the Redis server until all keys are returned.

Warning : consider KEYS as a command that should only be used in production environments with extreme care.

KEYS may ruin performance when it is executed against large databases. This command is intended for debugging and special operations, such as changing your keyspace layout. Don't use KEYS in your regular application code. If you're looking for a way to find keys in a subset of your keyspace, consider using SCAN or sets.

Supported glob-style patterns:

  • h?llo matches hello, hallo and hxllo
  • h*llo matches hllo and heeeello
  • h[ae]llo matches hello and hallo, but not hillo
  • h[^e]llo matches hallo, hbllo, ... but not hello
  • h[a-b]llo matches hallo and hbllo

Use \ to escape special characters if you want to match them verbatim.

相关推荐
就叫_这个吧3 分钟前
RabbitMQ+elasticsearch+Redis,实现新增内容并异步到es中,是否消费成功检测
redis·elasticsearch·rabbitmq
谢亮_vipxieliang6 分钟前
手机号验证技术方案:号段规则与正则表达式
java·服务器·spring boot·正则表达式·hibernate
敲代码的小小酥16 分钟前
InfluxDB时序数据库(续)
数据库·时序数据库
wang090718 分钟前
自己动手写一个tomcat之7监听器和过滤器
java·tomcat
梅孔立18 分钟前
Pi-Agent 终极极简配置文档(Java+Vue+Python爬虫 4-5千文件项目)
java·vue.js·python
李可以量化23 分钟前
Redis Client 从了解到精通(二)下:String 类型进阶操作全解
redis·git·python·量化交易·qmt
Query*31 分钟前
Agent 开发之项目 AI Native 化:通过大模型与 RAG 赋予产品智能能力
java·人工智能·ai
孫治AllenSun31 分钟前
【LangChain4J-03】Springboot 项目搭建框架
java·spring boot·后端
君顾132 分钟前
AI新零售线上商城系统实战:架构设计与开发全流程指南
java·开发语言·零售
智购科技自动贩卖机38 分钟前
自动售货机嵌入式系统Go语言开发实践:从资源受限设备到RTOS协程调度的工程化之路
大数据·linux·数据库·人工智能·yolo·架构·golang