Redis is an in-memory key-value pair database typically classified as a NoSQL database. Redis is commonly used for caching, transient data storage and as a holding area for data during analysis in Python applications.
Redis is easy to install and start using compared to most other persistent backends, but it’s useful to follow a walkthrough if you have never previously used Redis or any NoSQL data store.
- How to Use Redis with Python 3 and redis-py on Ubuntu 16.04 contains detailed steps to install and start using Redis in Python.
- How To Install and Use Redis is a Redis starter guide.
Redis with Python
Redis is easier to use with Python if you have a code library client that bridges from your code to your Redis instace. The following libraries and resources provide more information on handling data in a Redis instance with your Python code.
- Redis-py is a solid Python client to use with Redis.
- Walrus is a higher-level Python wrapper for Redis with some caching, querying and data structure components build into the library.
- Writing Redis in Python with Asyncio shows a detailed example for how to use the new Asyncio standard library in Python 3.4+ for working with Redis.
Redis should be customized out of its default configuration to secure it against unauthorized and unauthenticated users. These resources provide some advice on Reids security and guarding against data breaches.
- Pentesting Redis servers shows that security is important not only on your application but also the databases you’re using as well.
- Redis, just as with any relational or NoSQL database, needs to be secured based on security guidelines. There is also a post where the main author of Redis cracks its security to show the tradeoffs purposely made between ease of use and security in the default settings.
- Is your Redis server safe? is a tool to test that your Redis instances are locked down. The tool is based on the blog post a few things about Redis security.
- For God’s sake, secure your Mongo/Redis/etc! digs into the unfortunate default security settings that come with many NoSQL databases which can be used to compromise your systems. Make sure to not only install your dependencies such as Redis, but automate modifying default settings to lock them down against attackers.
General Redis resources
Once you have configured Redis, become comfortable using it and locked it down against malicious actors, you will want to learn more about operating, scaling and collecting metrics. The following resources should help you get started in those areas.
- Redis-playbook is an Ansible playbook for installing, configuring and securing a Redis instance.
- GitHub wrote a retrospective on moving persistent data out of Redis and into MySQL that is worth a read as you scale up your Redis usage.
- This video on Scaling Redis at Twitter is a detailed look behind the scenes with a massive Redis deployment.
- Real World Redis Tips provides some guidance from Heroku’s engineers from deploying Redis at scale. The tips include setting an explicit idle connection timeout, using a connection pooler and avoiding using
KEYSin favor of
- How to collect Redis metrics shows how to use the Redis CLI client to grab key metrics on latency.
- You should revise your Redis max connections setting is a retrospective from a hard web application failure due to Redis connections maxing out on Heroku, and how to avoid this in your own applications by modifying your