Skip to content

Instantly share code, notes, and snippets.

@itdaniher
Created February 1, 2018 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itdaniher/5052ee16605d50802b4174261c6e1440 to your computer and use it in GitHub Desktop.
Save itdaniher/5052ee16605d50802b4174261c6e1440 to your computer and use it in GitHub Desktop.
spawn a memcached-like redis instance
def start_redis_server(redis_socket_path = "/tmp/redis.sock"):
conf = b"""port 0
databases 1
unixsocket %s
maxmemory 100mb
maxmemory-policy volatile-lru
save ''""" % redis_socket_path.encode()
logging.debug('launching redis with conf: %s' % conf)
redis_process = subprocess.Popen(['redis-server', "-"], stdin = subprocess.PIPE, start_new_session=True)
try:
redis_process.communicate(conf, timeout=1)
except:
pass
def kill_redis():
os.killpg(os.getpgid(redis_process.pid), signal.SIGKILL)
atexit.register(kill_redis)
return redis_process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment