Skip to content

Commit cd8f45b

Browse files
committed
feature: add api in shdict: lpush, lpop, rpush, rpop, llen, expire
1 parent a5ac9fa commit cd8f45b

File tree

5 files changed

+1789
-143
lines changed

5 files changed

+1789
-143
lines changed

README.markdown

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,6 +2920,12 @@ Nginx API for Lua
29202920
* [ngx.shared.DICT.replace](#ngxshareddictreplace)
29212921
* [ngx.shared.DICT.delete](#ngxshareddictdelete)
29222922
* [ngx.shared.DICT.incr](#ngxshareddictincr)
2923+
* [ngx.shared.DICT.lpush](#ngxshareddictlpush)
2924+
* [ngx.shared.DICT.rpush](#ngxshareddictrpush)
2925+
* [ngx.shared.DICT.lpop](#ngxshareddictlpop)
2926+
* [ngx.shared.DICT.rpop](#ngxshareddictrpop)
2927+
* [ngx.shared.DICT.llen](#ngxshareddictllen)
2928+
* [ngx.shared.DICT.expire](#ngxshareddictexpire)
29232929
* [ngx.shared.DICT.flush_all](#ngxshareddictflush_all)
29242930
* [ngx.shared.DICT.flush_expired](#ngxshareddictflush_expired)
29252931
* [ngx.shared.DICT.get_keys](#ngxshareddictget_keys)
@@ -5912,6 +5918,12 @@ The resulting object `dict` has the following methods:
59125918
* [replace](#ngxshareddictreplace)
59135919
* [delete](#ngxshareddictdelete)
59145920
* [incr](#ngxshareddictincr)
5921+
* [lpush](#ngxshareddictlpush)
5922+
* [rpush](#ngxshareddictrpush)
5923+
* [lpop](#ngxshareddictlpop)
5924+
* [rpop](#ngxshareddictrpop)
5925+
* [llen](#ngxshareddictllen)
5926+
* [expire](#ngxshareddictexpire)
59155927
* [flush_all](#ngxshareddictflush_all)
59165928
* [flush_expired](#ngxshareddictflush_expired)
59175929
* [get_keys](#ngxshareddictget_keys)
@@ -6164,6 +6176,102 @@ See also [ngx.shared.DICT](#ngxshareddict).
61646176

61656177
[Back to TOC](#nginx-api-for-lua)
61666178

6179+
ngx.shared.DICT.lpush
6180+
---------------------
6181+
**syntax:** *length, err = ngx.shared.DICT:lpush(key, value)*
6182+
6183+
**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.**
6184+
6185+
Insert 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.
6186+
6187+
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"`.
6188+
6189+
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".
6190+
6191+
This feature was first introduced in the `v0.*.*` release.
6192+
6193+
See also [ngx.shared.DICT](#ngxshareddict).
6194+
6195+
[Back to TOC](#nginx-api-for-lua)
6196+
6197+
ngx.shared.DICT.rpush
6198+
---------------------
6199+
**syntax:** *length, err = ngx.shared.DICT:rpush(key, value)*
6200+
6201+
**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.**
6202+
6203+
Similar to the [lpush](#ngxshareddictlpush) method, but insert the specified (numerical or string) `value` at the tail of the list named `key`.
6204+
6205+
This feature was first introduced in the `v0.*.*` release.
6206+
6207+
See also [ngx.shared.DICT](#ngxshareddict).
6208+
6209+
[Back to TOC](#nginx-api-for-lua)
6210+
6211+
ngx.shared.DICT.lpop
6212+
--------------------
6213+
**syntax:** *val, err = ngx.shared.DICT:lpop(key)*
6214+
6215+
**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.**
6216+
6217+
Removes and returns the first element of the list named `key` in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict).
6218+
6219+
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"`.
6220+
6221+
This feature was first introduced in the `v0.*.*` release.
6222+
6223+
See also [ngx.shared.DICT](#ngxshareddict).
6224+
6225+
[Back to TOC](#nginx-api-for-lua)
6226+
6227+
ngx.shared.DICT.rpop
6228+
--------------------
6229+
**syntax:** *val, err = ngx.shared.DICT:rpop(key)*
6230+
6231+
**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.**
6232+
6233+
Removes and returns the last element of the list named `key` in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict).
6234+
6235+
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"`.
6236+
6237+
This feature was first introduced in the `v0.*.*` release.
6238+
6239+
See also [ngx.shared.DICT](#ngxshareddict).
6240+
6241+
[Back to TOC](#nginx-api-for-lua)
6242+
6243+
ngx.shared.DICT.llen
6244+
--------------------
6245+
**syntax:** *len, err = ngx.shared.DICT:llen(key)*
6246+
6247+
**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.**
6248+
6249+
Returns the length of the list named `key` in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict).
6250+
6251+
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"`.
6252+
6253+
This feature was first introduced in the `v0.*.*` release.
6254+
6255+
See also [ngx.shared.DICT](#ngxshareddict).
6256+
6257+
[Back to TOC](#nginx-api-for-lua)
6258+
6259+
ngx.shared.DICT.expire
6260+
----------------------
6261+
**syntax:** *ok, err = ngx.shared.DICT:expire(key, exptime)*
6262+
6263+
**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.**
6264+
6265+
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.
6266+
6267+
If key does not exist or has been expired, it will return `false` and `"not found"`. Otherwise it will return `true`.
6268+
6269+
This feature was first introduced in the `v0.*.*` release.
6270+
6271+
See also [ngx.shared.DICT](#ngxshareddict).
6272+
6273+
[Back to TOC](#nginx-api-for-lua)
6274+
61676275
ngx.shared.DICT.flush_all
61686276
-------------------------
61696277
**syntax:** *ngx.shared.DICT:flush_all()*

doc/HttpLuaModule.wiki

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4946,6 +4946,12 @@ The resulting object <code>dict</code> has the following methods:
49464946
* [[#ngx.shared.DICT.replace|replace]]
49474947
* [[#ngx.shared.DICT.delete|delete]]
49484948
* [[#ngx.shared.DICT.incr|incr]]
4949+
* [[#ngx.shared.DICT.lpush|lpush]]
4950+
* [[#ngx.shared.DICT.rpush|rpush]]
4951+
* [[#ngx.shared.DICT.lpop|lpop]]
4952+
* [[#ngx.shared.DICT.rpop|rpop]]
4953+
* [[#ngx.shared.DICT.llen|llen]]
4954+
* [[#ngx.shared.DICT.expire|expire]]
49494955
* [[#ngx.shared.DICT.flush_all|flush_all]]
49504956
* [[#ngx.shared.DICT.flush_expired|flush_expired]]
49514957
* [[#ngx.shared.DICT.get_keys|get_keys]]
@@ -5163,6 +5169,84 @@ This feature was first introduced in the <code>v0.3.1rc22</code> release.
51635169
51645170
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
51655171
5172+
== ngx.shared.DICT.lpush ==
5173+
'''syntax:''' ''length, err = ngx.shared.DICT:lpush(key, value)''
5174+
5175+
'''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.*''
5176+
5177+
Insert 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.
5178+
5179+
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>.
5180+
5181+
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".
5182+
5183+
This feature was first introduced in the <code>v0.*.*</code> release.
5184+
5185+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
5186+
5187+
== ngx.shared.DICT.rpush ==
5188+
'''syntax:''' ''length, err = ngx.shared.DICT:rpush(key, value)''
5189+
5190+
'''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.*''
5191+
5192+
Similar to the [[#ngx.shared.DICT.lpush|lpush]] method, but insert the specified (numerical or string) <code>value</code> at the tail of the list named <code>key</code>.
5193+
5194+
This feature was first introduced in the <code>v0.*.*</code> release.
5195+
5196+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
5197+
5198+
== ngx.shared.DICT.lpop ==
5199+
'''syntax:''' ''val, err = ngx.shared.DICT:lpop(key)''
5200+
5201+
'''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.*''
5202+
5203+
Removes and returns the first element of the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
5204+
5205+
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>.
5206+
5207+
This feature was first introduced in the <code>v0.*.*</code> release.
5208+
5209+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
5210+
5211+
== ngx.shared.DICT.rpop ==
5212+
'''syntax:''' ''val, err = ngx.shared.DICT:rpop(key)''
5213+
5214+
'''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.*''
5215+
5216+
Removes and returns the last element of the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
5217+
5218+
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>.
5219+
5220+
This feature was first introduced in the <code>v0.*.*</code> release.
5221+
5222+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
5223+
5224+
== ngx.shared.DICT.llen ==
5225+
'''syntax:''' ''len, err = ngx.shared.DICT:llen(key)''
5226+
5227+
'''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.*''
5228+
5229+
Returns the length of the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
5230+
5231+
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>.
5232+
5233+
This feature was first introduced in the <code>v0.*.*</code> release.
5234+
5235+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
5236+
5237+
== ngx.shared.DICT.expire ==
5238+
'''syntax:''' ''ok, err = ngx.shared.DICT:expire(key, exptime)''
5239+
5240+
'''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.*''
5241+
5242+
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.
5243+
5244+
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>.
5245+
5246+
This feature was first introduced in the <code>v0.*.*</code> release.
5247+
5248+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
5249+
51665250
== ngx.shared.DICT.flush_all ==
51675251
'''syntax:''' ''ngx.shared.DICT:flush_all()''
51685252

0 commit comments

Comments
 (0)