Skip to content

Instantly share code, notes, and snippets.

@gomezgoiri
Last active January 28, 2016 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gomezgoiri/aafeece829d96fbb13ac to your computer and use it in GitHub Desktop.
Save gomezgoiri/aafeece829d96fbb13ac to your computer and use it in GitHub Desktop.
Listing current sessions in PTAnywhere-api
#!/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'])
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment