2071 make V=s
2072 cd build_dir/target-x86_64_uClibc-0.9.33.2/root-x86/html
cd package/network/services/zk-audit/mysql
redis 遠程登陸 bind 0.0.0.0 /etc/redis/redis.confi 修改這個配置文件就可遠程登陸上去 nginx
啓動服務端 redis-server 1162 root 27372 S redis-server 0.0.0.0:6379git
啓動客戶端 redis-cli github
經常使用命令 : web
1 顯示全部的鍵值 keys *redis
127.0.0.1:6379> keys * 1) "term_app_info:1" 2) "term_info:18" 3) "term_info:23" 4) "term_info:29" 5) "term_info:11"
2 獲取值的信息sql
127.0.0.1:6379> HGETall term_info:36 1) "timestamp" 2) "1533185362" 3) "mac"
3 準備用lua 鏈接redis 數據庫數據庫
而後從找到了開源的redis lua https://github.com/openresty/lua-resty-redisapp
https://github.com/gitforks/redis-lua
而後又來個了nigx配置
D:\GIT\Q3_mysql\zk_openwrt\wac\nginx.conf
location /demo {
default_type text/html;
content_by_lua '
ngx.say("<p>hello, nginx</p>")';
}
經過web能夠訪問 http://192.168.1.1:8080/demo
頁面看到 hello, nginx (ngx.say 說在頁面上的 )
文件路徑很重要 /etc/nginx/nginx.conf
新加一個server的配置
server { listen 8822; server_name localhost; root /tmp/portal_cache/; location /test { content_by_lua ' local redis = require "luci.lib.redis" local red = redis:new() red:set_timeout(1000) -- 1 sec -- or connect to a unix domain socket file listened -- by a redis server: -- local ok, err = red:connect("unix:/path/to/redis.sock") local ok, err = red:connect("127.0.0.1", 6379) if not ok then ngx.say("failed to connect: ", err) return end ok, err = red:set("dog", "an animal") if not ok then ngx.say("failed to set dog: ", err) return end ngx.say("set result: ", ok) local res, err = red:get("dog") if not res then ngx.say("failed to get dog: ", err) return end if res == ngx.null then ngx.say("dog not found.") return end ngx.say("dog: ", res) red:init_pipeline() red:set("cat", "Marry") red:set("horse", "Bob") red:get("cat") red:get("horse") local results, err = red:commit_pipeline() if not results then ngx.say("failed to commit the pipelined requests: ", err) return end for i, res in ipairs(results) do if type(res) == "table" then if res[1] == false then ngx.say("failed to run command ", i, ": ", res[2]) else -- process the table value end else -- process the scalar value end end -- put it into the connection pool of size 100, -- with 10 seconds max idle time local ok, err = red:set_keepalive(10000, 100) if not ok then ngx.say("failed to set keepalive: ", err) return end -- or just close the connection right away: -- local ok, err = red:close() -- if not ok then -- ngx.say("failed to close: ", err) -- return -- end '; } }
http://192.168.1.1:8822/test 經過訪問觸發就能夠修改數據庫, 測試有效
/usr/local/openresty/nginx/nginx.conf
在個人虛擬機裏面執行的: openresty -c ~/work/conf/nginx.conf
這個是他的中文網站 : http://openresty.org/cn/components.html
www.xiaohuamao.top:8022 體驗了下openresty
git hub 地址 https://github.com/openresty/openresty 能夠學習下
這裏還有個開源項目 https://gitee.com/alexa/VeryNginx
Redis transactions 事務 因此 Redis 的內部能夠保持簡單且快速
client:select(15) -- for testing purposes 選擇15號數據庫, 默認在0號數據庫, 你在15號數據庫找0號數據庫的東西怎麼找獲得呢?
從redis 裏面讀取數據而後寫入mysql 裏面永久存儲
從redis 裏面讀取數據而後顯示到頁面上 速度快的很嘛
DBSIZE 能夠看到有多少條數據 keys * 可能卡
-- 演示將多條記錄數據組合成一條sql插入語句(for mysql) function getTpl0(tname) -- 獲取表各個字段 local t = { tpl_pack = {"packId","itemId","`group`","num","rate","rateType"}, } for k, v in pairs(t) do if tname == k then return t[k] end end end --tpl = {3813,10,0,2,0,1,1,0,350,5,220,6,0,0,0,0,154,0,0,0,210,80,29} tpl9122 = { -- "packId","itemId","`group`","num","rate","rateType" {9122, 3294, '', 1, 1, 2}, {9122, 3295, '', 1, 1, 2}, {9122, 3296, '', 1, 1, 2}, {9122, 3297, '', 1, 1, 2}, {9122, 3298, '', 1, 1, 2}, {9122, 9004, '', 2, 4, 2}, {9122, 117, '', 8, 4, 2}, {9122, 118, '', 8, 4, 2}, {9122, 119, '', 8, 4, 2}, {9122, 120, '', 8, 4, 2}, {9122, 322, '', 2, 4, 2}, {9122, 160, '', 5, 5, 2}, {9122, 327, '', 5, 5, 2}, {9122, 2900, '', 1, 6, 2}, {9122, 9101, '', 20, 7, 2}, {9122, 115, '', 15, 10, 2}, {9122, 114, '', 15, 12, 2}, {9122, 112, '', 15, 13, 2}, {9122, 113, '', 15, 13, 2}, } tpl9123 = { -- "packId","itemId","`group`","num","rate","rateType" {9123, 3299, '', 1, 1, 2}, {9123, 3300, '', 1, 1, 2}, {9123, 3301, '', 1, 1, 2}, {9123, 3302, '', 1, 1, 2}, {9123, 3303, '', 1, 1, 2}, {9123, 9004, '', 2, 4, 2}, {9123, 117, '', 8, 4, 2}, {9123, 118, '', 8, 4, 2}, {9123, 119, '', 8, 4, 2}, {9123, 120, '', 8, 4, 2}, {9123, 322, '', 2, 4, 2}, {9123, 160, '', 5, 5, 2}, {9123, 327, '', 5, 5, 2}, {9123, 2900, '', 1, 6, 2}, {9123, 9101, '', 20, 7, 2}, {9123, 115, '', 15, 10, 2}, {9123, 114, '', 15, 12, 2}, {9123, 112, '', 15, 13, 2}, {9123, 113, '', 15, 13, 2}, } function createInsertSql(tname, tpl) local tpl0 = getTpl0(tname) -- 獲取表各個字段 local ret = {} -- 插入記錄sql table.insert(ret, string.format("insert into `%s`(", tname)) for k, v in pairs(tpl0) do if k > 1 then table.insert(ret, ",") end table.insert(ret, v) end table.insert(ret, ") values ") for k, v in pairs(tpl) do if k > 1 then table.insert(ret, ",") end table.insert(ret, "(") for k2, v2 in pairs(v) do if k2 > 1 then table.insert(ret, ",") end if type(v2) == "string" then table.insert(ret, string.format("'%s'", v2)) else table.insert(ret, v2) end end table.insert(ret, ")") end table.insert(ret, ";") local result = table.concat(ret) -- 最終的sql語句 print(result) print() end createInsertSql("tpl_pack", tpl9122) createInsertSql("tpl_pack", tpl9123) 最終的執行結果以下: 1 2 3 4 [zcm@lua 6]$lua t1.lua insert into `tpl_pack`(packId,itemId,`group`,num,rate,rateType) values (9122,3294,'',1,1,2),(9122,3295,'',1,1,2),(9122,3296,'',1,1,2),(9122,3297,'',1,1,2),(9122,3298,'',1,1,2),(9122,9004,'',2,4,2),(9122,117,'',8,4,2),(9122,118,'',8,4,2),(9122,119,'',8,4,2),(9122,120,'',8,4,2),(9122,322,'',2,4,2),(9122,160,'',5,5,2),(9122,327,'',5,5,2),(9122,2900,'',1,6,2),(9122,9101,'',20,7,2),(9122,115,'',15,10,2),(9122,114,'',15,12,2),(9122,112,'',15,13,2),(9122,113,'',15,13,2); insert into `tpl_pack`(packId,itemId,`group`,num,rate,rateType) values (9123,3299,'',1,1,2),(9123,3300,'',1,1,2),(9123,3301,'',1,1,2),(9123,3302,'',1,1,2),(9123,3303,'',1,1,2),(9123,9004,'',2,4,2),(9123,117,'',8,4,2),(9123,118,'',8,4,2),(9123,119,'',8,4,2),(9123,120,'',8,4,2),(9123,322,'',2,4,2),(9123,160,'',5,5,2),(9123,327,'',5,5,2),(9123,2900,'',1,6,2),(9123,9101,'',20,7,2),(9123,115,'',15,10,2),(9123,114,'',15,12,2),(9123,112,'',15,13,2),(9123,113,'',15,13,2);