redis
Redis
설치
conda install redis conda install redis-py
서버 실행
redis-server
클라이언트 실행
redis-cli
예제
import os import shlex import subprocess import time from pathlib import Path from IPython import embed import psutil import redis def start_redis(port=6379, password='1234'): cmd = [ f'redis-server', f'--port {port}', f'--requirepass {password}', # f'--maxmemory 100mb, # f'allkeys-lru', # f'volatile-lru', ] cmd = ' '.join(cmd) server = subprocess.Popen(shlex.split(cmd)) return server def kill_processes(): parent = psutil.Process(os.getpid()) for child in parent.children(recursive=True): child.kill() parent.kill() if __name__ == '__main__': port = 6379 password = '1234' server = start_redis(port, password) c = redis.Redis(port=port, password=password) c.set(1, 1) print(c.get(1)) c.save() # disk에 저장(동기) # c.bgsave() # disk에 저장(비동기) server.terminate() kill_processes()
튜토리얼
대안
redis.txt · 마지막으로 수정됨: 2024/04/16 02:23 저자 rex8312