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

204
Visualizações
Redis-om search cannot find key after updating

I have some strange behaviour happening with my Redis-OM application, I understand that this is still a very BETA version of the software but I just wanted to make sure I wasn't doing something dumb (which I might be)

So I am setting up an application to keep a playlist of video ID's within a Room that I store temporarily in a Redis Cloud Database.

I have a function that creates a Room, one that fetches the Room details (everything currently in the room) and one that adds a new video to the Playlist within that room. (see below) - NOTE: the data variable within createRoom(data) is just a string of the Room ID

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

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

    const repository = new Repository(schema, client);

    const room = repository.createEntity(data);

    const id = await repository.save(room);

    await client.execute(['EXPIRE', `Room:${id}`, 43200]);

    return id;
}

export async function getRoom(code) {
    await connect();

    const repository = new Repository(schema, client);

    const room = await repository
        .search()
        .where('code')
        .equals(code)
        .returnFirst();

    return room;
}

export async function addVideoToRoom(code, videoDetails) {
    const room = await getRoom(code);
    await room.playlist.push(videoDetails);

    await connect();

    const repository = new Repository(schema, client);

    const id = await repository.save(room);

    return id;
}

The primary issue that I'm having is adding a second video to the playlist. What happens is

  • Create Room - adds a new room to the DB
  • Search for video
  • Click to add video to DB (video is successfully added)
  • Click to add second video to DB (fails because getRoom(code)fails - returns null)

This was working yesterday, however I'm not sure why it no longer works.

If anyone has any idea's why that might be please let me know, I have a feeling it may be how I'm handling clients or indexes with Redis so I have popped my functions for those below too.

const client = new Client();

async function connect() {
    if (!client.isOpen()) {
        await client.open(process.env.REDIS_URL);
    }
}

export async function createIndex() {
    await connect();

    const repository = new Repository(schema, client);

    await repository.dropIndex();

    await repository.createIndex();
}

Thanks very much programmers of Stack - If I'm being super dumb I do apologise.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Redis OM for Node.js supports neither nested objects nor a type of 'object' within the Schema. Valid types are 'string', 'number', 'boolean', and 'array'. Arrays are only arrays of strings. The rest are self-explanatory.

If you want to have a Room that has multiple Videos, you need to define a Room entity, perhaps with a playlist that is defined as an array not of objects, but of Video ids.

Details on this can be found in the README.

over 4 years ago · Santiago Trujillo 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