shdict: improved the error handling a bit and also increased the tests' code coverage.

This commit is contained in:
Yichun Zhang (agentzh) 2014-01-04 19:56:41 -08:00
Родитель 0afaeec3d0
Коммит a4323aab82
4 изменённых файлов: 806 добавлений и 29 удалений

Просмотреть файл

@ -4432,6 +4432,8 @@ ngx.shared.DICT.get
Retrieving the value in the dictionary [ngx.shared.DICT](#ngxshareddict) for the key `key`. If the key does not exist or has been expired, then `nil` will be returned.
In case of errors, `nil` and a string describing the error will be returned.
The value returned will have the original data type when they were inserted into the dictionary, for example, Lua booleans, numbers, or strings.
The first argument to this method must be the dictionary object itself, for example,
@ -6533,4 +6535,3 @@ See Also
* [memc-nginx-module](http://github.com/agentzh/memc-nginx-module)
* [The ngx_openresty bundle](http://openresty.org)
* [Nginx Systemtap Toolkit](https://github.com/agentzh/nginx-systemtap-toolkit)

Просмотреть файл

@ -3709,6 +3709,8 @@ This feature was first introduced in the <code>v0.3.1rc22</code> release.
Retrieving the value in the dictionary [[#ngx.shared.DICT|ngx.shared.DICT]] for the key <code>key</code>. If the key does not exist or has been expired, then <code>nil</code> will be returned.
In case of errors, <code>nil</code> and a string describing the error will be returned.
The value returned will have the original data type when they were inserted into the dictionary, for example, Lua booleans, numbers, or strings.
The first argument to this method must be the dictionary object itself, for example,
@ -5534,4 +5536,3 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* [[HttpMemcModule]]
* [http://openresty.org The ngx_openresty bundle]
* [https://github.com/agentzh/nginx-systemtap-toolkit Nginx Systemtap Toolkit]

Просмотреть файл

@ -396,28 +396,32 @@ ngx_http_lua_shdict_get_helper(lua_State *L, int get_stale)
"but only seen %d", n);
}
luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
zone = lua_touserdata(L, 1);
if (zone == NULL) {
return luaL_error(L, "bad user data for the ngx_shm_zone_t pointer");
return luaL_error(L, "bad \"zone\" argument");
}
ctx = zone->data;
name = ctx->name;
if (lua_isnil(L, 2)) {
lua_pushnil(L);
lua_pushliteral(L, "nil key");
return 2;
}
key.data = (u_char *) luaL_checklstring(L, 2, &key.len);
if (key.len == 0) {
lua_pushnil(L);
return 1;
lua_pushliteral(L, "empty key");
return 2;
}
if (key.len > 65535) {
return luaL_error(L,
"the key argument is more than 65535 bytes: \"%s\"",
key.data);
lua_pushnil(L);
lua_pushliteral(L, "key too long");
return 2;
}
hash = ngx_crc32_short(key.data, key.len);
@ -831,24 +835,31 @@ ngx_http_lua_shdict_set_helper(lua_State *L, int flags)
"but only seen %d", n);
}
luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
zone = lua_touserdata(L, 1);
if (zone == NULL) {
return luaL_error(L, "bad user data for the ngx_shm_zone_t pointer");
return luaL_error(L, "bad \"zone\" argument");
}
ctx = zone->data;
if (lua_isnil(L, 2)) {
lua_pushnil(L);
lua_pushliteral(L, "nil key");
return 2;
}
key.data = (u_char *) luaL_checklstring(L, 2, &key.len);
if (key.len == 0) {
return luaL_error(L, "attempt to use empty keys");
lua_pushnil(L);
lua_pushliteral(L, "empty key");
return 2;
}
if (key.len > 65535) {
return luaL_error(L, "the key argument is more than 65535 bytes: %d",
(int) key.len);
lua_pushnil(L);
lua_pushliteral(L, "key too long");
return 2;
}
hash = ngx_crc32_short(key.data, key.len);
@ -882,9 +893,9 @@ ngx_http_lua_shdict_set_helper(lua_State *L, int flags)
break;
default:
return luaL_error(L, "unsupported value type for key \"%s\" in "
"shared_dict: %s", key.data,
lua_typename(L, value_type));
lua_pushnil(L);
lua_pushliteral(L, "bad value type");
return 2;
}
if (n >= 4) {
@ -1142,8 +1153,9 @@ ngx_http_lua_shdict_incr(lua_State *L)
}
if (key.len > 65535) {
return luaL_error(L, "the key argument is more than 65535 bytes: %d",
(int) key.len);
lua_pushnil(L);
lua_pushliteral(L, "key too long");
return 2;
}
hash = ngx_crc32_short(key.data, key.len);

Разница между файлами не показана из-за своего большого размера Загрузить разницу