Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between python native data structure "DICTIONARY" and "Redis" database?

So far in my all test cases it seems I could have also used python dictionary in place of redis.So I am not able to convince my self why Redis ? Note: I am new to Redis so please forgive me for such a naive question.

like image 744
pyAddict Avatar asked Dec 27 '17 07:12

pyAddict


1 Answers

No need to ask for forgiveness for asking a question! :) In fact, I just fielded a similar question from a colleague a couple of weeks ago.

Redis objects are very similar to familiar data structures that you're likely to see in lots of other programming languages. Redis hashes are fairly analogous to Python dictionaries, Redis sets are analogous to Python sets, Redis strings are analogous to a Python string, etc. That much is true. But what if instead of a dictionary containing 10 elements, you had to manipulate a dictionary containing 1,000 elements. Or what if you had to store hundreds of dictionaries each containing dozens of keys? What if you have to store an unknown quantity of information (for instance, you want users to be able to sign-up for your service and create profiles)? Redis is a data storage engine (like MySQL, MongoDB, etc.) first and foremost. It just so happens that it also provides you with multiple ways of structuring data that are very similar to how you would structure your data in your application code, so it's really quite simple to implement certain patterns with your data in Redis that you would likely be familiar with as an application developer. Does that make sense?

I'm also of the mindset that "data" should always be stored separately from application logic, but I think that's probably a separate conversation to be had regarding philosophy as opposed to practicality. ;)

like image 50
Michael McTiernan Avatar answered Oct 05 '22 22:10

Michael McTiernan