Last active
January 28, 2016 19:45
-
-
Save gomezgoiri/aafeece829d96fbb13ac to your computer and use it in GitHub Desktop.
Listing current sessions in PTAnywhere-api
This file contains 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import redis | |
import operator | |
from tabulate import tabulate | |
def sort_table(table, col=0): | |
return sorted(table, key=operator.itemgetter(col)) | |
r = redis.StrictRedis(db=0) | |
count = 0 | |
table = [] | |
for skey in r.keys('session:*'): | |
session_id = skey.split(':')[1] | |
session = r.hgetall(skey) | |
ttl = r.ttl(skey) | |
table.append([session_id, session['url'], ttl]) | |
count += 1 | |
# Show sessions ordered by Time To live | |
print '\nOpened sessions: %d.\n' % count | |
print tabulate(sort_table(table, 2), headers=['Session', 'Allocation URL', 'TTL']) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment