Skip to content

Commit

Permalink
IBHostedCached: no need to do the redis call inside a Lock
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunsi committed Dec 20, 2024
1 parent eaa8c78 commit da84389
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions util/ib_hosted.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def get(self, ep, cached=False, **params):
if not self.locks.get(ep):
self.locks[ep] = Lock()

cached_result = REDIS.get(f"ibh:{ep}")
if cached_result is not None and cached:
return json_loads(cached_result)

# make sure we only ever run one get() per endpoint at the same
# time to avoid doing too many requests.
with self.locks[ep]:
cached_result = REDIS.get(f"ibh:{ep}")
if cached_result is not None and cached:
return json_loads(cached_result)

result = self.ib.get(ep, **params)
# store result into redis database, set it to expire after 60 seconds
REDIS.set(f"ibh:{ep}", result.text, ex=60)
Expand Down

0 comments on commit da84389

Please sign in to comment.