Lua腳本中的一個NoSQL數據庫:Tarantool

jopen 10年前發布 | 19K 次閱讀 Tarantool NoSQL數據庫

介紹

Tarantool是一個NoSQL數據庫,運行在Lua編程語言中。 它利用了Node.JS強大的網絡編程功能,數據存儲利用了Redis持久化功能。

特性

  • a drop-in replacement for Lua 5.1, based on LuaJIT 2.0; simply use #!/usr/bin/tarantool instead of #!/usr/bin/lua in your script,
  • Lua packages for non-blocking I/O, fibers and HTTP,
  • MsgPack data format and MsgPack based client-server protocol,
  • two data engines: 100% in-memory with optional persistence and a 2-level disk-based B-tree, to use with large data sets,
  • secondary key and index iterators support,
  • asynchronous master-master replication,
  • authentication and access control.

示例代碼:

#!/usr/bin/env tarantool

box.cfg{}
hosts = box.space.hosts
if not hosts then
    hosts = box.schema.create_space('hosts')
    hosts:create_index('primary', { parts = {1, 'STR'} })
end

local function handler(self)
    local host = self.req.peer.host
    local response = {
        host = host;
        counter = hosts:inc(host);
    }
    self:render({ json = response })
end

httpd = require('http.server')
server = httpd.new('127.0.0.1', 8080)
server:route({ path = '/' }, handler)
server:start()

    項目主頁:http://www.baiduhome.net/lib/view/home/1406259221585

     本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
     轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
     本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!