Using redis Cache, the cache key value is a range value (which can be processed). how can I find the corresponding cache when there is a number of zones in the input range?

Source: Internet
Author: User
For example, I now have an array ({code ...}) now, I want to save each value in the array to the redis Cache. the cached key value can be the value of the array key after any processing. at this time, I input a value of 38000, I want to find the cache value with the key value containing 38000 in the cache. what is there... for example:
I now have an array
Array (

'2018 _ 20180101' => 'Shanghai', '2018 _ 20180101' => 'Beijing', '2018 _ 20180101' => 'Tianjin ', '1970 _ 000000' => 'shenzhen'

)
Now, I want to save each value in the array to the redis Cache. the cached key value can be the value of the array key after any processing. at this time, I input a value of 38000, I want to find the cache value with the key value containing 38000 in the cache. Is there any good solution?

Please kindly advise!

Reply content:

For example:
I now have an array
Array (

'2018 _ 20180101' => 'Shanghai', '2018 _ 20180101' => 'Beijing', '2018 _ 20180101' => 'Tianjin ', '1970 _ 000000' => 'shenzhen'

)
Now, I want to save each value in the array to the redis Cache. the cached key value can be the value of the array key after any processing. at this time, I input a value of 38000, I want to find the cache value with the key value containing 38000 in the cache. Is there any good solution?

Please kindly advise!

// If there are many keys in the array but the value is not large, use an ordered set.

$ Redis-> zAdd ('key', 10000, 'Shanghai'); $ redis-> zAdd ('key', 20001, 'Beijing '); $ apsaradb for redis-> zAdd ('key', 30201, 'Tianjin '); $ apsaradb for redis-> zAdd ('key', 30301, 'shenzhen '); $ redis-> zAdd ('key', 40001, 'invalid '); $ index = 38000; $ value = $ redis-> zRangeByScore ('key', $ index, '+ inf', ['limit' => [0, 1]); // Shenzhen

This data is irregular.
In my opinion, foreach, then take out the right part and compare the size. if it is just greater than or equal to 3800, it will jump out of the loop and return the current key value.
Of course, the format must be consistent with your current one, from small to large.

Redis-cli has a command line: keys [patten], patten can be a regular expression, and the key command ending with 38000 is: keys * 38000. The corresponding phpRedis method is named keys and getKeys. for details, refer to keys & getKeys.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.