Skip to content

Instantly share code, notes, and snippets.

@dgnsrekt
Last active May 24, 2019 23:35
Show Gist options
  • Save dgnsrekt/a9ee00cd65d4a548e4178657c14ecc81 to your computer and use it in GitHub Desktop.
Save dgnsrekt/a9ee00cd65d4a548e4178657c14ecc81 to your computer and use it in GitHub Desktop.
Download and start a redis server within your python project with nox.
import nox
from pathlib import Path
PROJECT_ROOT_DIRECTORY = Path(__file__).parent
REDIS_DIRECTORY = PROJECT_ROOT_DIRECTORY / "redis-stable"
REDIS_COMPRESSED_FILE_NAME = "redis-stable.tar.gz"
REDIS_DOWNLOAD_URL = "http://download.redis.io/" + REDIS_COMPRESSED_FILE_NAME
REDIS_SERVER_LOCATION = REDIS_DIRECTORY / "src" / "redis-server"
@nox.session(python=False)
def redis(session):
"""
Downloads and runs a redis server. 'nox -- runsever' to spin a redis server
"""
if not REDIS_SERVER_LOCATION.exists():
session.run("wget", "--verbose", "--no-clobber", REDIS_DOWNLOAD_URL, external=True)
session.run("tar", "-xzf", REDIS_COMPRESSED_FILE_NAME, external=True)
session.run("rm", REDIS_COMPRESSED_FILE_NAME, external=True)
session.cd(REDIS_DIRECTORY)
session.run("make", external=True)
assert REDIS_SERVER_LOCATION.exists(), "Something went wrong..."
if session.posargs[0] == "runserver":
session.run(str(REDIS_SERVER_LOCATION))
@dgnsrekt
Copy link
Author

Run the following to spin up a redis server

nox -- runserver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment