Redis - Safely retrieving a small set of keys in production database

StackOverflow https://stackoverflow.com/questions/23296681

  •  09-07-2023
  •  | 
  •  

質問

I don't think there is an answer to this but I'm hoping there is something out there. In production, using KEYS is a bad practice as it will scan all records ( O(n) ). If there is a very large number of keys, that can hurt performance.

Assuming there is a very large number of keys in a database, are there any safe ways to get a few of those keys? Eg if I just want to look at a record and I don't really care what I get.

I understand this is more of a design issue (eg use select, use sets) and that I should never really need to run keys unless I know there isn't a huge ammount of data in the database. The motivation is more about being cautious so I don't run keys one day and kill the db because I'm in a different database than I thought

役に立ちましたか?

解決

The recommended approach (as of v2.8) is to use the SCAN command (and siblings) instead. SCAN basically allows you to iterate through your keyspace with a cursor so you don't block other operations.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top