Page MenuHomePhabricator
Paste P11211

Prune stale Echo keys from Redis main stash
ActivePublic

Authored by Krinkle on Sat, May 16, 4:48 PM.
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 created this paste.Sat, May 16, 4:48 PM
Krinkle edited the content of this paste. (Show Details)Sat, May 16, 10:55 PM
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)