Skip to content

Instantly share code, notes, and snippets.

Last active Aug 29, 2015
What would you like to do?
a simple keystore system in Python. Multiple values can be stored in a single key, and are retrieved based on time of creation.
import time
class keyStore:
def __init__(self): = {}
def put(self, key, value):
# create array if it doesn't exist
if key not in[key] = []
# store value with current time[key].append(value, time.time())
def get(self, key, timestamp = None):
# check if key has ever been stored
if key not in
return None
# get newest value if no timestamp specified
if(timestamp == None):
timestamp = time.time()
# loop through key's array backwards
for item in reversed([key]):
# if item is newer or equal to specified timestamp, return value
if(item[1] <= timestamp):
return item[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment