0

I'm using redis-lua module. How can I connect to an in-transit enabled redis server in my lua script? I'm using AWS elastic cache, I've enabled in-transit encryption.

Lua script which I'm using to connect with a redis instance without in-transit encryption enabled is given below,

local redis = require 'redis'
local client = redis.connect('127.0.0.1', 6379)
local response = client:ping()

From my another node.js script, I've found a solution to connect to an in-transit encryption enabled instance from, Securing Node Redis

The code which I've tried is given below. and is working fine not reliable, but, Is there any module available out there, or any reliable solution.

local ssl = require "ssl"
local socket = require "socket"
local params = {
    mode = "client",
    protocol = "tlsv1",
    verify = "none",
    options = "all",
}
local tcp_socket = socket.tcp()
tcp_socket:connect("xxxxxxxxxx", "6379")
local conn  = ssl.wrap(tcp_socket, params)
conn:dohandshake()
conn:send("AUTH testing\n\n")
conn:send("SET test tcp\n\n")
local line, err = conn:receive()
print(err or line)
conn:close()

Cheers

1 Answers1

0

redis-lua module supports multiple way of giving the connection parameters. One of the way is to provide the created socket in the table like,

{
    socket = <socket>
}

To connect to an in-transit encryption enabled redis elastic cache,

local ssl = require "ssl"
local socket = require "socket"
local redis = require "redis"
local config = {
    host = "xxxxxxxxxxxxxx",
    port = "6379",
    password = "XXXXXXXXXXXXXXX"
}
local params = {
    mode = "client",
    protocol = "tlsv1",
    verify = "none",
    options = "all",
}
local tcp_socket = socket.tcp()
tcp_socket:connect(config.host, config.port)
local conn  = ssl.wrap(tcp_socket, params)
conn:dohandshake()
local client = redis.connect({
    socket = conn
})
client:auth(config.password)
print(client:ping())