Skip to content

Instantly share code, notes, and snippets.

@alancriaxyz
Last active April 17, 2024 17:26
Show Gist options
  • Save alancriaxyz/ebdc7053cc40399259f10cc438b03765 to your computer and use it in GitHub Desktop.
Save alancriaxyz/ebdc7053cc40399259f10cc438b03765 to your computer and use it in GitHub Desktop.
===========================================================================
REDIS
===========================================================================
const client = createClient({
url: process.env.REDIS_URL
});
client.on('error', (err) => console.log('Redis Client Error', err));
await client.connect();
const tagsRepo = await tagsRepository();
await client.flushDb();
// Salva varios registros
for (let i = 0; i < 200000; i++) {
tagsRepo.save({
name: `Tag 2 ${i + 1}`,
slug: `tag-${i}`
});
}
//Conta os registros
tags = await tagsRepo.search().return.count()
//Retorna todos os registros
tags = await tagsRepo.search().return.all()
//Ordena registros
tags = await tagsRepo.search().sortBy('name', 'DESC').return.all()
//Procura um registro pelo nome
tags = await tagsRepo.search()
.where('name').equals("Tag 45343")
.return.all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment