Skip to content

Instantly share code, notes, and snippets.

@codebynumbers
Created November 20, 2014 04:57
Show Gist options
  • Select an option

  • Save codebynumbers/8ce37ac503833d3d426e to your computer and use it in GitHub Desktop.

Select an option

Save codebynumbers/8ce37ac503833d3d426e to your computer and use it in GitHub Desktop.
hulk.py
""" HULK DB - A BIG DUMB DATA STORE
A probably overly simple way to store data to disk
with fast writes and lookups without needing indices in RAM
TODO: RESTful interface (something lightweight cherry-py maybe)
MAYBE: expirations
NEVER: Clustering, complex storage, data-types
"""
from distutils.dir_util import mkpath
datadir = 'data'
def set(key, val):
path = key_to_path(key)
mkpath(path)
with open("{}/{}".format(path,"_"), 'w') as fh:
fh.write(val)
def get(key):
path = key_to_path(key)
with open("{}/{}".format(path,"_")) as fh:
return fh.read()
def key_to_path(key):
return "{}/{}".format(datadir, '/'.join(list(key)))
if __name__ == "__main__":
set("4b2289", "cat")
print get("4b2289")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment