Created
February 1, 2018 21:50
-
-
Save itdaniher/5052ee16605d50802b4174261c6e1440 to your computer and use it in GitHub Desktop.
spawn a memcached-like redis instance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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