Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6945695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:28:10+00:00 2026-05-27T13:28:10+00:00

Let us suppose I have an app which has articles and authors. It persists

  • 0

Let us suppose I have an app which has articles and authors. It persists its data in a Redis base. The articles are stored as hashes, as the one below represented in JSON syntax:

{ "title" : "My title", "content" : "This is a content", "authorId" : 1}

Also, my authors are represented by hashes:

{ "name": "John Smith", "username" : "jsmith", "password" : "secret", "id" : 1}

The question is, how would you retrieve all articles given an author id? Is there some command in Redis to do it? Would you retrieve and filter them manually? Or is my way of representing this relationship flawed? What would you suggest?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:28:11+00:00Added an answer on May 27, 2026 at 1:28 pm

    In Redis there’s no direct way to retrieve hashes using a field value as a selection criteria. With your current data model only way to it is to retrieve all article hashes and then discarding those that don’t match, but this method is far from efficient.

    The fact is, you’ll have to maintain an index by yourself. As you can’t have sets inside hashes, I’d do this by having separate sets containing IDs of articles of an author. That way, you’ll have hashes of authors:

    author_1: { "name": "John Smith", ... "id": 1 }
    author_2: { "name": "Jane Doe", ... "id": 2 }
    

    And sets for this mapping:

    author_1_articles: [1, 3]
    author_2_articles: [2]
    

    And it maps to these articles:

    article_1: { "title": "My title", ... "authorId": 1 }
    article_2: { "title": "Another one", ... "authorId": 2 }
    article_3: { "title": "What a story", ... "authorId": 3 }
    

    Now, when you want to get articles for an author X, you’ll just get SMEMBERS author_X_articles and you’ll get the list of article IDs.

    I’d use sets, because Redis will just ignore it if you end up adding same article for an author multiple times. So the list of articles you’ll get will never have duplicates, and you can use SADD without first checking if the article is already in the set.

    This might sound like a lot of work, and it will be if your data model is complex and you have a lot of different access patterns you need to make fast. What you’ll end up doing is maintaining your own indexes, and for those you must duplicate data and keep it up to date. That’s the NoSQL tradeoff…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a CMS application written in Node.js which persists data on a
Let's suppose that I have 2 processes in Erlang, and each process has a
Let's suppose I have a Winforms app with a Dictionary that looks like this:
Let's suppose I have the following url: /valid/django/app/path/?foo=bar&spam=eggs I can simulate a request to
Let's suppose I have an applet running within a page in a browser. What
Let us suppose we have a site entirely written on Silverlight. All navigation occurs
Let's suppose I have n arrays, where n is a variable (some number greater
Let's suppose I have xml like this one: <Server Active=No> <Url>http://some.url</Url> </Server> C# class
Let us suppose i have these three methods defined: int F1(int, int); int F1(float,
Suppose I have some code: let listB = [ 1; 2; 3 ] Using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.