mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 21:43:21 +00:00
flush-memcached: Use pylibmc.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
committed by
Tim Abbott
parent
1ce15fba9c
commit
699626f3cf
@@ -1,26 +1,15 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import socket
|
|
||||||
import sys
|
import sys
|
||||||
from urllib.parse import urlsplit
|
|
||||||
|
|
||||||
BASE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../..")
|
BASE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../..")
|
||||||
sys.path.append(BASE_DIR)
|
sys.path.append(BASE_DIR)
|
||||||
|
|
||||||
import scripts.lib.setup_path_on_import
|
import scripts.lib.setup_path_on_import
|
||||||
from zproject import settings
|
from zproject import settings
|
||||||
|
import pylibmc
|
||||||
|
|
||||||
url = urlsplit("//" + settings.MEMCACHED_LOCATION)
|
pylibmc.Client(
|
||||||
assert url.port is not None
|
[settings.MEMCACHED_LOCATION], behaviors=settings.CACHES["default"]["OPTIONS"]
|
||||||
|
).flush_all()
|
||||||
print("Flushing memcached...")
|
|
||||||
with socket.create_connection((url.hostname, url.port)) as f:
|
|
||||||
f.sendall(b"flush_all\r\n")
|
|
||||||
response = b""
|
|
||||||
while b"\n" not in response:
|
|
||||||
response += f.recv(4096)
|
|
||||||
if response != b"OK\r\n":
|
|
||||||
print(response, file=sys.stderr)
|
|
||||||
print("Failed to flush memcached", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user