Get redis connection optionally from the environment

master
Victor Roest 2019-10-12 13:11:57 +02:00
parent b2d5eac5bf
commit 5e0f733b23
No known key found for this signature in database
GPG Key ID: F69440FC85CD66CD
1 changed files with 10 additions and 7 deletions

View File

@ -1,6 +1,7 @@
import redis
import json
import uuid
import os
import random
import hashids
import asyncio
@ -14,16 +15,18 @@ from .models import *
from starlette.websockets import WebSocket
from starlette.middleware.cors import CORSMiddleware
hashes = hashids.Hashids("a very good salt yes this is nice ok",
4, "ABCDEFGHJKLMNPQRSTUVXYZ23456789")
hashes = hashids.Hashids("a very good salt yes this is nice ok", 4, "ABCDEFGHJKLMNPQRSTUVXYZ23456789")
app = FastAPI(title="Cards against idiots")
r = redis.Redis(host='redis', port=6379, password='yeet')
app.add_middleware(CORSMiddleware, allow_origins=[
'*'], allow_methods=["*"], allow_headers=["*"])
# loop = asyncio.get_event_loop()
# r = aioredis.create_redis("redis://redis", loop=loop)
r = redis.Redis(
host=os.getenv("REDIS_HOST", "redis"),
port=os.getenv("REDIS_PORT", 6379),
password=os.getenv("REDIS_PASS", "yeet")
)
app.add_middleware(CORSMiddleware, allow_origins=['*'], allow_methods=["*"], allow_headers=["*"])
cards = {}
with open("cards.json", encoding="UTF-8") as file: