Redis - Beyond Caching #1 (PubSub, EazyHack and Swags)

Redis - Beyond Caching #1 (PubSub, EazyHack and Swags)

After a very successful Elasticsearch Series, I am here to start the next series demanded by my community..! Redis - So much beyond caching...!!

This full series will be covering a lot of interesting topics and would involve many practical use cases of using them..! From basics of Redis, to amazing things made by Redis and using them with Hands On, we will be focusing on everything in this series.

Introducing Eazy Hacks

Starting from this series, most of my blogs would be accompanied with a Hands-On challenge (like homework) known as Eazy Hacks..! A mini challenge series where you would be implementing whatever I write about in my blogs..! That too, only 1 small piece of it, not the whole application..!

Yes! We have prizes for you as well..!

Sweet right? Learning something new, implementing it within minutes or hours and then winning some awesome sweet swags..!! I don't think there is much better motivation for you guys..!

Check out the bottom of this article to find the first challenge, due by 30th June..!

Redis - Caching and Beyond Caching

What is Redis? Redis is an open source, in-memory data store used by millions of developers as a database, cache, streaming engine, and message broker and much more..!

Essentially, it's a Key-Value based database, which gives you many types of data structures implemented within it..! Let's see some of them..!

No alt text provided for this image

As we saw the basic structure "strings" which can be used to add strings as well as integers, let's have a quick look at other types as well quickly, without going into too much detail..!

No alt text provided for this image

Similarly we have Sets and SortedSets which follow somewhat similar commands but behave differently..! Best place to learn about them is the official Redis documentation. Let’s checkout one last before we move on the PubSub - Hashes

These hashes are something similar to JSON or dictionaries, but not totally, and we will talk about them in depth later, but here is a preview of them -?

No alt text provided for this image

Redis PubSub - Publisher Subscriber

Now, once we know the basics of Redis, let’s move on to other use cases of Redis..! Redis has so much in its features that it takes an entire series to talk about it..! Let’s start with PubSub - a feature which is so important and fully known as Publisher Subscriber.

Think of a system where one service needs to broadcast messages to many services (or clients) and does not want to take the load of acknowledgements as well as making sure each service gets the message. Just a plain simple Live Broadcast.

Therefore, there are 3 types of entities involved here -

Publisher

A publisher is a service which emits (or sends) messages to a channel (unique namespace) so that anyone listening to that channel would get that message.

Subscriber

A subscriber is a service which listens (or subscribes) to messages on a particular (or set of) channels. Once a message is received, the subscriber does its computation and then listens to the next message.

Broker

The system in between which handles the routing of each message from publisher to each connected subscriber, is known as a broker. Obviously, this broker is Redis as we are talking about the same, but specifically its Redis’s PubSub feature which does it internally.

Running Redis on your Local System

While there are many ways to install Redis, I personally recommend using the Docker method to start a very simple Redis server. With docker installed and running, it’s just 1 single command -?

Starts a docker instance in background (-d) and binds with port 6379 on your machine.

docker run -d -p 6379:6379 redis

Using Redis PubSub in Python

It’s so simple to start using Redis as well as PubSub in python..! Check the code below for building a simple Publisher in python..!

No alt text provided for this image

Similarly, a simple Subscriber would look like -

No alt text provided for this image

Use Cases of PubSub Systems

Online Group Chatting System

Think about an online group chatting system (without storing chat history, let's say) between multiple machines, where the group is assigned a single channel ID, and each client (or machine) is sending messages and receiving them from each other.

Building a Mini Zoom App

You can check my previous blog here around this.!!

Building Notification Broadcast System

Imagine a small script running on your device which just listens to broadcast messages from your org / company and shows a pop up message somewhere on your screen..! Expand on this and think about various notification systems built in each app / device / website.

Eazy Hack - Redis PubSub Challenge

Finally coming to the good stuff, as promised, I am launching Eazy Hacks - a challenge based mini hack series. Obviously, this time the topic is Redis PubSub, and people who would be submitting the best creative ideas and small implementations using Redis PubSub will win some cool Exclusive Swags from Eazy Develop...! (really unique and awesome)

Don't forget, every hack would have different swag..! Can't win it twice ;)

The first challenge - Eazy Hacks 1.0 - would be live from the point of this blog post to 30th June, 2022, post which submissions would be judged. All the rules, guidelines and submission details are given on Eazy Hacks page..!

Don't forget to mark yourself "attending" on the event page as well..!!
Nikhil Kommuri

Software Development Engineer at Expedia

2 年

This is such a great Insight :)

回复
POOJA JAIN

Storyteller | Linkedin Top Voice 2024 | Senior Data Engineer@ Globant | Linkedin Learning Instructor | 2xGCP & AWS Certified | LICAP'2022

2 年

Insightful share ????

Palakh Khanna

Asia's 100 Women Power Leaders 2023| UN Women 75 Leaders | Founder-Break The Ice| American Express| BW WB 30U30| 2X TEDx | Featured @Times Square, NY| Harvard HPAIR ‘22| UN Millennium Fellow| Josh Talk|50+ talks| Speaker

2 年

Great initiative Shrey Batra!!:)

要查看或添加评论,请登录

Shrey Batra的更多文章

社区洞察

其他会员也浏览了