From 2864a68fdf6fa884fee8771cde4b16eec9e30f4e Mon Sep 17 00:00:00 2001 From: nonjosh Date: Wed, 15 May 2024 13:00:28 +0000 Subject: [PATCH 1/2] update deprecated code The api is not longer working, so just retrive all to avoid getting empty list --- .gitignore | 2 ++ Dockerfile | 21 +++++++++++++-------- app/main.py | 3 ++- docker-compose.yaml | 9 +++++++++ requirements.txt | 13 +++++++++++++ test_redis_ts.py | 23 +++++++++++++++++++++++ 6 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 requirements.txt create mode 100644 test_redis_ts.py diff --git a/.gitignore b/.gitignore index 2208f4c..8d4b78a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +data/ + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/Dockerfile b/Dockerfile index ef85270..31f18c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,15 +2,20 @@ FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8 WORKDIR /app -# Install Poetry -RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | POETRY_HOME=/opt/poetry python && \ - cd /usr/local/bin && \ - ln -s /opt/poetry/bin/poetry && \ - poetry config virtualenvs.create false +# # Install Poetry +# RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | POETRY_HOME=/opt/poetry python && \ +# cd /usr/local/bin && \ +# ln -s /opt/poetry/bin/poetry && \ +# poetry config virtualenvs.create false -# Copy poetry.lock* in case it doesn't exist in the repo -COPY ./pyproject.toml ./poetry.lock* /app/ +# # Copy poetry.lock* in case it doesn't exist in the repo +# COPY ./pyproject.toml ./poetry.lock* /app/ -RUN bash -c "poetry install --no-root" +# RUN bash -c "poetry install --no-root" + +COPY requirements.txt ./ + +# Install any needed packages specified in requirements.txt +RUN pip install --no-cache-dir -r requirements.txt COPY ./app /app diff --git a/app/main.py b/app/main.py index f8eb7c2..1436627 100644 --- a/app/main.py +++ b/app/main.py @@ -114,7 +114,8 @@ async def persist(keys: Keys, data: BitcoinSentiments): async def get_hourly_average(ts_key: str, top_of_the_hour: int): response = await redis.execute_command( - 'TS.RANGE', ts_key, top_of_the_hour, '+', + # 'TS.RANGE', ts_key, top_of_the_hour, '+', + 'TS.RANGE', ts_key, '-', '+', # The api is not longer working, so just retrive all to avoid getting empty list 'AGGREGATION', 'avg', HOURLY_BUCKET, ) # Returns a list of the structure [timestamp, average]. diff --git a/docker-compose.yaml b/docker-compose.yaml index 90110f5..2e8a389 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -26,3 +26,12 @@ services: depends_on: - redis entrypoint: "pytest -s" + + redis-commander: + image: rediscommander/redis-commander:latest + environment: + - REDIS_HOSTS=local:redis:6379 + ports: + - "8081:8081" + depends_on: + - redis diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4580564 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,13 @@ +fastapi==0.61.0 +uvicorn==0.14.0 +requests==2.24.0 +asgi-lifespan==1.0.1 +python-dateutil==2.8.1 +httpx==0.18.2 +aioredis==2.0.0 +pytest +tox +pytest-cov +pytest-asyncio +ipdb +yapf diff --git a/test_redis_ts.py b/test_redis_ts.py new file mode 100644 index 0000000..b606458 --- /dev/null +++ b/test_redis_ts.py @@ -0,0 +1,23 @@ +import redis +import time + +# Connect to Redis +r = redis.Redis(host='192.168.50.101', port=16379, db=0) + +# # Check if the time series already exists +# if not r.exists('myts'): +# # Create a new time series +# r.execute_command('TS.CREATE', 'myts') + +# # Add multiple data points to the time series +# for i in range(10): +# timestamp = int(time.time() * 1000) # current time in milliseconds +# r.execute_command('TS.ADD', 'myts', timestamp, 50 + i) +# time.sleep(1) # wait for 1 second before adding the next data point + +# # Retrieve all data points we just added +# result = r.execute_command('TS.RANGE', 'myts', '-', '+') + +result = r.execute_command('TS.RANGE', 'is-bitcoin-lit:sentiment:mean:30s', '-', '+') + +print(result) From 58245eead516fee717f918e0a7ec0e682447f021 Mon Sep 17 00:00:00 2001 From: nonjosh Date: Wed, 15 May 2024 13:38:30 +0000 Subject: [PATCH 2/2] update test_redis_ts.py --- test_redis_ts.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test_redis_ts.py b/test_redis_ts.py index b606458..c44daa2 100644 --- a/test_redis_ts.py +++ b/test_redis_ts.py @@ -2,22 +2,22 @@ import time # Connect to Redis -r = redis.Redis(host='192.168.50.101', port=16379, db=0) +r = redis.Redis(host='192.168.50.101', port=6379, db=0) -# # Check if the time series already exists -# if not r.exists('myts'): -# # Create a new time series -# r.execute_command('TS.CREATE', 'myts') +# Check if the time series already exists +if not r.exists('myts'): + # Create a new time series + r.execute_command('TS.CREATE', 'myts') -# # Add multiple data points to the time series -# for i in range(10): -# timestamp = int(time.time() * 1000) # current time in milliseconds -# r.execute_command('TS.ADD', 'myts', timestamp, 50 + i) -# time.sleep(1) # wait for 1 second before adding the next data point +# Add multiple data points to the time series +for i in range(10): + timestamp = int(time.time() * 1000) # current time in milliseconds + r.execute_command('TS.ADD', 'myts', timestamp, 50 + i) + time.sleep(1) # wait for 1 second before adding the next data point -# # Retrieve all data points we just added -# result = r.execute_command('TS.RANGE', 'myts', '-', '+') +# Retrieve all data points we just added +result = r.execute_command('TS.RANGE', 'myts', '-', '+') -result = r.execute_command('TS.RANGE', 'is-bitcoin-lit:sentiment:mean:30s', '-', '+') +# result = r.execute_command('TS.RANGE', 'is-bitcoin-lit:sentiment:mean:30s', '-', '+') print(result)