MangoDB 宣称自己是比 MongoDB 更可靠更快速的版本,而且只有 30 行代码。
下面是来自 MangoDB 首页上的介绍:
MangoDB 是最快的数据库之一,它允许你存放任意类型的数据,没有任何 IO 瓶颈。如果你熟悉 MongoDB,那么你使用 MangoDB 会很顺手,你无需任何操作就可立即映射已有的数据到一个全新的自动 SHARTING 算法。
关键是该软件只有 30 行代码:
from gevent.server import StreamServer
import os
def mangodb(socket, address):
socket.sendall('HELLO\r\n')
client = socket.makefile()
output = open('/dev/null', 'w')
while 1:
line = client.readline()
if not line:
break
cmd_bits = line.split(' ', 1)
cmd = cmd_bits[0]
if cmd == 'BYE':
break
if len(cmd_bits) > 1:
output.write(cmd_bits[1])
if os.environ.get('MANGODB_DURABLE', False):
output.flush()
os.fsync(output.fileno())
client.write('OK' + os.urandom(1024).encode('string-escape') + '\r\n')
client.flush()
if __name__ == '__main__':
server = StreamServer(('0.0.0.0', 27017), mangodb)
print ('Starting MangoDB on port 27017')
server.serve_forever()
Getting Started
Install gevent:
easy_install -U gevent
Run the server:
python server.py
With your MongoDB client, connect to localhost on port 27017.
That's it! You'll enjoy the same reliability as you're used to with MongoDB, but you'll get your responses so fast that you'll never want to go back!
时间:2012-06-27 17:18
来源:oschina
作者:oschina
原文链接