Skip to content

Commit 7e26d07

Browse files
author
Andrii Soldatenko
committed
refactor using redis pipelines
1 parent 8698510 commit 7e26d07

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/sentry/dynamic_sampling/tasks.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,17 @@ def adjust_sample_rates(
8484
ds_projects = model.adjust_sample_rates()
8585

8686
redis_client = get_redis_client_for_ds()
87-
for ds_project in ds_projects:
88-
# hash, key, value
89-
cache_key = _generate_cache_key(org_id=org_id)
90-
redis_client.hset(
91-
cache_key,
92-
ds_project.id,
93-
ds_project.new_sample_rate, # redis stores is as string
94-
)
95-
redis_client.pexpire(cache_key, CACHE_KEY_TTL)
96-
schedule_invalidate_project_config(
97-
project_id=ds_project.id, trigger="dynamic_sampling_prioritise_project_bias"
98-
)
87+
with redis_client.pipeline(transaction=False) as pipeline:
88+
for ds_project in ds_projects:
89+
# hash, key, value
90+
cache_key = _generate_cache_key(org_id=org_id)
91+
pipeline.hset(
92+
cache_key,
93+
ds_project.id,
94+
ds_project.new_sample_rate, # redis stores is as string
95+
)
96+
pipeline.pexpire(cache_key, CACHE_KEY_TTL)
97+
schedule_invalidate_project_config(
98+
project_id=ds_project.id, trigger="dynamic_sampling_prioritise_project_bias"
99+
)
100+
pipeline.execute()

0 commit comments

Comments
 (0)