diff --git a/ch8/cache_aside/cache_aside.py b/ch8/cache_aside/cache_aside.py index 592b616..2affb95 100644 --- a/ch8/cache_aside/cache_aside.py +++ b/ch8/cache_aside/cache_aside.py @@ -1,5 +1,4 @@ import sqlite3 -import sys from pathlib import Path import redis @@ -19,7 +18,7 @@ def get_quote(quote_id: str) -> str: with sqlite3.connect(DB_PATH) as db: cursor = db.cursor() res = cursor.execute( - f"SELECT text FROM quotes WHERE id = {quote_id}" + f"SELECT text FROM quotes WHERE id = {quote_id}" # nosec ).fetchone() if not res: return "There was no quote stored matching that id!" @@ -31,13 +30,15 @@ def get_quote(quote_id: str) -> str: # Add to the cache key = f"{CACHE_KEY_PREFIX}.{quote_id}" - cache.set(key, quote, ex=60) + cache.set(key, quote, ex=60) # type: ignore out.append(f"Added TO CACHE, with key '{key}'") else: out.append(f"Got '{quote}' FROM CACHE") if out: return " - ".join(out) + else: + return "" def main(): diff --git a/ch8/cache_aside/populate_db.py b/ch8/cache_aside/populate_db.py index 7afa331..d4307d8 100644 --- a/ch8/cache_aside/populate_db.py +++ b/ch8/cache_aside/populate_db.py @@ -1,8 +1,7 @@ -# pip install redis -# pip install faker +# pip3 install redis +# pip3 install faker import sqlite3 -import sys from pathlib import Path from random import randint @@ -38,7 +37,7 @@ def add_quotes(quotes_list): cursor = db.cursor() for quote_text in quotes_list: - quote_id = randint(1, 100) + quote_id = randint(1, 100) # nosec quote = (quote_id, quote_text) cursor.execute(