lua-resty-maghash

实现 Maglev 的一致性哈希算法

$ opm get kwanhur/lua-resty-maghash

lua-resty-maghash

lua-resty-maghash 实现 Google 的负载均衡方案 - Maglev 的一致性哈希算法

概述

        lua_package_path "/path/to/lua-resty-maghash/lib/?.lua;;";
    
        server {
            location /test {
                content_by_lua '
                local cjson = require('cjson.safe')
                local maghash = require('resty.maghash')
                local mag = maghash:new(7)
    
                mag:add_backend('b1')
                mag:add_backend('b2')
                mag:add_backend('b3')
                local lookup = mag:lookup()
                ngx.print(cjson.encode(lookup))
                local entry = mag.entry
                ngx.print(cjson.encode(entry))
                
                mag:remove_backend('b3')
                local lookup = mag:lookup()
                ngx.print(cjson.encode(lookup))
                local entry = mag.entry
                ngx.print(cjson.encode(entry))
                ';
            }
        }

方法

new

语法: mag = maghash:new(m)

创建一个新的 maghash 对象。

add_backend

语法: mag:add_backend(backend)

将后端添加到 mag 后端

remove_backend

语法: mag:remove_backend(backend)

从 mag 后端中移除一个后端

get_backend

语法: backend = mag:get_backend('abc123&^%')

获取指定内容的后端

lookup

语法: lookup = mag:lookup()

获取所有后端

安装

您可以使用 opm 安装它。就像这样:opm install kwanhur/lua-resty-maghash

依赖

作者

kwanhur <huang_hua2012@163.com>, VIPS Inc.

版权和许可

此模块根据 BSD 2-Clause 许可证授权。

版权所有 (C) 2016, by kwanhur <huang_hua2012@163.com>, VIPS Inc.

保留所有权利。

在满足以下条件的情况下,允许以源代码和二进制形式重新分发和使用此软件,无论是否修改。

  • 源代码重新分发必须保留上述版权声明、此条件列表以及以下免责声明。

  • 二进制形式的重新分发必须在附带的文档和/或其他材料中复制上述版权声明、此条件列表以及以下免责声明。

本软件由版权所有者和贡献者“按现状”提供,任何明示或暗示的保证,包括但不限于适销性和特定用途适用性的暗示保证均被排除在外。在任何情况下,版权所有者或贡献者均不对任何直接、间接、意外、特殊、示范性或后果性损害(包括但不限于替代商品或服务的采购;使用、数据或利润损失;或业务中断)负责,无论其原因如何。无论是在合同、严格责任或侵权行为(包括疏忽或其他)的情况下,即使已告知有可能发生此类损害,也与使用本软件有关。

作者

Kwanhur

许可证

2bsd

依赖

luajit

版本