Understanding Redis and Its Primitives
Redis is an open-source, in-memory data structure project implementing a distributed, in-memory key-value database with optional durability. It can be used as a database, cache, message broker, and queue. It supports various types of data structures, including Strings, Lists, Sets, Sorted sets, etc.
Common use cases of Redis include caching, real-time analytics, publish/subscribe, job & queue management, and much more.
Redis works with an in-memory dataset to achieve outstanding performance. However, it has built-in persistence mechanisms to store data in the disk for data durability: it involves two methods, RDB (Redis DataBase file) and AOF (Append Only File).
Let's now dive into some Python code to interact with Redis, similar to PostgreSQL, but here, we're dealing with an in-memory key value pair datastore. We're going to connect to a Redis data store, set a key value pair, and get the value of the key. (Please ensure Redis is up and running at port 6379 on localhost in your local system).
In the coming lesson, we will build a primitive version of Redis as part of the 'Build Datastores From Scratch' course. This knowledge forms a crucial foundation for the upcoming lessons and will help us understand how such high-performing technologies operate under the hood and serve industries like finance and AI.
xxxxxxxxxx
if __name__ == "__main__":
# Python logic here
import redis
r = redis.Redis(host='localhost', port=6379, db=0)
r.set('finance', 'AI')
print(r.get('finance'))