如何在redis中实现键的前缀匹配?

How to implement prefix match for keys in redis?

我在 Redis 中有如下一组键值对

"690-product-Qwaf@#45" :"mens-clothing/shirts"
"690-product-Ywsg##67" :"womens-clothing/shirts"
"690-product-Wsrf@%59" : "boys-clothing/sweaters"
"690-brand-P2af@#45" : "Puma"
"690-brand-Z3af&#35" : "Free People"
"690-brand-Q4af%#49" : "True Religion"

我只需要从上面的集合中获取以“690-brand-”开头的键。我怎样才能在 redis 中实现相同的目标?

使用redis的SCAN命令可以扫描键。请参阅文档 http://redis.io/commands/scan

例子

SCAN 0 MATCH "690-brand-*"

有关 node.js 示例,请参阅此

如果您在开发环境中工作或调试某些东西并且数据库不是很大,您也可以使用 KEYS 命令。 Link - http://redis.io/commands/keys

注意:不建议将KEYS用于生产环境。