Docs
SupportGet Started
  • Get Started
  • Platform
  • Products
  • Tutorials
  • Enterprise
  • Get Started
  • Frontend
    • Angular
    • React
    • Vue
    • Next.js
    • Svelte
    • Static Sites
      • Static HTML
      • HTML5UP Template
      • Bootstrap
  • Backend
    • Python
      • Python
      • Django
      • Flask
      • Python Discord Bot
      • Python Telegram Bot
      • Polling Python Telegram Bot
      • Whatsapp Bot
    • Node.js
      • Express.js
      • Node.js Discord Bot
      • Node.js Telegram Bot
      • Polling Node Telegram Bot
      • Slack Bot
    • Java
    • Go
    • Docker
      • Caddy Docker Site
      • Docker Laravel App
      • Docker PHP App
      • Flask Docker App
  • Database
    • MySQL
      • Django + MySQL
      • Flask + MySQL
      • Java + MySQL
    • MongoDB
      • Django + MongoDB
      • Express + MongoDB
      • Flask + MongoDB
    • Postgres
    • Redis
  • Full Stack
    • Next.js
      • Next.js + Express.js
      • Next.js + MongoDB
      • Static File Share with Flask and Caddy
    • Flask + HTMX
    • MEAN Stack
    • MERN Stack
  • Peristent Storage
  • WordPress
Powered by GitBook

© Copyright Code Capsules. All rights reserved.

On this page
  • Create a Redis Data Capsule
  • Connecting a Data Capsule to a Backend Capsule
  • Connecting to a Redis Data Capsule from a Python application
  • Connecting to a Redis Data Capsule from a Node.js application

Was this helpful?

Export as PDF
  1. Database

Redis

PreviousPostgresNextFull Stack

Last updated 17 days ago

Was this helpful?

In this tutorial, we’ll create a Redis Data Capsule to provide low-latency, in-memory data storage for your application hosted on Code Capsules.

Create a Redis Data Capsule

Log in to your and navigate to the Space your Redis Capsule will be contained in. Click the yellow + button in the bottom left of the screen, select "New Capsule", then select "Redis" from the dropdown.

Choose a payment option, and click "Create Capsule".

Connecting a Data Capsule to a Backend Capsule

Now we need to connect our Data Capsule to a Backend Capsule using a database connection URL.

Navigate to your Backend Capsule and click on the "Configure" tab. Scroll down to the "Data capsules" section and click "View". Click the + next to the Connection string variable to create a DATABASE_URL environmental variable in your Backend Capsule, which gives access to services and features of your Data Capsule.

We'll use this environment variable in our app to connect to the Redis database.

Connecting to a Redis Data Capsule from a Python application

If your Backend Capsule is a Python application, use the following code to connect to your Redis database:

import os
import redis

redis_url = os.getenv('REDIS_URL')

connection = redis.from_url(redis_url)

# Do something here

Connecting to a Redis Data Capsule from a Node.js application

If your Backend Capsule is a Node.js application, use the following code to connect to your Redis database:

let redis = require('redis');
let redis_url = process.env.REDIS_URL

let connection = redis.createClient({
  url: redis_url
});

connection.connect();

// Do something here 

connection.quit();

If you’d like to deploy another application in a different language or framework, take a look at our other .

deployment guides
Code Capsules account
Create Data Capsule
Redis Url