LoginSignup
3
3

More than 5 years have passed since last update.

LuaとNginxとRedisについて

Posted at

NginxでLuaを使う

LuaJITのインストール

本体インストール

こんな感じ。

wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz
tar vxzf LuaJIT-2.0.2.tar.gz
cd LuaJIT-2.0.2
make;sudo make install;

LuaRocksインストール

cpanmみたいな感じの物。

sudo apt-get install zip
cd /usr/local/src
wget https://nodeload.github.com/keplerproject/luarocks/zip/master
mv master master.zip
cd luarocks-master
# 適当に環境変数は設定する
./configure --with-lua=/usr/local/bin/luajit --with-lua-lib=/usr/local/lib/ --with-lua-include=/usr/local/include/luajit-2.0
make
sudo make install
# LuaRocks内のShebangが正しくLuaJITを参照しないので置換する
sudo perl -pi -e 's|/usr/local/bin/luajit/bin/lua|/usr/local/bin/luajit|' /usr/local/bin/luarocks

Nginxのインストール

モジュールを落としてきて関連づけさせてインストールする。

git clone https://github.com/chaoslawful/lua-nginx-module.git
# 適当に環境変数でLuaJITの位置を指定してあげる
# 適当なNginxのソースに対してconfigureを実行する
# UbuntuだとZlibとかPCREが要求されるので適当に入れておくなり、指定するなり…
LUAJIT_INC=/usr/local/include/luajit-2.0 LUAJIT_LIB=/usr/local/lib/ ./configure --add-module=/usr/local/src/lua-nginx-module
make; sudo make install 

LuaからRedisを使うにあたって

インストール

Redisはインストールされているとします。
LuaRedisのモジュールを使用する。
LuaRocksは入っているのでインストール出来る。

# 適宜sudoする必要があるかも
luarocks install redis-lua

確認する

LuaJITのreplから入ってる事の確認をする。

r=require("redis");
c=r.connect("localhost" , 6379);
c:set("hoge" , 1);
print(c:get("hoge"));
-- 1
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3