####安装Redis
wget http://download.redis.io/releases/redis-4.0.9.tar.gz
tar -xzf redis-4.0.9.tar.gz
cd redis-4.0.9
make
添加环境变量
PATH=/home/redis-4.0.9/src:$PATH
export PATH
配置后台运行
vi redis.conf
# 后台运行
daemonize yes
# 禁用保护模式
protected-mode no
# 开启aof持久化
appendonly yes
# 禁用绑定
bind 127.0.0.1
启动服务
redis-server redis.conf
重启
redis-cli -h 127.0.0.1 -p 6379 shutdown
#或者
ps -ef|grep redis
kill -9
测试
redis-cli -v
####配置Nginx代理
vi conf/nginx.conf
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
# redis 链接池
upstream redis_pool {
server 127.0.0.1:6379;
keepalive 1024;
}
server {
listen 80;
location =/redis {
internal; #仅限能内部访问
redis2_query get $arg_key;
redis2_pass redis_pool;
}
location =/lua_redis {
content_by_lua '
local parser = require("redis.parser")
local res = ngx.location.capture("/redis", {
args = { key = ngx.var.arg_key }
})
if res.status == 200 then
reply = parser.parse_reply(res.body)
ngx.say(reply)
end
';
}
}
}
以前写的,已经不知道现在还好不好使了