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

  • Home
  • SEARCH
  • 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 8009013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:19:12+00:00 2026-06-04T18:19:12+00:00

Because of the poor performance with using python dict for huge data, i manage

  • 0

Because of the poor performance with using python dict for huge data, i manage to migrate to redis. So i have the following :

"doc1" =>  ('989', 4.0), ('99', 4.0), ('990', 4.0), ('991', 4.0), ('992', 4.0), ('993', 4.0), ('994', 4.0), ('995', 4.0), ('996', 4.0), ('997', 4.0), ('998', 4.0), ('999', 4.0)

"doc2" =>  ('4', 4.0), ('21', 4.0), ('55', 4.0), ('991', 4.0), ('992', 4.0), ('993', 4.0), ('994', 4.0), ('995', 4.0), ('996', 4.0)

"result" => ('991', 8.0), ('992', 8.0), ('993', 8.0), ('994', 8.0), ('995', 8.0), ('996', 8.0), ('99', 4.0),('4', 4.0), ('21', 4.0), ('55', 4.0)

So as you can see, i want to combine the two redis lists into one by using python in a way that if there are elements in doc1 that exists in doc2 sum their values, if the elements in doc1 doesn’t exist in doc2 add the elements to results. My previous implementation using dict was:

result_array = {k: [db_array.get(k, result_array.get(k))[0],db_array.get(k, dv)[1] + result_array.get(k, dv)[1]] for k in set(db_array) | set(result_array)}

how to keep the structure of the dictionary

As you can see this solution is for:

{'991': [4.0, 's.text'], '21': [4.0, 't.text'], '990': [4.0, 'b.text']}

but redis doesn’t support list in list so i have to find a different solution.

  • 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-06-04T18:19:13+00:00Added an answer on June 4, 2026 at 6:19 pm

    If the values are unique, you could use redis sorted set:

    zadd doc1 4.0 989
    zadd doc1 4.0 991
    
    zadd doc2 4.0 21
    zadd doc2 4.0 991
    
    zinterstore result 2 doc1 doc2
    zrange result 0 -1 withscores
    1) "991"
    2) "8"
    

    This will give you the intersection of the sets (the elements which exists in both sets) with the score a sum of the element’s score in each set.

    To get the elements which exist in doc1 but not doc2 is trickier, since there is no zdiff in redis. Depending on your data (and what scores are for elements present in both sets), you might do this (supposing all scores (what you call “values”) are positive, and scores for mutual elements are the same in both sets):

    zunionstore only_in_doc1 2 doc1 doc2 weights 1 -1
    zremrangebyscore only_in_doc1 -inf 0
    zrange only_in_doc1 0 -1 withscores
    1) "989"
    2) "4"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a simple server - client program with Swing interface using singleton
I have a poor man's replication setup that I can't do anything about. Some
The sad truth about this post is that I have poor regex skills. I
I am creating C# winforms application, which connects to the Database. Because I have
I have built an app using jQuery mobile. Apart of some compatibility issues across
I have a few panels that I slide horizontally using the animate function that
Before the performance people tear my head off: yes, I have done profiling before
I have an existing website developped using ASP.NET MVC 3 and Entity Framework 4
I have been having trouble with the WPF DataGrid and listbox GridView performance when
I have the following MySql query: select t1.* from Table1 t1 inner join Table2

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.