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.

相关推荐
rchmin几秒前
mysql中 char 和 varchar 的区别
数据库·mysql
SelectDB4 分钟前
深入理解 Doris Variant:如何让 JSON 查询性能追平列存,还能承载万列索引字段?|Deep Dive
大数据·数据库·数据分析
百***3289 分钟前
数据库(MySQL):使用命令从零开始在Navicat创建一个数据库及其数据表(一).创建基础表
数据库·mysql·oracle
转转技术团队21 分钟前
MyBatis-Plus踩坑血泪史:那些年我们踩过的坑!
java·面试·mybatis
i***665021 分钟前
Spring Boot 整合 Redis 步骤详解
spring boot·redis·bootstrap
q***d17330 分钟前
SQL性能调优
数据库·sql
sg_knight33 分钟前
IntelliJ IDEA 实用插件:GitToolBox 使用指南
java·ide·git·intellij-idea·插件·gittoolbox
青云交42 分钟前
Java 大视界 -- Java 大数据机器学习模型在电商用户画像构建与精准营销中的应用
java·大数据·机器学习·电商·协同过滤·用户画像·精准营销
z***67771 小时前
Spring EL 表达式的简单介绍和使用
java·后端·spring
q***T5831 小时前
MySQL爬虫
数据库·爬虫·mysql