Skip to content

Instantly share code, notes, and snippets.

@LiraNuna
Created October 12, 2016 18:33
Show Gist options
  • Save LiraNuna/46a56dda867bcbd240422faa7042b0c5 to your computer and use it in GitHub Desktop.
Save LiraNuna/46a56dda867bcbd240422faa7042b0c5 to your computer and use it in GitHub Desktop.
"""
Zstore is designed to be a heavily read, low write storage that is shared
across all instances of Python code that is connected to it. It is updated
via a call to .update(), which is meant to be a slow process.
Usage:
zstore = Zstore(db)
zstore.set('something', 'something')
zstore.get('something')
=> 'something'
Behaviors:
- If you set a key to a value, it will always be that value until you either
update again or set another key to something else (implicit update).
- All gets are direct memory accesses and eventually consistent as long as
updates are called on a regular basis. This can be per request or per
task, as you will.
- Updates are performed asynchronously on a thread via zookeeper watches
"""
import patreon
from patreon.exception.generic_errors import TestEnvironmentOnly
from patreon.services.museum_curator import Museum
from patreon.services.zookeeper import PatreonZookeeperInterface
class ZStore:
def __init__(self):
# self.museum = self._initialize_museum()
# self.museum.start()
pass
def _initialize_museum(self):
pass
# return Museum(PatreonZookeeperInterface(), '/zstore')
def empty(self):
pass
# if not patreon.is_test_environment():
# raise TestEnvironmentOnly
# self.museum.delete_node('/zstore', recursive=True)
# self.museum.stop()
# self.museum = self._initialize_museum()
# self.museum.start()
def set(self, key, value):
pass
# self.museum.set_value('/zstore/{}'.format(key), value)
def get_or_create(self, key, default):
pass
# value = self.get(key)
# if value is not None:
# return value
# self.set(key, default)
# return default
def get(self, key, default=None):
pass
"""Get the cached value of a particular key."""
# return self.museum.get_value('/zstore/{}'.format(key), default)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment