@@ -19,11 +19,14 @@ local ngx_shared = ngx.shared
1919local getmetatable = getmetatable
2020
2121
22+ local MAX_ERR_MSG_LEN = 128
23+
24+
2225ffi .cdef [[
2326 int ngx_http_lua_ffi_shdict_get (void * zone , const unsigned char * key ,
2427 size_t key_len , int * value_type , unsigned char ** str_value_buf ,
2528 size_t * str_value_len , double * num_value , int * user_flags ,
26- int get_stale , int * is_stale );
29+ int get_stale , int * is_stale , char ** errmsg );
2730
2831 int ngx_http_lua_ffi_shdict_incr (void * zone , const unsigned char * key ,
2932 size_t key_len , double * value , char ** err , int has_init , double init ,
@@ -201,8 +204,12 @@ local function shdict_get(zone, key)
201204 local rc = C .ngx_http_lua_ffi_shdict_get (zone , key , key_len , value_type ,
202205 str_value_buf , value_len ,
203206 num_value , user_flags , 0 ,
204- is_stale )
207+ is_stale , errmsg )
205208 if rc ~= 0 then
209+ if errmsg [0 ] then
210+ return nil , ffi_str (errmsg [0 ])
211+ end
212+
206213 return error (" failed to get the key" )
207214 end
208215
@@ -272,8 +279,12 @@ local function shdict_get_stale(zone, key)
272279 local rc = C .ngx_http_lua_ffi_shdict_get (zone , key , key_len , value_type ,
273280 str_value_buf , value_len ,
274281 num_value , user_flags , 1 ,
275- is_stale )
282+ is_stale , errmsg )
276283 if rc ~= 0 then
284+ if errmsg [0 ] then
285+ return nil , ffi_str (errmsg [0 ])
286+ end
287+
277288 return error (" failed to get the key" )
278289 end
279290
0 commit comments