Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use scan of php redis

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "how to use the scan of php redis". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

When deleting the cache, we need to delete it in batch in some scenarios, but we are not sure the specific key value. We can query it by matching and delete it.

However, using keys can cause the redis server to go down. Use it cautiously.

In general, companies will also disable more sensitive commands such as keys. [related recommendation: Redis video tutorial]

So the scan command is used to match the query at work.

SCAN cursor [MATCH pattern] [COUNT count]

such as

# scan key values that match test1:* from cursor 0, scanning 1000 scan 0 match test1:* count 1000 at a time

1) represents the cursor value for the next scan, and the command line displays a string type. 2) indicates the list of key values matched by this scan

How to implement it with php code, for example

Function getKeysByPattern ($pattern) {$keysList = []; while (true) {/ / @ todo replace the client here with your own redis client object $keys = $client- > scan ($iterator, $pattern,1000); $keysList = array_merge ($keysList, $keys?? []); if ($iterator = 0) {/ / iteration ended and no key break matching pattern was found } if ($iterator = null) {/ / "cursor is null, reset to 0, continue to scan" $iterator = "0";}} $keysList = array_unique ($keysList); return keysList;} "how to use scan for php redis" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report