mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
merge master
This commit is contained in:
@@ -415,6 +415,8 @@ append_one(struct bson *bs, lua_State *L, const char *key, size_t sz, int depth)
|
||||
append_key(bs, L, BSON_BOOLEAN, key, sz);
|
||||
write_byte(bs, lua_toboolean(L,-1));
|
||||
break;
|
||||
case LUA_TNIL:
|
||||
luaL_error(L, "Bson array has a hole (nil), Use bson.null instead");
|
||||
default:
|
||||
luaL_error(L, "Invalid value type : %s", lua_typename(L,vt));
|
||||
}
|
||||
@@ -452,12 +454,7 @@ pack_dict_data(lua_State *L, struct bson *b, int depth, int kt) {
|
||||
size_t sz;
|
||||
switch(kt) {
|
||||
case LUA_TNUMBER:
|
||||
// copy key, don't change key type
|
||||
lua_pushvalue(L,-2);
|
||||
lua_insert(L,-2);
|
||||
key = lua_tolstring(L,-2,&sz);
|
||||
append_one(b, L, key, sz, depth);
|
||||
lua_pop(L,2);
|
||||
luaL_error(L, "Bson dictionary's key can't be number");
|
||||
break;
|
||||
case LUA_TSTRING:
|
||||
key = lua_tolstring(L,-2,&sz);
|
||||
|
||||
@@ -33,7 +33,7 @@ function _M.new(startup_nodes,opt)
|
||||
end
|
||||
|
||||
local function nodename(node)
|
||||
return string.format("%s:%s",node.host,node.port)
|
||||
return string.format("%s:%d",node.host,node.port)
|
||||
end
|
||||
|
||||
function rediscluster:get_redis_link(node)
|
||||
@@ -74,20 +74,22 @@ function rediscluster:initialize_slots_cache()
|
||||
local conn = self.connections[name] or self:get_redis_link(startup_node)
|
||||
local list = conn:cluster("slots")
|
||||
for _,result in ipairs(list) do
|
||||
local ip,port,runid = table.unpack(result[3])
|
||||
local ip,port = table.unpack(result[3])
|
||||
assert(ip)
|
||||
port = assert(tonumber(port))
|
||||
local master_node = {
|
||||
host = ip,
|
||||
port = port,
|
||||
runid = runid,
|
||||
slaves = {},
|
||||
}
|
||||
self:set_node_name(master_node)
|
||||
for i=4,#result do
|
||||
local ip,port,runid = table.unpack(result[i])
|
||||
local ip,port = table.unpack(result[i])
|
||||
assert(ip)
|
||||
port = assert(tonumber(port))
|
||||
local slave_node = {
|
||||
host = ip,
|
||||
port = port,
|
||||
runid = runid,
|
||||
}
|
||||
self:set_node_name(slave_node)
|
||||
table.insert(master_node.slaves,slave_node)
|
||||
@@ -184,10 +186,7 @@ function rediscluster:close_all_connection()
|
||||
end
|
||||
|
||||
function rediscluster:get_connection(node)
|
||||
if type(node) == "string" then
|
||||
local ip,port = string.match(node,"^([^:]+):([^:]+)$")
|
||||
node = {host=ip,port=port}
|
||||
end
|
||||
node.port = assert(tonumber(node.port))
|
||||
local name = node.name or nodename(node)
|
||||
local conn = self.connections[name]
|
||||
if not conn then
|
||||
@@ -346,9 +345,10 @@ function rediscluster:call(...)
|
||||
end
|
||||
local newslot = tonumber(errlist[2])
|
||||
local node_ip,node_port = string.match(errlist[3],"^([^:]+):([^:]+)$")
|
||||
node_port = assert(tonumber(node_port))
|
||||
local node = {
|
||||
host = node_ip,
|
||||
port = tonumber(node_port),
|
||||
port = node_port,
|
||||
}
|
||||
if not asking then
|
||||
self:set_node_name(node)
|
||||
|
||||
@@ -1389,14 +1389,16 @@ socket_server_poll(struct socket_server *ss, struct socket_message * result, int
|
||||
int error;
|
||||
socklen_t len = sizeof(error);
|
||||
int code = getsockopt(s->fd, SOL_SOCKET, SO_ERROR, &error, &len);
|
||||
const char * err = NULL;
|
||||
if (code < 0) {
|
||||
result->data = strerror(errno);
|
||||
err = strerror(errno);
|
||||
} else if (error != 0) {
|
||||
result->data = strerror(error);
|
||||
err = strerror(error);
|
||||
} else {
|
||||
result->data = "Unknown error";
|
||||
err = "Unknown error";
|
||||
}
|
||||
force_close(ss, s, &l, result);
|
||||
result->data = (char *)err;
|
||||
return SOCKET_ERR;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -22,9 +22,9 @@ end
|
||||
|
||||
local obj_a = {
|
||||
__data = {
|
||||
[1] = 2,
|
||||
[3] = 4,
|
||||
[5] = 6,
|
||||
["1"] = 2,
|
||||
["3"] = 4,
|
||||
["5"] = 6,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ setmetatable(
|
||||
|
||||
local obj_b = {
|
||||
__data = {
|
||||
[7] = 8,
|
||||
[9] = 10,
|
||||
[11] = obj_a,
|
||||
["7"] = 8,
|
||||
["9"] = 10,
|
||||
["11"] = obj_a,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user