Created
November 20, 2014 04:57
-
-
Save codebynumbers/8ce37ac503833d3d426e to your computer and use it in GitHub Desktop.
hulk.py
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
| """ 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