Skip to content

Commit ed408d6

Browse files
committed
feature: add api in shdict: lpush, lpop, rpush, rpop, llen, expire
1 parent 04a57a1 commit ed408d6

File tree

5 files changed

+1791
-145
lines changed

5 files changed

+1791
-145
lines changed

README.markdown

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2700,6 +2700,12 @@ Nginx API for Lua
27002700
* [ngx.shared.DICT.replace](#ngxshareddictreplace)
27012701
* [ngx.shared.DICT.delete](#ngxshareddictdelete)
27022702
* [ngx.shared.DICT.incr](#ngxshareddictincr)
2703+
* [ngx.shared.DICT.lpush](#ngxshareddictlpush)
2704+
* [ngx.shared.DICT.rpush](#ngxshareddictrpush)
2705+
* [ngx.shared.DICT.lpop](#ngxshareddictlpop)
2706+
* [ngx.shared.DICT.rpop](#ngxshareddictrpop)
2707+
* [ngx.shared.DICT.llen](#ngxshareddictllen)
2708+
* [ngx.shared.DICT.expire](#ngxshareddictexpire)
27032709
* [ngx.shared.DICT.flush_all](#ngxshareddictflush_all)
27042710
* [ngx.shared.DICT.flush_expired](#ngxshareddictflush_expired)
27052711
* [ngx.shared.DICT.get_keys](#ngxshareddictget_keys)
@@ -5608,6 +5614,12 @@ The resulting object `dict` has the following methods:
56085614
* [replace](#ngxshareddictreplace)
56095615
* [delete](#ngxshareddictdelete)
56105616
* [incr](#ngxshareddictincr)
5617+
* [lpush](#ngxshareddictlpush)
5618+
* [rpush](#ngxshareddictrpush)
5619+
* [lpop](#ngxshareddictlpop)
5620+
* [rpop](#ngxshareddictrpop)
5621+
* [llen](#ngxshareddictllen)
5622+
* [expire](#ngxshareddictexpire)
56115623
* [flush_all](#ngxshareddictflush_all)
56125624
* [flush_expired](#ngxshareddictflush_expired)
56135625
* [get_keys](#ngxshareddictget_keys)
@@ -5860,6 +5872,102 @@ See also [ngx.shared.DICT](#ngxshareddict).
58605872

58615873
[Back to TOC](#nginx-api-for-lua)
58625874

5875+
ngx.shared.DICT.lpush
5876+
---------------------
5877+
**syntax:** *length, err = ngx.shared.DICT:lpush(key, value)*
5878+
5879+
**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.**
5880+
5881+
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.
5882+
5883+
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"`.
5884+
5885+
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".
5886+
5887+
This feature was first introduced in the `v0.*.*` release.
5888+
5889+
See also [ngx.shared.DICT](#ngxshareddict).
5890+
5891+
[Back to TOC](#nginx-api-for-lua)
5892+
5893+
ngx.shared.DICT.rpush
5894+
---------------------
5895+
**syntax:** *length, err = ngx.shared.DICT:rpush(key, value)*
5896+
5897+
**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.**
5898+
5899+
Similar to the [lpush](#ngxshareddictlpush) method, but insert the specified (numerical or string) `value` at the tail of the list named `key`.
5900+
5901+
This feature was first introduced in the `v0.*.*` release.
5902+
5903+
See also [ngx.shared.DICT](#ngxshareddict).
5904+
5905+
[Back to TOC](#nginx-api-for-lua)
5906+
5907+
ngx.shared.DICT.lpop
5908+
--------------------
5909+
**syntax:** *val, err = ngx.shared.DICT:lpop(key)*
5910+
5911+
**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.**
5912+
5913+
Removes and returns the first element of the list named `key` in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict).
5914+
5915+
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"`.
5916+
5917+
This feature was first introduced in the `v0.*.*` release.
5918+
5919+
See also [ngx.shared.DICT](#ngxshareddict).
5920+
5921+
[Back to TOC](#nginx-api-for-lua)
5922+
5923+
ngx.shared.DICT.rpop
5924+
--------------------
5925+
**syntax:** *val, err = ngx.shared.DICT:rpop(key)*
5926+
5927+
**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.**
5928+
5929+
Removes and returns the last element of the list named `key` in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict).
5930+
5931+
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"`.
5932+
5933+
This feature was first introduced in the `v0.*.*` release.
5934+
5935+
See also [ngx.shared.DICT](#ngxshareddict).
5936+
5937+
[Back to TOC](#nginx-api-for-lua)
5938+
5939+
ngx.shared.DICT.llen
5940+
--------------------
5941+
**syntax:** *len, err = ngx.shared.DICT:llen(key)*
5942+
5943+
**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.**
5944+
5945+
Returns the length of the list named `key` in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict).
5946+
5947+
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"`.
5948+
5949+
This feature was first introduced in the `v0.*.*` release.
5950+
5951+
See also [ngx.shared.DICT](#ngxshareddict).
5952+
5953+
[Back to TOC](#nginx-api-for-lua)
5954+
5955+
ngx.shared.DICT.expire
5956+
----------------------
5957+
**syntax:** *ok, err = ngx.shared.DICT:expire(key, exptime)*
5958+
5959+
**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.**
5960+
5961+
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.
5962+
5963+
If key does not exist or has been expired, it will return `false` and `"not found"`. Otherwise it will return `true`.
5964+
5965+
This feature was first introduced in the `v0.*.*` release.
5966+
5967+
See also [ngx.shared.DICT](#ngxshareddict).
5968+
5969+
[Back to TOC](#nginx-api-for-lua)
5970+
58635971
ngx.shared.DICT.flush_all
58645972
-------------------------
58655973
**syntax:** *ngx.shared.DICT:flush_all()*

doc/HttpLuaModule.wiki

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4683,6 +4683,12 @@ The resulting object <code>dict</code> has the following methods:
46834683
* [[#ngx.shared.DICT.replace|replace]]
46844684
* [[#ngx.shared.DICT.delete|delete]]
46854685
* [[#ngx.shared.DICT.incr|incr]]
4686+
* [[#ngx.shared.DICT.lpush|lpush]]
4687+
* [[#ngx.shared.DICT.rpush|rpush]]
4688+
* [[#ngx.shared.DICT.lpop|lpop]]
4689+
* [[#ngx.shared.DICT.rpop|rpop]]
4690+
* [[#ngx.shared.DICT.llen|llen]]
4691+
* [[#ngx.shared.DICT.expire|expire]]
46864692
* [[#ngx.shared.DICT.flush_all|flush_all]]
46874693
* [[#ngx.shared.DICT.flush_expired|flush_expired]]
46884694
* [[#ngx.shared.DICT.get_keys|get_keys]]
@@ -4900,6 +4906,84 @@ This feature was first introduced in the <code>v0.3.1rc22</code> release.
49004906
49014907
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
49024908
4909+
== ngx.shared.DICT.lpush ==
4910+
'''syntax:''' ''length, err = ngx.shared.DICT:lpush(key, value)''
4911+
4912+
'''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.*''
4913+
4914+
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.
4915+
4916+
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>.
4917+
4918+
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".
4919+
4920+
This feature was first introduced in the <code>v0.*.*</code> release.
4921+
4922+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
4923+
4924+
== ngx.shared.DICT.rpush ==
4925+
'''syntax:''' ''length, err = ngx.shared.DICT:rpush(key, value)''
4926+
4927+
'''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.*''
4928+
4929+
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>.
4930+
4931+
This feature was first introduced in the <code>v0.*.*</code> release.
4932+
4933+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
4934+
4935+
== ngx.shared.DICT.lpop ==
4936+
'''syntax:''' ''val, err = ngx.shared.DICT:lpop(key)''
4937+
4938+
'''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.*''
4939+
4940+
Removes and returns the first element of the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
4941+
4942+
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>.
4943+
4944+
This feature was first introduced in the <code>v0.*.*</code> release.
4945+
4946+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
4947+
4948+
== ngx.shared.DICT.rpop ==
4949+
'''syntax:''' ''val, err = ngx.shared.DICT:rpop(key)''
4950+
4951+
'''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.*''
4952+
4953+
Removes and returns the last element of the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
4954+
4955+
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>.
4956+
4957+
This feature was first introduced in the <code>v0.*.*</code> release.
4958+
4959+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
4960+
4961+
== ngx.shared.DICT.llen ==
4962+
'''syntax:''' ''len, err = ngx.shared.DICT:llen(key)''
4963+
4964+
'''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.*''
4965+
4966+
Returns the length of the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
4967+
4968+
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>.
4969+
4970+
This feature was first introduced in the <code>v0.*.*</code> release.
4971+
4972+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
4973+
4974+
== ngx.shared.DICT.expire ==
4975+
'''syntax:''' ''ok, err = ngx.shared.DICT:expire(key, exptime)''
4976+
4977+
'''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.*''
4978+
4979+
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.
4980+
4981+
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>.
4982+
4983+
This feature was first introduced in the <code>v0.*.*</code> release.
4984+
4985+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
4986+
49034987
== ngx.shared.DICT.flush_all ==
49044988
'''syntax:''' ''ngx.shared.DICT:flush_all()''
49054989

0 commit comments

Comments
 (0)