Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

220
Vistas
Redis: How is the result of KEYS * sorted?

I have a very simple php redis application which creates keys at certain events. All the keys are just counters and have an expire time of 24 hours. Basically a rolling window of 24 hours for every key to gather some statistics.

if ($redis->exists($key)) {
    $redis->incr($key); 
}
else {
    $redis->set($key, '1');
    $now = time(); // current timestamp
    $redis->expireAt($key, $now + 86400);
}

When I extract an overview of all my keys with $list = $redis->keys("*"); (or in a redis-cli console with keys *), I would suspect a chronological order by creation date. However this is not case. Neither are they ordered alphabetically, by value...

So my question is, how is this list sorted?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

First of all, don't use keys * it is debug function not designed for a production, you can kill your server... If you need enumerate all keys in DB in safe way, use SCAN function with LIMIT.

Anyway results of keys or scan is not sorted in any manner, order of results related to internal memory structure of redis's hashtable.

About your php script, you can do it by a single command, without exists set expireat just run:

SET key 1 EX 86400 NX

EX 86400 mean expire in 86400 (1 day) seconds from now

NX mean create a key only if it doesn't exists.

If this command return (nil) run regular INCR key its mean that the key already exists. BTW INCR command will not remove your expire settings.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda