Conversation
lib/acid/redis.lua
Outdated
| local function get_redis_cli(self) | ||
| local redis_cli, err_msg = resty_redis:new() | ||
| if redis_cli == nil then | ||
| return nil, nil, 'NewRedisError', err_msg |
lib/acid/redis.lua
Outdated
| local cmd, cmd_args = unpack(cmd_and_args) | ||
| local rst, err_code, err_msg = self[cmd](self, unpack(cmd_args or {})) | ||
| if err_code ~= nil then | ||
| self['discard'](self) |
There was a problem hiding this comment.
为啥不直接self:discard(), 为了某种风格一致吗?
There was a problem hiding this comment.
还是直接用self:discard()吧
| @@ -0,0 +1,237 @@ | |||
| local strutil = require("acid.strutil") | |||
There was a problem hiding this comment.
感觉这个文件里大部分逻辑跟redis都没关系...
感觉这个文件实现了2个东西...一个是一致性hash,一个是nwr...感觉逻辑上是可以分开的, 并且独立于redis的.
There was a problem hiding this comment.
1.acid.chash.lua已经是一个一致性hash的实现了,这里主要实现的是redis的一致性hash,
2.和nwr时有些耦合,我想想怎么分开
There was a problem hiding this comment.
这个想完之后...有打算修改吗?还是就酱了?
There was a problem hiding this comment.
nwr的区分开了,hash部分还是在redia_hash中
lib/acid/redis_chash.lua
Outdated
| return nil | ||
| end | ||
|
|
||
| local function optimize_choose_servers(addrs, least) |
There was a problem hiding this comment.
一个提供按照某种规则(如s2按照service_stat的server响应时间排序优先访问哪些server)优化chash选择的server接口,这里是一个直接返回addr是的默认函数
lib/acid/redis_chash.lua
Outdated
|
|
||
| if (tonumber(multi_rst[1]) ~= 1 or tonumber(multi_rst[1]) ~= 0) | ||
| and tonumber(multi_rst[2]) ~= 1 then | ||
| return nil, 'RunRedisCMDError', 'transaction HSET error' |
lib/acid/redis_chash.lua
Outdated
| end | ||
|
|
||
| function _M.hset(self, args, n, w, expire) | ||
| return run_xset_cmd(self, 'hset', args, n, w, expire) |
There was a problem hiding this comment.
一般对于一个业务,nwr是确定的, 读/写的wr必须 w+r>n才有意义.所以这里直接传1个参数包括nwr3个值, 对业务使用可能更友好(一个业务1个nwr配置) 实现也简单点. 不需要区分读写操作配置不同的nw / nr. 直接都传nwr进来. 好像这样好点?
lib/acid/redis_proxy.lua
Outdated
| HGET = {'GET', 'hget', 2, false, {}}, | ||
|
|
||
| -- hset(hashname, hashkey, val, expire=nil) | ||
| HSET = {'PUT', 'hset', 3, true, {'expire'}}, |
There was a problem hiding this comment.
这种配置方式是跟保海串通好的吧?~ <( ̄︶ ̄)>
There was a problem hiding this comment.
我改了下,不需要get set hget hset,直接table的key lower()下就可以了
|
|
||
| local redis_cmd_names = tableutil.keys(redis_cmd_model) | ||
|
|
||
| local function get_secret_key(access_key, secret_key) |
There was a problem hiding this comment.
aws_authenticator用到的,需要通过access_key得到secret_key
| end | ||
|
|
||
| local function output(rst, err_code, err_msg) | ||
| local status, body, headers = 200, '', {} |
There was a problem hiding this comment.
output独立到一个公用函数里吧, 我记得acid里好多模块都有这么一坨定义
There was a problem hiding this comment.
_M.output(status, headers, body)只是实现了将发送出去status, headers, body
lib/acid/redis_proxy.lua
Outdated
|
|
||
| local function get_cmd_args() | ||
| --local uri_ptr = '^/redisproxy/v\\d+/(\\S+)/(\\S+)$' | ||
| local uri_ptr = '^/redisproxy/v\\d+/(\\S+?)/(\\S+)$' |
There was a problem hiding this comment.
印象里..ptr是pointer的缩写...这里要缩写的话, ptn好点...
上面的注释是打酱油的吗...
There was a problem hiding this comment.
O(∩_∩)O哈哈~,一看你就是写C
ptn是pattern的缩写,比ptr些
想想用regex吧,ngx.re.match用的是regex
syntax: captures, err = ngx.re.match(subject, regex, options?, ctx?, res_table?)
lib/acid/redis.lua
Outdated
|
|
||
| local to_str = strutil.to_str | ||
|
|
||
| local _M = {} |
lib/acid/redis.lua
Outdated
| end | ||
| end | ||
|
|
||
| local multi_rst, err_code, err_msg = self['exec'](self) |
lib/acid/redis_proxy.lua
Outdated
| HGET = {'GET', 'hget', 2, false, {}}, | ||
|
|
||
| -- hset(hashname, hashkey, val, expire=nil) | ||
| HSET = {'PUT', 'hset', 3, true, {'expire'}}, |
There was a problem hiding this comment.
我改了下,不需要get set hget hset,直接table的key lower()下就可以了
|
|
||
| local redis_cli = acid_redis:new(ip, port, r_opts) | ||
|
|
||
| if pexpire ~= nil and cmd == 'hset' then |
There was a problem hiding this comment.
set不需要事务,set命令本身支持带expire参数
lib/acid/redis_proxy.lua
Outdated
|
|
||
| local rst, err_code, err_msg | ||
| if cmd == 'hget' then | ||
| rst, err_code, err_msg = self.redis_chash:hget(cmd_args, n, r) |
There was a problem hiding this comment.
nwr作为一个table传进去,expire也传进去,直接self.redis_chash[cmd]()
lib/acid/redis_proxy.lua
Outdated
|
|
||
| local cmd, cmd_args, nwr, expire = args.cmd, args.cmd_args, args.nwr, args.expire | ||
|
|
||
| local rst, err_code, err_msg = self.redis_cli[cmd](self, cmd_args, nwr, expire) |
There was a problem hiding this comment.
这里不太对吧,self有redis_cli吗,self.redis_chash?
lib/acid/redis_proxy.lua
Outdated
| return nil, 'InvalidCommand', to_str('just support: ', redis_cmd_names) | ||
| end | ||
|
|
||
| local http_method, cmd, nargs, needed_value, _ = unpack(cmd_model) |
There was a problem hiding this comment.
这里的cmd不需要配置,string.lower上面的cmd就可以了。少配置个参数。
30dd31b to
d6ec951
Compare
| end | ||
|
|
||
| setmetatable(_M, {__index = function(_, cmd) | ||
| local method = function (self, ...) |
There was a problem hiding this comment.
设置metatable有点不好懂, 直接列出所有的method逐个生成吧.
There was a problem hiding this comment.
这里是为了自动支持redis所有命令,不过从可读性来说是有点不太好懂,或者加个注释如何
| @@ -0,0 +1,237 @@ | |||
| local strutil = require("acid.strutil") | |||
There was a problem hiding this comment.
这个想完之后...有打算修改吗?还是就酱了?
|
|
||
| local function get_chash(self) | ||
| local conf = self.conf | ||
| local now = ngx.time() |
There was a problem hiding this comment.
这个update的代码好像跟async_cache的逻辑(或cache)模块一样,应该可以复用吧?
d6ec951 to
9c82997
Compare
ps:测试后续补上