Пример #1
0
class CachedEntity(object):

    def __init__(self):

        self._cache = CacheClient()

    def save(self):

        entity_id = self.get_id()
        data = json.dumps(self.get_attrs())

        if self._cache.set(entity_id, data):
            return entity_id

    def get_attrs(self):

        return dict([(key, value) for key, value in self.__dict__.iteritems() if not key.startswith("_")])

    @staticmethod
    def get(key):

        return json.loads(CacheClient().get(key))

    @staticmethod
    def delete(key):

        return CacheClient().delete(key)

    def get_id(self):

        return self.__hash__()
Пример #2
0
    'proserpine', 'cupid', 'terra', 'somnus', 'ops', 'uranus', 'victoria',
    'aurora', 'faunus', 'luna', 'sol', 'hercules', 'ulysses'
]

ports = [i for i in range(6555, 6563)]
printlock = Lock()
nodes = [
    Node(5,
         clusterNames[i],
         ports[i],
         position=(random.randint(-10, 10), random.randint(-10, 10)),
         lock=printlock) for i in range(len(ports))
]

if __name__ == "__main__":
    c = CacheClient(nodes=[node.port for node in nodes])

    threads = [Thread(target=node.serve, args=()) for node in nodes]
    for thread in threads:
        thread.start()

    time.sleep(2)
    c.getDistances()
    time.sleep(7)
    json = '{"a": 123, "b": 75}'
    c.writeCache('dolphin', json)

    json = "{'a': 1729, 'b': 540}"
    c.writeCache('cow', json)

    json = "{'a': '-1^\\frac{1}{2}', 'b': 'e'}"
Пример #3
0
    def __init__(self):

        self._cache = CacheClient()