Category : redis

im developing a rates service that retrieves rates from cache (Django, Redis), which has its own container. class CachedTraderRepository: def get_rate(self, pair): print("GET RATE START") print(pair) pair_rate = cache.get(pair) print(pair_rate) print("GET RATE END") return pair_rate def get_all_rates(self): print("GET ALL RATES START") all_rates = cache.get("all_pairs") print(all_rates) print("GET ALL RATES END") return all_rates I have a script ..

Read more

I want to use multiple threads by ThreadPoolExecutor to consume redis queue. But my progress ends unexpected as the queue is still not empty. Below are my main codes: from concurrent.futures import ThreadPoolExecutor import redis from redis import Redis pool = redis.ConnectionPool( max_connections=settings.REDIS_POOL_MAX_CLIENT, host=settings.REDIS_HOST, port=settings.REDIS_PORT, db=8, decode_responses=True ) redis_con = Redis(connection_pool=pool) class BasicTask(object): def __init__(self, ..

Read more

Using sqlalchemy and Postgres. Want to utilize redis for cache. Say we use the following function to attempt to read from redis first, if it doesn’t exist, read from db. def get_user(id) -> User: key = f'{USER_REDIS_PREFIX}{id}’ res = redis_conn.get(key) if res: user_dict = json.loads(res, object_hook=datetime_hook) return User(**user_dict) else: # read from postgres return user ..

Read more

i have a question how i can store a input in flask into redis. I want to store a name that the user write at the page into redis from flask import Flask, render_template, url_for, redirect, request, session from datetime import timedelta import redis app = Flask(__name__) app.secret_key = "key" app.permanent_session_lifetime = timedelta(days=100) @app.route(‘/’) def ..

Read more

We are facing [Errno 54] Connection reset by peer at very random in our application and looks like it is being triggered by redis server than client. Python’s redis client have backoff strategy implementation but it’s unable to handle this scenario. There are github issues on official repo as well and many people commented recently ..

Read more

I am having a flask app which is doing inference on a ml model and I added celery and redis as message broker to do queue based predictions from celery import Celery app.config.update( CELERY_BROKER_URL=’redis://localhost:6379/0′, CELERY_RESULT_BACKEND=’redis://localhost:6379/0′ ) def make_celery(app): celery = Celery(app.import_name, broker=app.config[‘CELERY_BROKER_URL’]) celery.conf.update(app.config) TaskBase = celery.Task class ContextTask(TaskBase): abstract = True def __call__(self, *args, **kwargs): ..

Read more