Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Python Programming Blueprints

You're reading from   Python Programming Blueprints Build nine projects by leveraging powerful frameworks such as Flask, Nameko, and Django

Arrow left icon
Product type Paperback
Published in Feb 2018
Publisher Packt
ISBN-13 9781786468161
Length 456 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
 Riti Riti
Author Profile Icon Riti
Riti
 Furtado Furtado
Author Profile Icon Furtado
Furtado
 Pennington Pennington
Author Profile Icon Pennington
Pennington
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Title Page
Copyright and Credits
Dedication
Contributors
Packt Upsell
Preface
1. Implementing the Weather Application FREE CHAPTER 2. Creating a Remote-Control Application with Spotify 3. Casting Votes on Twitter 4. Exchange Rates and the Currency Conversion Tool 5. Building a Web Messenger with Microservices 6. Extending TempMessenger with a User Authentication Microservice 7. Online Video Game Store with Django 8. Ordering Microservices 9. Notification Serverless Application 1. Other Books You May Enjoy Index

Prepending the email to our messages


One thing that our TempMessenger is missing is accountability. We have no idea which users are posting what, which is fine for an anonymous messaging application (and if that is what you want, then skip this section altogether). To do this, when we store our messages, we will want to also store the email of the user who sent it.

Let's start by revisiting the messages.py dependency. Update save_message in our RedisClient to the following:

def save_message(self, email, message): 
    message_id = uuid4().hex 
    payload = { 
        'email': email, 
        'message': message, 
    } 
    self.redis.hmset(message_id, payload) 
    self.redis.pexpire(message_id, MESSAGE_LIFETIME) 
 
    return message_id 

The first thing you'll notice is that, in order to call save_message, we now require the user's email.

What we have also done here is to change the format of the data we are storing in Redis from a string to a hash. Redis hashes allow us to store dictionary...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Visually different images