thibaultcha / lua-cassandra

Pure Lua driver for Apache Cassandra
https://thibaultcha.github.io/lua-cassandra
Other
98 stars 35 forks source link

resty/cassandra/cluster.lua:117: attempt to index local 'self' (a nil value) #89

Closed georgecao closed 7 years ago

georgecao commented 7 years ago

my_module.lua

local Cluster = require "resty.cassandra.cluster"
local dc_rr = require "resty.cassandra.policies.lb.dc_rr"

local cluster
local _M = {}
function _M.init()
    local policy = dc_rr.new("local_dc")
    cluster = Cluster.new({
        shm = 'cassandra', -- defined by the lua_shared_dict directive
        contact_points = { '10.10.10.10' },
        keyspace = 'my_keyspace',
        lb_policy = policy
    })

    assert(cluster.refresh())
end

function _M.execute(...)
    return cluster:execute(...)
end

return _M`

In the HTTP context, init_by_lua_file lua/init.lua;

init.lua

local cc = require 'my_module'
cc.init()

Then execute sbin/nginx -t shows the error:

nginx: [error] init_by_lua_file error: resty/cassandra/cluster.lua:117: attempt to index local 'self' (a nil value)
stack traceback:
    resty/cassandra/cluster.lua:117: in function 'get_peers'
    resty/cassandra/cluster.lua:448: in function 'refresh'

And the nginx version is

sbin/nginx -v
nginx version: openresty/1.9.15.1

Luajit version is luajit-2.1.0-beta2