lua连接redis
local redis = require "redis"
local host = "you—host"
local port = 6379
local password = "password"
local client = redis.connect(host, port)
local authResult = client:auth(password)
if not authResult then
print("Failed to authenticate with Redis.")
os.exit(1)
end
if not client:ping() then
print("Failed to connect to Redis.")
os.exit(1)
end
print("Connected to Redis.")
client:set("my_key", "Hello, Redis!")
local value = client:get("my_key")
print("Value for 'my_key':", value)
client:quit()