Jacob Kranz
Jacob Kranz

Reputation: 951

redis use range of numbers with KEYS

I have some keys called Events:21039-lat:101.2321-long:24.3143. Now, I'd like to search for all keys where it goes something like this: Events:*-lat:[any number between 99.2321 and 103.2321]-long:[any number between 23.3143 and 25.3143].

The reason why I'm deciding to use keys is because there are not many events written to, therefore I can have many many read slaves, and otherwise I'd have to do this calculation in a highly non-scaleable way w. mysql. Is there a better way with/without redis though?

Upvotes: 0

Views: 437

Answers (1)

Manu Manjunath
Manu Manjunath

Reputation: 6411

Usage of keys in a production environment is not recommended. It's time complexity is O(N) with N being the number of keys in the database. (source: http://redis.io/commands/keys)

You can maintain a bunch of Events:* keys in a set. Read the set using sMembers() and fetch those keys.

In case you're worried about an additional network call, use a pipeline.

Upvotes: 3

Related Questions