Last active
September 14, 2022 20:40
-
-
Save nelsoncbf/a7b0e7d7a619b0da202a7cccf4cc3f83 to your computer and use it in GitHub Desktop.
set expiration in redis python keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from apiman.redis import db | |
from datetime import timedelta | |
def set_expiration(data): | |
c = 0 | |
for x in data: | |
if 'analytics' in x: | |
db.expire(x, timedelta(minutes=20)) | |
print(f'Implementada expiração em {c} chaves') | |
data = db.keys() | |
keys = { | |
'analytics': 0, | |
'usermanager:ticket': 0, | |
'usermanager:location': 0, | |
'usermanager::valid': 0, | |
'usermanager:blackout': 0, | |
'usermanager:cloudtrax': 0, | |
'redirect': 0, | |
'clientarea': 0, | |
'captive:auth': 0, | |
'captiveportal:user': 0, | |
'captive:campaign': 0, | |
'reply.celery.pidbox': 0, | |
'total': 0 | |
} | |
for x in data: | |
keys['total'] += 1 | |
if 'analytics:' in x: | |
keys['analytics'] += 1 | |
elif 'usermanager' in x: | |
if 'usermanager:ticket' in x: | |
keys['usermanager:ticket'] += 1 | |
elif 'usermanager:location' in x: | |
keys['usermanager:location'] += 1 | |
elif ':valid' in x: | |
keys['usermanager::valid'] += 1 | |
elif 'usermanager:blackout' in x: | |
keys['usermanager:blackout'] += 1 | |
elif 'cloudtrax' in x: | |
keys['usermanager:cloudtrax'] += 1 | |
else: | |
print(x) | |
elif 'redirect' in x: | |
keys['redirect'] += 1 | |
elif 'clientarea' in x: | |
keys['clientarea'] += 1 | |
elif 'captive:auth' in x: | |
keys['captive:auth'] += 1 | |
elif 'captiveportal:user' in x: | |
keys['captiveportal:user'] += 1 | |
elif 'captive:campaign' in x: | |
keys['captive:campaign'] += 1 | |
elif 'reply.celery.pidbox' in x: | |
keys['reply.celery.pidbox'] +=1 | |
else: | |
print(x, len(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment