
Redis State Management on Cloud Run: Handling Missing Keys and Silent Failures
Redis HSET always returns a value, even when the key doesn't exist. This led to a subtle bug in our production system: state updates were logging success when they were actually failing silently. This guide covers Redis state management patterns for long-running Cloud Run tasks, including how to detect missing keys, handle socket timeouts, and properly configure VPC networking for Cloud Run + Memorystore. The Problem: Silent Failures We use Redis (Memorystore) to track state for long-running evaluation tasks. Each task updates its progress periodically: # ❌ BAD: This logs success even when the key doesn't exist import redis import logging r = redis . Redis ( host = ' 10.x.x.x ' , port = 6379 ) def update_task_progress ( task_id : str , progress : int ): result = r . hset ( f " task: { task_id } " , " progress " , progress ) if result : logging . info ( f " Updated progress for { task_id } : { progress } % " ) else : logging . warning ( f " Failed to update progress for { task_id } " )
Continue reading on Dev.to Python
Opens in a new tab



