Page MenuHomePhabricator
Paste P11211

Prune stale Echo keys from Redis main stash
ActivePublic

Authored by Krinkle on May 16 2020, 4:48 PM.
Tags
None
Referenced Files
F31822824: raw.txt
May 16 2020, 10:57 PM
F31822821: raw.txt
May 16 2020, 10:56 PM
F31822819: raw.txt
May 16 2020, 10:55 PM
F31822097: raw.txt
May 16 2020, 4:48 PM
Subscribers
None
from __future__ import print_function
import os
import time
import redis
red = redis.StrictRedis(password=os.environ['AUTH'])
query_key_pattern = '*:echo:seen:*'
cond_key = ':echo:seen:'
cond_ttl = -1
# cond_value = 's:14:"19700101000001";'
checked = 0
printed = 0
deleted = 0
for key in red.scan_iter(match=query_key_pattern, count=1000):
if not cond_key in key:
# sanity
print('F', end='')
continue
checked += 1
if checked > 1000:
# idle for 100ms
time.sleep(0.100)
checked = 0
if red.ttl(key) == cond_ttl:
red.delete(key)
deleted += 1
printed += 1
if (printed > 80):
print('.. deleted ' + str(deleted) + ' sofar')
printed = 0

Event Timeline

Krinkle edited the content of this paste. (Show Details)
Krinkle changed the visibility from "Custom Policy" to "Public (No Login Required)".
Krinkle removed a project: WMF-NDA.
Krinkle edited the content of this paste. (Show Details)