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

406
Visualizações
Setting the TTL (expire) using new Redis-OM & Node Object Mapping

I came across the new Redis-OM Node Object Mapping functionality, I've not really experimented with Redis before but I thought now might be the time to give it a go.

Right now I have a basic function set up for creating a room but I would like the room to expire after say 24 hours (86400 seconds iirc).

export async function createRoom(data) {
    await connect();

    const repository = new Repository(schema, client);

    const room = repository.createEntity(data);

    const id = await repository.save(room);

    return id;
}

How do I set the TTL or expire time for an object using the Object Mapping approach... see my schema below.

class Room extends Entity {}
let schema = new Schema(
    Room,
    {
        code: { type: 'string' },
        playlist: { type: 'array', videos: { type: 'string' } },
    },
    {
        dataStructure: 'JSON',
    }
);

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Right now, Redis OM doesn't support setting the TTL as part of object mapping but I think it's a good idea and will put it in the backlog.

For now, you can set it manually using the Client.execute() method to call EXPIRE on the key containing the object you want to expire.

Details on the EXPIRE command are here but it's pretty much just EXPIRE key seconds.

They key for objects in Redis OM for Node.js is made up of the entity name and the entity ID separated by a colon. So, in your example, this would be something like Room:01FT4JWNQ2FJHQEVWXNRMWZ2QR.

Putting this together, here's the magic line of code:

await client.execute(['EXPIRE', `Room:${id}`, 3600]);
about 4 years ago · Juan Pablo Isaza Relatório
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