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

120
Vistas
Sorting with IoRedis- possible without pure JS?

is it possible to sort data using ioRedis without using js' functions? I have this kinda get function which is supposed to sort authors by their age (year).

When I create an author, I do something like this:

http localhost:5000/authors id=1 name="name" lastname="lastname" year=1970

I need to do it using JSON.stringify because if I don't, then under they key there is [object Object]

Then I parse each of stringified, because keys look like this:

[
  '{"id":"2","name":"autor","lastname":"ch","year":"1998"}',
  '{"id":"5","name":"autor5","lastname":"ch","year":"2005"}',
  '{"id":"4","name":"autor4","lastname":"ch","year":"2002"}',
  '{"id":"3","name":"autor3","lastname":"ch","year":"1997"}'
]

My code:

router.get("/", async (req, res) => {
    const keys = await client.smembers("authors")
    console.log(keys)
    const keysMapped = keys.map(key => JSON.parse(key))
    const sorted = await client.sort(keysMapped.year)
    //console.log(typeof keysMapped)
    //console.log(sorted)
    return res.send(sorted);
});

router.post("/", async (req, res) => {
    try {
        const wynik = await client.hset("authors", JSON.stringify(req.body))
        return res.send(req.body)
    } catch (err) {
        console.error(err)
    }
});

The sort function doesn't seem to work, but I don't know how to try in in any other way. There is SORT in Redis, but I don't know if it's available in ioRedis also or I should use maybe Lodash or pure JS?

about 4 years ago · Juan Pablo Isaza
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