eredis 调试

[root@lvhuizhen eredis]# erl -pa ebin/
Erlang/OTP 17 [erts-6.0] [source] [64-bit] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V6.0  (abort with ^G)

4> {ok, Client} = eredis:start_link([{host,"172.16.176.150"},{port,6379},{database,0},{password,[]},{reconnect_sleep,100},{connect_timeout,5000}]).
{ok,<0.42.0>}
5> eredis:q(Client,["SMEMBERS", terminal_type_domains]).
{ok,[<<"dcb80871-372b-4617-b329-9aafe6f78acb">>]}
6> 
eredis:q(Client, ["HGET", "domain:dcb80871-372b-4617-b329-9aafe6f78acb:terminal_type_num", sky_windows]).   
{ok,<<"2">>}

emysql测试:

[root@localhost emysql]# erl -pa ./ebin/
Erlang/OTP 17 [erts-6.0] [source] [64-bit] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V6.0  (abort with ^G)
1> crypto:start().
ok
2> application:start(emysql).
ok
3> emysql:add_pool(my_pool, [{size,1}, {user,"admin"}, {password,"itserver"},{host,"172.16.81.107"},{port,3306},{database,"nms_db"}, {encoding,utf8},{start_cmds,[<<"SET TIME_ZONE='+00:00'">>,<<"SET SQL_MODE='STRICT_ALL_TABLES'">>]}]).
ok
4> emysql:execute(my_pool,<<"select count(*) from warning_repaired">>).
{result_packet,5,
               [{field,2,<<"def">>,<<>>,<<>>,<<>>,<<"count(*)">>,<<>>,8,
                       <<>>,63,21,129,0,#Fun<emysql_tcp.10.74485508>}],
               [[879340]],
               <<>>}
5>                                                                     
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
       (v)ersion (k)ill (D)b-tables (d)istribution
q
[root@localhost emysql]#

{result_packet,_,_,Value,_} = emysql:execute(PoolId,list_to_binary(SQL)),

第四个参数就是结果:如上面的[[879340]]


测试lua脚本:

redis-cli --eval ./update_physical_server_info.lua 0 , "4ca6230b-491f-46e2-a1ae-80f0e0e40742" "ip" "10.0.0.1;172.16.185.199;172.16.185.200;"

其中 --eval参数 是告诉redis-cli 读取并运行后面的lua脚本, ./updata_physical_server_info.lua 是ratelimiting.lua文件的位置,后面跟着的是传给lua脚本的参数。 其中“,”号前的0是要操作的建,可以再脚本中使用KEYS[1]获取, 后面的是参数,在脚本中能够使用ARGV[1]和ARGV[2]获得。

    注意:上面的命令中“,”两边的空格不能省略,否则会出错。

    update_physical_server_info.lua脚本的内容如下:

local KeyMoidInfo = 'p_server:' .. ARGV[1] .. ':info'
redis.call('HSET',KeyMoidInfo,ARGV[2],ARGV[3])

local ServerGuid = redis.call('HGET', KeyMoidInfo,'guid')
if ServerGuid ~= nil then 
    local KeyGuidInfo = 'p_server:' .. ServerGuid .. ':info'
    redis.call('HSET',KeyGuidInfo,ARGV[2],ARGV[3])
end

参考文章:redis入门很简单,第6章脚本


转载于:https://my.oschina.net/lvhuizhenblog/blog/508214

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值