In this step-by-step tutorial, you’ll cover how to use both Redis and its Python client library. You’ll learn a bite-sized slice of Redis itself and master the redis-py client library.

In this tutorial, you’ll learn how to use Python with Redis (pronounced RED-iss, or maybe REE-diss or Red-DEES, depending on who you ask), which is a lightning fast in-memory key-value store that can be used for anything from A to Z. Here’s what Seven Databases in Seven Weeks, a popular book on databases, has to say about Redis:

It’s not simply easy to use; it’s a joy. If an API is UX for programmers, then Redis should be in the Museum of Modern Art alongside the Mac Cube.

And when it comes to speed, Redis is hard to beat. Reads are fast, and writes are even faster, handling upwards of 100,000 SET operations per second by some benchmarks.

Intrigued? This tutorial is built for the Python programmer who may have zero to little Redis experience. We’ll tackle two tools at once and introduce both Redis itself as well as one of its Python client libraries, redis-py.

redis-py (which you import as just redis) is one of many Python clients for Redis, but it has the distinction of being billed as “currently the way to go for Python” by the Redis developers themselves. It lets you call Redis commands from Python, and get back familiar Python objects in return.

In this tutorial, you’ll cover:

  • Installing Redis from source and understanding the purpose of the resulting binaries
  • Learning a bite-size slice of Redis itself, including its syntax, protocol, and design
  • Mastering redis-py while also seeing glimpses of how it implements Redis’ protocol
  • Setting up and communicating with an Amazon ElastiCache Redis server instance

Table of Contents

  • Installing Redis From Source
    
  • Configuring Redis
    
  • Ten or So Minutes to Redis
    
  •     Getting Started
    
  •     Redis as a Python Dictionary
    
  •     More Data Types in Python vs Redis
    
  • Using redis-py: Redis in Python
    
  •     First Steps
    
  •     Allowed Key Types
    
  •     Example: PyHats.com
    
  •     Using Key Expiry
    
  •     PyHats.com, Part 2
    
  •     Persistence and Snapshotting
    
  •     Serialization Workarounds
    
  •     Encryption
    
  •     Compression
    
  • Using Hiredis
    
  • Using Enterprise Redis Applications
    
  • Wrapping Up
    
  • Further Reading
    

#redis #python

How to Use Redis With Python
3.40 GEEK