Diogo Luiz
Diogo Luiz

Reputation: 48

Find namespace records in Redis

How do I find all the records in Redis?

USER_EXCHANGE = table

USER_ID = User ID (primary key)

UID = relationship

The key is stored with the following structure

USER_EXCHANGE:USER_ID:4030:UID:63867a4c6948e9405f4dd73bd9eaf8782b7a6667063dbd85014bd02046f6cc2e

I am trying to find all the records of the user 4030...

using (var redisClient = new RedisClient ())
{
    List<object> ALL_UID = redisClient.Get<List<object>>("USER_EXCHANGE:USER_ID:4030:UID:*");
}

What am I doing wrong? Thank you all for your help.

Upvotes: 2

Views: 3936

Answers (1)

jeorfevre
jeorfevre

Reputation: 2316

Hi as you're trying to fetch all keys matching a pattern you should use KEYS. GET won't match patterns. by will retrieve complete full names.

Caution this is a debug function and not a production function. doc: https://redis.io/commands/keys

Production simple solution, recommanded for you is :

  1. store a list of your key in a LIST USER_EXCHANGE:USER_ID:4030 => [ uid1, uid2, uid3 ....]
  2. get list of uids for a specific user ID by getting the list.

This is a good practice in REDIS.

Upvotes: 1

Related Questions