Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda