Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 44 lines (34 sloc) 1.26 KB
#!/usr/bin/env python
#Copyright (c) 2011 Fabula Solutions. All rights reserved.
#Use of this source code is governed by a BSD-style license that can be
#found in the license.txt file.
# leveldb client
import zmq
import threading
import time
import json
class leveldb(object):
"""leveldb client"""
def __init__(self, host="tcp://", timeout=10*1000): = host
self.timeout = timeout
def connect(self):
self.context = zmq.Context()
self.socket = self.context.socket(zmq.XREQ)
def get(self, key):
self.socket.send_multipart(['get', json.dumps(key)])
return self.socket.recv_multipart()[0]
def put(self, key, value):
self.socket.send_multipart(['put', json.dumps([key, value])])
return self.socket.recv_multipart()[0]
def delete(self, key):
self.socket.send_multipart(['delete', json.dumps(key)])
return self.socket.recv_multipart()[0]
def range(self, start=None, end=None):
self.socket.send_multipart(['range', json.dumps([start, end])])
return self.socket.recv_multipart()[0]
def close(self):