Redis®*: Connecting Python to Redis

This documentation is part of the Using with Python guide. You can view the complete guide here: How to connect Redis with Python.

👋 Welcome to the Stackhero documentation!

Stackhero provides a ready-to-use Redis cloud solution offering numerous advantages, including:

  • Redis Commander web interface included.
  • Unlimited message size and transfers.
  • Updates made easy with just one click.
  • Optimal performance and enhanced security thanks to a private, dedicated infrastructure.

Save time and make your life easier: it only takes 5 minutes to try Stackhero's Redis cloud hosting solution!

Let us explore a straightforward example using default values that should cater to most needs:

import redis

r = redis.from_url(
  'rediss://default:<password>@<XXXXXX>.stackhero-network.com:<PORT_TLS>',
  health_check_interval=10,
  socket_connect_timeout=5,
  retry_on_timeout=True,
  socket_keepalive=True
)

To enhance security, consider using environment variables for your credentials. Here is how you can do it:

import os
import redis

r = redis.from_url(
  os.environ.get("STACKHERO_REDIS_URL_TLS"),
  health_check_interval=10,
  socket_connect_timeout=5,
  retry_on_timeout=True,
  socket_keepalive=True
)

Ensure your environment variables include a definition like: STACKHERO_REDIS_URL_TLS=rediss://default:<password>@<XXXXXX>.stackhero-network.com:<PORT_TLS>