Skip to content

Commit 1de5883

Browse files
doujiang24agentzh
authored andcommitted
feature: added new shdict methods: lpush, lpop, rpush, rpop, llen for manipulating list-typed values.
These methods can be used in the same way as the redis commands of the same names. Essentially we now have shared memory based queues now. Each queue is indexed by a key. Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
1 parent d6258da commit 1de5883

File tree

6 files changed

+1718
-72
lines changed

6 files changed

+1718
-72
lines changed

README.markdown

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3041,6 +3041,11 @@ Nginx API for Lua
30413041
* [ngx.shared.DICT.replace](#ngxshareddictreplace)
30423042
* [ngx.shared.DICT.delete](#ngxshareddictdelete)
30433043
* [ngx.shared.DICT.incr](#ngxshareddictincr)
3044+
* [ngx.shared.DICT.lpush](#ngxshareddictlpush)
3045+
* [ngx.shared.DICT.rpush](#ngxshareddictrpush)
3046+
* [ngx.shared.DICT.lpop](#ngxshareddictlpop)
3047+
* [ngx.shared.DICT.rpop](#ngxshareddictrpop)
3048+
* [ngx.shared.DICT.llen](#ngxshareddictllen)
30443049
* [ngx.shared.DICT.flush_all](#ngxshareddictflush_all)
30453050
* [ngx.shared.DICT.flush_expired](#ngxshareddictflush_expired)
30463051
* [ngx.shared.DICT.get_keys](#ngxshareddictget_keys)
@@ -6035,6 +6040,11 @@ The resulting object `dict` has the following methods:
60356040
* [replace](#ngxshareddictreplace)
60366041
* [delete](#ngxshareddictdelete)
60376042
* [incr](#ngxshareddictincr)
6043+
* [lpush](#ngxshareddictlpush)
6044+
* [rpush](#ngxshareddictrpush)
6045+
* [lpop](#ngxshareddictlpop)
6046+
* [rpop](#ngxshareddictrpop)
6047+
* [llen](#ngxshareddictllen)
60386048
* [flush_all](#ngxshareddictflush_all)
60396049
* [flush_expired](#ngxshareddictflush_expired)
60406050
* [get_keys](#ngxshareddictget_keys)
@@ -6093,7 +6103,7 @@ ngx.shared.DICT.get
60936103

60946104
**context:** *set_by_lua&#42;, rewrite_by_lua&#42;, access_by_lua&#42;, content_by_lua&#42;, header_filter_by_lua&#42;, body_filter_by_lua&#42;, log_by_lua&#42;, ngx.timer.&#42;, balancer_by_lua&#42;, ssl_certificate_by_lua&#42;, ssl_session_fetch_by_lua&#42;, ssl_session_store_by_lua&#42;*
60956105

6096-
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.
6106+
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.
60976107

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

@@ -6298,6 +6308,86 @@ See also [ngx.shared.DICT](#ngxshareddict).
62986308

62996309
[Back to TOC](#nginx-api-for-lua)
63006310

6311+
ngx.shared.DICT.lpush
6312+
---------------------
6313+
**syntax:** *length, err = ngx.shared.DICT:lpush(key, value)*
6314+
6315+
**context:** *init_by_lua&#42;, set_by_lua&#42;, rewrite_by_lua&#42;, access_by_lua&#42;, content_by_lua&#42;, header_filter_by_lua&#42;, body_filter_by_lua&#42;, log_by_lua&#42;, ngx.timer.&#42;, balancer_by_lua&#42;, ssl_certificate_by_lua&#42;, ssl_session_fetch_by_lua&#42;, ssl_session_store_by_lua&#42;*
6316+
6317+
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.
6318+
6319+
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"`.
6320+
6321+
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".
6322+
6323+
This feature was first introduced in the `v0.10.6` release.
6324+
6325+
See also [ngx.shared.DICT](#ngxshareddict).
6326+
6327+
[Back to TOC](#nginx-api-for-lua)
6328+
6329+
ngx.shared.DICT.rpush
6330+
---------------------
6331+
**syntax:** *length, err = ngx.shared.DICT:rpush(key, value)*
6332+
6333+
**context:** *init_by_lua&#42;, set_by_lua&#42;, rewrite_by_lua&#42;, access_by_lua&#42;, content_by_lua&#42;, header_filter_by_lua&#42;, body_filter_by_lua&#42;, log_by_lua&#42;, ngx.timer.&#42;, balancer_by_lua&#42;, ssl_certificate_by_lua&#42;, ssl_session_fetch_by_lua&#42;, ssl_session_store_by_lua&#42;*
6334+
6335+
Similar to the [lpush](#ngxshareddictlpush) method, but inserts the specified (numerical or string) `value` at the tail of the list named `key`.
6336+
6337+
This feature was first introduced in the `v0.10.6` release.
6338+
6339+
See also [ngx.shared.DICT](#ngxshareddict).
6340+
6341+
[Back to TOC](#nginx-api-for-lua)
6342+
6343+
ngx.shared.DICT.lpop
6344+
--------------------
6345+
**syntax:** *val, err = ngx.shared.DICT:lpop(key)*
6346+
6347+
**context:** *init_by_lua&#42;, set_by_lua&#42;, rewrite_by_lua&#42;, access_by_lua&#42;, content_by_lua&#42;, header_filter_by_lua&#42;, body_filter_by_lua&#42;, log_by_lua&#42;, ngx.timer.&#42;, balancer_by_lua&#42;, ssl_certificate_by_lua&#42;, ssl_session_fetch_by_lua&#42;, ssl_session_store_by_lua&#42;*
6348+
6349+
Removes and returns the first element of the list named `key` in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict).
6350+
6351+
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"`.
6352+
6353+
This feature was first introduced in the `v0.10.6` release.
6354+
6355+
See also [ngx.shared.DICT](#ngxshareddict).
6356+
6357+
[Back to TOC](#nginx-api-for-lua)
6358+
6359+
ngx.shared.DICT.rpop
6360+
--------------------
6361+
**syntax:** *val, err = ngx.shared.DICT:rpop(key)*
6362+
6363+
**context:** *init_by_lua&#42;, set_by_lua&#42;, rewrite_by_lua&#42;, access_by_lua&#42;, content_by_lua&#42;, header_filter_by_lua&#42;, body_filter_by_lua&#42;, log_by_lua&#42;, ngx.timer.&#42;, balancer_by_lua&#42;, ssl_certificate_by_lua&#42;, ssl_session_fetch_by_lua&#42;, ssl_session_store_by_lua&#42;*
6364+
6365+
Removes and returns the last element of the list named `key` in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict).
6366+
6367+
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"`.
6368+
6369+
This feature was first introduced in the `v0.10.6` release.
6370+
6371+
See also [ngx.shared.DICT](#ngxshareddict).
6372+
6373+
[Back to TOC](#nginx-api-for-lua)
6374+
6375+
ngx.shared.DICT.llen
6376+
--------------------
6377+
**syntax:** *len, err = ngx.shared.DICT:llen(key)*
6378+
6379+
**context:** *init_by_lua&#42;, set_by_lua&#42;, rewrite_by_lua&#42;, access_by_lua&#42;, content_by_lua&#42;, header_filter_by_lua&#42;, body_filter_by_lua&#42;, log_by_lua&#42;, ngx.timer.&#42;, balancer_by_lua&#42;, ssl_certificate_by_lua&#42;, ssl_session_fetch_by_lua&#42;, ssl_session_store_by_lua&#42;*
6380+
6381+
Returns the number of elements in the list named `key` in the shm-based dictionary [ngx.shared.DICT](#ngxshareddict).
6382+
6383+
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"`.
6384+
6385+
This feature was first introduced in the `v0.10.6` release.
6386+
6387+
See also [ngx.shared.DICT](#ngxshareddict).
6388+
6389+
[Back to TOC](#nginx-api-for-lua)
6390+
63016391
ngx.shared.DICT.flush_all
63026392
-------------------------
63036393
**syntax:** *ngx.shared.DICT:flush_all()*

doc/HttpLuaModule.wiki

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5053,6 +5053,11 @@ The resulting object <code>dict</code> has the following methods:
50535053
* [[#ngx.shared.DICT.replace|replace]]
50545054
* [[#ngx.shared.DICT.delete|delete]]
50555055
* [[#ngx.shared.DICT.incr|incr]]
5056+
* [[#ngx.shared.DICT.lpush|lpush]]
5057+
* [[#ngx.shared.DICT.rpush|rpush]]
5058+
* [[#ngx.shared.DICT.lpop|lpop]]
5059+
* [[#ngx.shared.DICT.rpop|rpop]]
5060+
* [[#ngx.shared.DICT.llen|llen]]
50565061
* [[#ngx.shared.DICT.flush_all|flush_all]]
50575062
* [[#ngx.shared.DICT.flush_expired|flush_expired]]
50585063
* [[#ngx.shared.DICT.get_keys|get_keys]]
@@ -5106,7 +5111,7 @@ This feature was first introduced in the <code>v0.3.1rc22</code> release.
51065111
51075112
'''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*''
51085113
5109-
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.
5114+
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.
51105115
51115116
In case of errors, <code>nil</code> and a string describing the error will be returned.
51125117
@@ -5281,6 +5286,71 @@ The optional `init` parameter was first added in the <code>v0.10.6</code> releas
52815286
52825287
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
52835288
5289+
== ngx.shared.DICT.lpush ==
5290+
'''syntax:''' ''length, err = ngx.shared.DICT:lpush(key, value)''
5291+
5292+
'''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.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*''
5293+
5294+
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.
5295+
5296+
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>.
5297+
5298+
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".
5299+
5300+
This feature was first introduced in the <code>v0.10.6</code> release.
5301+
5302+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
5303+
5304+
== ngx.shared.DICT.rpush ==
5305+
'''syntax:''' ''length, err = ngx.shared.DICT:rpush(key, value)''
5306+
5307+
'''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.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*''
5308+
5309+
Similar to the [[#ngx.shared.DICT.lpush|lpush]] method, but inserts the specified (numerical or string) <code>value</code> at the tail of the list named <code>key</code>.
5310+
5311+
This feature was first introduced in the <code>v0.10.6</code> release.
5312+
5313+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
5314+
5315+
== ngx.shared.DICT.lpop ==
5316+
'''syntax:''' ''val, err = ngx.shared.DICT:lpop(key)''
5317+
5318+
'''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.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*''
5319+
5320+
Removes and returns the first element of the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
5321+
5322+
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>.
5323+
5324+
This feature was first introduced in the <code>v0.10.6</code> release.
5325+
5326+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
5327+
5328+
== ngx.shared.DICT.rpop ==
5329+
'''syntax:''' ''val, err = ngx.shared.DICT:rpop(key)''
5330+
5331+
'''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.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*''
5332+
5333+
Removes and returns the last element of the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
5334+
5335+
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>.
5336+
5337+
This feature was first introduced in the <code>v0.10.6</code> release.
5338+
5339+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
5340+
5341+
== ngx.shared.DICT.llen ==
5342+
'''syntax:''' ''len, err = ngx.shared.DICT:llen(key)''
5343+
5344+
'''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.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*''
5345+
5346+
Returns the number of elements in the list named <code>key</code> in the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
5347+
5348+
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>.
5349+
5350+
This feature was first introduced in the <code>v0.10.6</code> release.
5351+
5352+
See also [[#ngx.shared.DICT|ngx.shared.DICT]].
5353+
52845354
== ngx.shared.DICT.flush_all ==
52855355
'''syntax:''' ''ngx.shared.DICT:flush_all()''
52865356

0 commit comments

Comments
 (0)