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 redis
import json import json
import uuid import uuid
import os
import random import random
import hashids import hashids
import asyncio import asyncio
@ -14,16 +15,18 @@ from .models import *
from starlette.websockets import WebSocket from starlette.websockets import WebSocket
from starlette.middleware.cors import CORSMiddleware from starlette.middleware.cors import CORSMiddleware
hashes = hashids.Hashids("a very good salt yes this is nice ok", hashes = hashids.Hashids("a very good salt yes this is nice ok", 4, "ABCDEFGHJKLMNPQRSTUVXYZ23456789")
4, "ABCDEFGHJKLMNPQRSTUVXYZ23456789")
app = FastAPI(title="Cards against idiots") 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 = redis.Redis(
# r = aioredis.create_redis("redis://redis", loop=loop) 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 = {} cards = {}
with open("cards.json", encoding="UTF-8") as file: with open("cards.json", encoding="UTF-8") as file: