Frage

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

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top