Skip to content

Commit 3eb0be9

Browse files
committed
some doc fix and bugfix
1 parent 2683c4d commit 3eb0be9

File tree

4 files changed

+43
-39
lines changed

4 files changed

+43
-39
lines changed

README.markdown

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6105,7 +6105,7 @@ ngx.shared.DICT.get
61056105

61066106
**context:** *set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua**
61076107

6108-
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.
6108+
Retrieving the value in the dictionary [ngx.shared.DICT](#ngxshareddict) for the key `key`. If the key does not exist or has expired, then `nil` will be returned.
61096109

61106110
In case of errors, `nil` and a string describing the error will be returned.
61116111

@@ -6314,11 +6314,11 @@ ngx.shared.DICT.lpush
63146314
---------------------
63156315
**syntax:** *length, err = ngx.shared.DICT:lpush(key, value)*
63166316

6317-
**context:** *init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.**
6317+
**context:** *init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.**
63186318

6319-
Inserts the specified (numerical or string) `value` at the head of the list named `key` in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict). Returns the length of the list after the push operations.
6319+
Inserts the specified (numerical or string) `value` at the head of the list named `key` in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict). Returns the number of elements in the list after the push operation.
63206320

6321-
If `key` does not exist, it is created as empty list before performing the push operations. When key holds a value that is not a list, it will return `nil` and `"wrongtype operation"`.
6321+
If `key` does not exist, it is created as an empty list before performing the push operations. When the `key` already takes a value that is not a list, it will return `nil` and `"value not a list"`.
63226322

63236323
It never overrides the (least recently used) unexpired items in the store when running out of storage in the shared memory zone. In this case, it will immediately return `nil` and the string "no memory".
63246324

@@ -6332,7 +6332,7 @@ ngx.shared.DICT.rpush
63326332
---------------------
63336333
**syntax:** *length, err = ngx.shared.DICT:rpush(key, value)*
63346334

6335-
**context:** *init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.**
6335+
**context:** *init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.**
63366336

63376337
Similar to the [lpush](#ngxshareddictlpush) method, but inserts the specified (numerical or string) `value` at the tail of the list named `key`.
63386338

@@ -6346,11 +6346,11 @@ ngx.shared.DICT.lpop
63466346
--------------------
63476347
**syntax:** *val, err = ngx.shared.DICT:lpop(key)*
63486348

6349-
**context:** *init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.**
6349+
**context:** *init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.**
63506350

63516351
Removes and returns the first element of the list named `key` in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict).
63526352

6353-
If `key` does not exist, it will return `nil`. When key holds a value that is not a list, it will return `nil` and `"wrongtype operation"`.
6353+
If `key` does not exist, it will return `nil`. When the `key` already takes a value that is not a list, it will return `nil` and `"value not a list"`.
63546354

63556355
This feature was first introduced in the `v0.*.*` release.
63566356

@@ -6362,11 +6362,11 @@ ngx.shared.DICT.rpop
63626362
--------------------
63636363
**syntax:** *val, err = ngx.shared.DICT:rpop(key)*
63646364

6365-
**context:** *init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.**
6365+
**context:** *init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.**
63666366

63676367
Removes and returns the last element of the list named `key` in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict).
63686368

6369-
If `key` does not exist, it will return `nil`. When key holds a value that is not a list, it will return `nil` and `"wrongtype operation"`.
6369+
If `key` does not exist, it will return `nil`. When the `key` already takes a value that is not a list, it will return `nil` and `"value not a list"`.
63706370

63716371
This feature was first introduced in the `v0.*.*` release.
63726372

@@ -6378,11 +6378,11 @@ ngx.shared.DICT.llen
63786378
--------------------
63796379
**syntax:** *len, err = ngx.shared.DICT:llen(key)*
63806380

6381-
**context:** *init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.**
6381+
**context:** *init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.**
63826382

63836383
Returns the length of the list named `key` in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict).
63846384

6385-
If key does not exist, it is interpreted as an empty list and 0 is returned. When key holds a value that is not a list, it will return `nil` and `"wrongtype operation"`.
6385+
If key does not exist, it is interpreted as an empty list and 0 is returned. When the `key` already takes a value that is not a list, it will return `nil` and `"value not a list"`.
63866386

63876387
This feature was first introduced in the `v0.*.*` release.
63886388

@@ -6394,11 +6394,11 @@ ngx.shared.DICT.expire
63946394
----------------------
63956395
**syntax:** *ok, err = ngx.shared.DICT:expire(key, exptime)*
63966396

6397-
**context:** *init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.**
6397+
**context:** *init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.**
63986398

6399-
The `exptime` argument specifies expiration time (in seconds) for the inserted key-value pair. The time resolution is 0.001 seconds. If the exptime takes the value 0, then the item will never be expired.
6399+
The `exptime` argument specifies a new expiration time (in seconds) for an existing key-value pair in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict) specified by the `key` argument. The time resolution is 0.001 seconds. If the exptime takes the value 0, then the item will never expire.
64006400

6401-
If key does not exist or has been expired, it will return `false` and `"not found"`. Otherwise it will return `true`.
6401+
If key does not exist or has expired, it will return `false` and `"not found"`. Otherwise it will return `true`.
64026402

64036403
This feature was first introduced in the `v0.*.*` release.
64046404

doc/HttpLuaModule.wiki

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5112,7 +5112,7 @@ This feature was first introduced in the <code>v0.3.1rc22</code> release.
51125112
51135113
'''context:''' ''set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*''
51145114
5115-
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.
5115+
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 expired, then <code>nil</code> will be returned.
51165116
51175117
In case of errors, <code>nil</code> and a string describing the error will be returned.
51185118
@@ -5292,9 +5292,9 @@ See also [[#ngx.shared.DICT|ngx.shared.DICT]].
52925292
52935293
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*''
52945294
5295-
Inserts the specified (numerical or string) <code>value</code> at the head of the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]]. Returns the length of the list after the push operations.
5295+
Inserts the specified (numerical or string) <code>value</code> at the head of the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]]. Returns the number of elements in the list after the push operation.
52965296
5297-
If <code>key</code> does not exist, it is created as empty list before performing the push operations. When key holds a value that is not a list, it will return <code>nil</code> and <code>"wrongtype operation"</code>.
5297+
If <code>key</code> does not exist, it is created as an empty list before performing the push operations. When the <code>key</code> already takes a value that is not a list, it will return <code>nil</code> and <code>"value not a list"</code>.
52985298
52995299
It never overrides the (least recently used) unexpired items in the store when running out of storage in the shared memory zone. In this case, it will immediately return <code>nil</code> and the string "no memory".
53005300
@@ -5320,7 +5320,7 @@ See also [[#ngx.shared.DICT|ngx.shared.DICT]].
53205320
53215321
Removes and returns the first element of the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
53225322
5323-
If <code>key</code> does not exist, it will return <code>nil</code>. When key holds a value that is not a list, it will return <code>nil</code> and <code>"wrongtype operation"</code>.
5323+
If <code>key</code> does not exist, it will return <code>nil</code>. When the <code>key</code> already takes a value that is not a list, it will return <code>nil</code> and <code>"value not a list"</code>.
53245324
53255325
This feature was first introduced in the <code>v0.*.*</code> release.
53265326
@@ -5333,7 +5333,7 @@ See also [[#ngx.shared.DICT|ngx.shared.DICT]].
53335333
53345334
Removes and returns the last element of the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
53355335
5336-
If <code>key</code> does not exist, it will return <code>nil</code>. When key holds a value that is not a list, it will return <code>nil</code> and <code>"wrongtype operation"</code>.
5336+
If <code>key</code> does not exist, it will return <code>nil</code>. When the <code>key</code> already takes a value that is not a list, it will return <code>nil</code> and <code>"value not a list"</code>.
53375337
53385338
This feature was first introduced in the <code>v0.*.*</code> release.
53395339
@@ -5346,7 +5346,7 @@ See also [[#ngx.shared.DICT|ngx.shared.DICT]].
53465346
53475347
Returns the length of the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
53485348
5349-
If key does not exist, it is interpreted as an empty list and 0 is returned. When key holds a value that is not a list, it will return <code>nil</code> and <code>"wrongtype operation"</code>.
5349+
If key does not exist, it is interpreted as an empty list and 0 is returned. When the <code>key</code> already takes a value that is not a list, it will return <code>nil</code> and <code>"value not a list"</code>.
53505350
53515351
This feature was first introduced in the <code>v0.*.*</code> release.
53525352
@@ -5357,9 +5357,9 @@ See also [[#ngx.shared.DICT|ngx.shared.DICT]].
53575357
53585358
'''context:''' ''init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*''
53595359
5360-
The <code>exptime</code> argument specifies expiration time (in seconds) for the inserted key-value pair. The time resolution is 0.001 seconds. If the exptime takes the value 0, then the item will never be expired.
5360+
The <code>exptime</code> argument specifies a new expiration time (in seconds) for an existing key-value pair in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]] specified by the <code>key</code> argument. The time resolution is 0.001 seconds. If the exptime takes the value 0, then the item will never expire.
53615361
5362-
If key does not exist or has been expired, it will return <code>false</code> and <code>"not found"</code>. Otherwise it will return <code>true</code>.
5362+
If key does not exist or has expired, it will return <code>false</code> and <code>"not found"</code>. Otherwise it will return <code>true</code>.
53635363
53645364
This feature was first introduced in the <code>v0.*.*</code> release.
53655365

src/ngx_http_lua_shdict.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static ngx_inline ngx_shm_zone_t *ngx_http_lua_shdict_get_zone(lua_State *L,
5252
#define NGX_HTTP_LUA_SHDICT_REPLACE 0x0002
5353
#define NGX_HTTP_LUA_SHDICT_SAFE_STORE 0x0004
5454

55+
5556
#define NGX_HTTP_LUA_SHDICT_LEFT 0x0001
5657
#define NGX_HTTP_LUA_SHDICT_RIGHT 0x0002
5758

@@ -60,6 +61,7 @@ enum {
6061
SHDICT_USERDATA_INDEX = 1,
6162
};
6263

64+
6365
enum {
6466
SHDICT_TNIL = 0, /* same as LUA_TNIL */
6567
SHDICT_TBOOLEAN = 1, /* same as LUA_TBOOLEAN */
@@ -69,7 +71,7 @@ enum {
6971
};
7072

7173

72-
static ngx_queue_t *
74+
static ngx_inline ngx_queue_t *
7375
ngx_http_lua_shdict_get_list_head(ngx_http_lua_shdict_node_t *sd, u_short len)
7476
{
7577
return (ngx_queue_t *) ngx_align_ptr(((u_char *) &sd->data + len),
@@ -607,7 +609,7 @@ ngx_http_lua_shdict_get_helper(lua_State *L, int get_stale)
607609
ngx_shmtx_unlock(&ctx->shpool->mutex);
608610

609611
lua_pushnil(L);
610-
lua_pushliteral(L, "wrongtype operation");
612+
lua_pushliteral(L, "value is a list");
611613
return 2;
612614

613615
default:
@@ -1712,8 +1714,9 @@ ngx_http_lua_shdict_push_helper(lua_State *L, int flags)
17121714

17131715
dd("shdict lookup returned %d", (int) rc);
17141716

1717+
/* exists but expired */
1718+
17151719
if (rc == NGX_DONE) {
1716-
/* exists but expired */
17171720

17181721
if (sd->value_type != SHDICT_TLIST) {
17191722
/* TODO: reuse when length matched */
@@ -1761,14 +1764,17 @@ ngx_http_lua_shdict_push_helper(lua_State *L, int flags)
17611764

17621765
dd("go to push_node");
17631766
goto push_node;
1767+
}
1768+
1769+
/* exists and not expired */
17641770

1765-
} else if (rc == NGX_OK) {
1771+
if (rc == NGX_OK) {
17661772

17671773
if (sd->value_type != SHDICT_TLIST) {
17681774
ngx_shmtx_unlock(&ctx->shpool->mutex);
17691775

17701776
lua_pushnil(L);
1771-
lua_pushliteral(L, "wrongtype operation");
1777+
lua_pushliteral(L, "value not a list");
17721778
return 2;
17731779
}
17741780

@@ -1993,7 +1999,7 @@ ngx_http_lua_shdict_pop_helper(lua_State *L, int flags)
19931999
ngx_shmtx_unlock(&ctx->shpool->mutex);
19942000

19952001
lua_pushnil(L);
1996-
lua_pushliteral(L, "wrongtype operation");
2002+
lua_pushliteral(L, "value not a list");
19972003
return 2;
19982004
}
19992005

@@ -2076,7 +2082,6 @@ ngx_http_lua_shdict_pop_helper(lua_State *L, int flags)
20762082
ngx_slab_free_locked(ctx->shpool, node);
20772083

20782084
} else {
2079-
20802085
sd->value_len = sd->value_len - 1;
20812086

20822087
ngx_queue_remove(&sd->queue);
@@ -2151,21 +2156,20 @@ ngx_http_lua_shdict_llen(lua_State *L)
21512156
dd("shdict lookup returned %d", (int) rc);
21522157

21532158
if (rc == NGX_OK) {
2154-
21552159
if (sd->value_type != SHDICT_TLIST) {
21562160
ngx_shmtx_unlock(&ctx->shpool->mutex);
21572161

21582162
lua_pushnil(L);
2159-
lua_pushliteral(L, "wrongtype operation");
2163+
lua_pushliteral(L, "value not a list");
21602164
return 2;
21612165
}
21622166

21632167
ngx_queue_remove(&sd->queue);
21642168
ngx_queue_insert_head(&ctx->sh->queue, &sd->queue);
21652169

2166-
lua_pushnumber(L, (lua_Number) sd->value_len);
2167-
21682170
ngx_shmtx_unlock(&ctx->shpool->mutex);
2171+
2172+
lua_pushnumber(L, (lua_Number) sd->value_len);
21692173
return 1;
21702174
}
21712175

t/133-shdict-list.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ nil nil
8282
GET /test
8383
--- response_body
8484
push success
85-
nil wrongtype operation
85+
nil value is a list
8686
--- no_error_log
8787
[error]
8888

@@ -181,7 +181,7 @@ GET /test
181181
--- response_body
182182
push success
183183
false exists
184-
nil wrongtype operation
184+
nil value is a list
185185
--- no_error_log
186186
[error]
187187

@@ -247,7 +247,7 @@ GET /test
247247
--- response_body
248248
push success
249249
nil not a number
250-
nil wrongtype operation
250+
nil value is a list
251251
--- no_error_log
252252
[error]
253253

@@ -308,7 +308,7 @@ key: foo
308308
GET /test
309309
--- response_body
310310
set success
311-
nil wrongtype operation
311+
nil value not a list
312312
bar nil
313313
--- no_error_log
314314
[error]
@@ -341,7 +341,7 @@ bar nil
341341
GET /test
342342
--- response_body
343343
set success
344-
nil wrongtype operation
344+
nil value not a list
345345
bar nil
346346
--- no_error_log
347347
[error]
@@ -374,7 +374,7 @@ bar nil
374374
GET /test
375375
--- response_body
376376
set success
377-
nil wrongtype operation
377+
nil value not a list
378378
bar nil
379379
--- no_error_log
380380
[error]

0 commit comments

Comments
 (0)