openwrt redis
2071 make V=s
2072 cd build_dir/target-x86_64_uClibc-0.9.33.2/root-x86/
cd package/network/services/zk-audit/
redis 远程登录 bind 0.0.0.0 /etc/redis/redis.confi 修改这个配置文件就可远程登录上去
启动服务端 redis-server 1162 root 27372 S redis-server 0.0.0.0:6379
启动客户端 redis-cli
常用命令 :
1 显示所有的键值 keys *
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 获取值的信息
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-redis
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 ;
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() -- 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", )
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[] == false then
ngx.say("failed to run command ", i, ": ", res[])
else
-- process the table value
end
else
-- process the scalar value
end
end
-- put it into the connection pool of size ,
-- with seconds max idle time
local ok, err = red:set_keepalive(, )
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"
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , }, {, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
} tpl9123 = {
-- "packId","itemId","`group`","num","rate","rateType"
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , }, {, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
{, , '', , , },
} 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 > then
table.insert(ret, ",")
end
table.insert(ret, v)
end
table.insert(ret, ") values ") for k, v in pairs(tpl) do
if k > then
table.insert(ret, ",")
end
table.insert(ret, "(")
for k2, v2 in pairs(v) do
if k2 > 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)
最终的执行结果如下: [zcm@lua ]$lua t1.lua
insert into `tpl_pack`(packId,itemId,`group`,num,rate,rateType) values (,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,); insert into `tpl_pack`(packId,itemId,`group`,num,rate,rateType) values (,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,),(,,'',,,);
openwrt redis的更多相关文章
- 记录一次widora sdk编译ipk 实战编译redis
因为业务需求,需要用到redis存储一点简单的数据,因为redis有良好的哈希机制,可以完美实现我的某些需求,但openwrt官方提供memcached的ipk并没有提供redis,没办法,只能自 ...
- Openwrt路由器上安装python
在路由器安装python之前,还是经过了一番折腾的.淘宝上买了个已经刷好系统的小米迷你路由器,但里面安装的不是预期的Pandorbox,而是LEDE. 这个固件已经带了大量自带的软件,128的内存实在 ...
- 使用redis构建可靠分布式锁
关于分布式锁的概念,具体实现方式,直接参阅下面两个帖子,这里就不多介绍了. 分布式锁的多种实现方式 分布式锁总结 对于分布式锁的几种实现方式的优劣,这里再列举下 1. 数据库实现方式 优点:易理解 缺 ...
- Ignite性能测试以及对redis的对比
测试方法 为了对Ignite做一个基本了解,做了一个性能测试,测试方法也比较简单主要是针对client模式,因为这种方法和使用redis的方式特别像.测试方法很简单主要是下面几点: 不作参数优化,默认 ...
- mac osx 安装redis扩展
1 php -v查看php版本 2 brew search php|grep redis 搜索对应的redis ps:如果没有brew 就根据http://brew.sh安装 3 brew ins ...
- Redis/HBase/Tair比较
KV系统对比表 对比维度 Redis Redis Cluster Medis Hbase Tair 访问模式 支持Value大小 理论上不超过1GB(建议不超过1MB) 理论上可配置(默认配置1 ...
- Redis数据库
Redis是k-v型数据库的典范,设计思想及数据结构实现都值得学习. 1.数据类型 value支持五种数据类型:1.字符串(strings)2.字符串列表(lists)3.字符串集合(sets)4.有 ...
- redis 学习笔记(2)
redis-cluster 简介 redis-cluster是一个分布式.容错的redis实现,redis-cluster通过将各个单独的redis实例通过特定的协议连接到一起实现了分布式.集群化的目 ...
- redis 学习笔记(1)
redis持久化 snapshot数据快照(rdb) 这是一种定时将redis内存中的数据写入磁盘文件的一种方案,这样保留这一时刻redis中的数据镜像,用于意外回滚.redis的snapshot的格 ...
随机推荐
- idae父子项目Test执行报Result Maps collection already contains value for xxx
现象:同一个springmvc工程使用eclipse和idea用Tomcat启动都没问题,但是如果走单元测试使用到了@ContextConfiguration这个spring的上下文注解idea出问题 ...
- 2018-3-5-安装-pip
title author date CreateTime categories 安装 pip lindexi 2018-3-5 19:4:4 +0800 2018-03-05 18:57:15 +08 ...
- BZOJ 1576: [Usaco2009 Jan]安全路经Travel
日常自闭半小时后看题解,太弱了qwq. 感觉这道题还是比较难的,解法十分巧妙,不容易想到. 首先题目说了起点到每个点的最短路都是唯一的,那么对这个图求最短路图必定是一棵树,而且这棵树是唯一的. 那么我 ...
- mysql5.7问题:[Note] InnoDB: Waiting for page_cleaner to finish flushing of buffer pool
在关闭mysql5.7的时候发现问题,一直处于夯住状态 [root@localhost ~]# /etc/init.d/mysqld stop Shutting down MySQL......... ...
- mongodb数据库管道操作
1.$project(修改文档的结构,可以用来重命名.增加或删除文档中的字段) db.order.aggregate([ { $project:{ rade_no:1, all_price:1} } ...
- Hello cnblog!
博主是从csdn搬过来的,原博客地址: https://blog.csdn.net/Cold_Chair 里面有一些不错的游记和知识点讲解,由于不方便搬过来,所以有兴趣的同学可以去看看(* ̄︶ ̄)
- 【LeetCode 21】合并两个有序链表
题目链接 [题解] 就是归并排序的一趟合并操作. 新建个链表加在上面就好.(用原来的链表的头结点也没问题) 加个头结点会比较好操作一点. 返回的时候返回头结点的next域就行 [代码] /** * D ...
- 百度API获取位置范围内的周边服务
百度地图API是一套为开发者免费提供的基于百度地图的应用程序接口,包括JavaScript.iOS.Andriod.静态地图.Web服务等多种版本,提供基本地图.位置搜索.周边搜索.... <s ...
- project的操作说明
project 1 操作的步骤 设定一个起始时间:7月1号 安排好摘要(任务)的先后顺序 一个一个任务的来:A任务,下面有几个分布实现的部门: 设计部门 3个工作日 程序部门 1个工作日.然后配置相互 ...
- ajax url地址
当前网址 http://localhost:8080/exam_paper/402881ec5c3924ec015c394ee4210000/set_questions ajax请求url var u ...