Last active
April 1, 2020 21:23
-
-
Save mpenick/5d453eaea102885f1b71d66e254b34f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local Cluster = require 'resty.cassandra.cluster' | |
local Auth = require 'cassandra.auth' | |
local Socket = require 'cassandra.socket' | |
Socket.force_luasocket("timer", true) | |
-- For performance reasons, the cluster variable | |
-- should live in an upvalue at the main chunk level of your | |
-- modules to avoid creating it on every request. | |
-- see the 'intro' example in the online documentation. | |
-- | |
local auth = Auth.plain_text("test", "test123") | |
local cluster, err = Cluster.new { | |
shm = 'cassandra', -- defined by the lua_shared_dict directive | |
contact_points = {'081daf93-69b5-467b-8763-43a72b09bab5-us-east1.db.astra-dev.datastax.com'}, -- 1) Use cloud host | |
use_proxy = true, -- 2) Set use_proxy to true (ignore system.peers) | |
default_port = 32087, -- 3) Use round-robin port from ./secure-connect-test/cqlshrc | |
ssl = true, | |
verify = true, | |
cert = "./secure-connect-test/cert", | |
key = "./secure-connect-test/key", | |
cafile = "./secure-connect-test/ca.crt", | |
auth = auth, | |
keyspace = 'system', | |
} | |
if not cluster then | |
ngx.log(ngx.ERR, 'could not create cluster: ', err) | |
return ngx.exit(500) | |
end | |
local rows, err = cluster:execute "SELECT * FROM peers" | |
if not rows then | |
ngx.log(ngx.ERR, 'could not retrieve peers: ', err) | |
return ngx.exit(500) | |
end | |
ngx.say('peers: ', #rows) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment