You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -6205,6 +6207,8 @@ The resulting object `dict` has the following methods:
6205
6207
*[flush_all](#ngxshareddictflush_all)
6206
6208
*[flush_expired](#ngxshareddictflush_expired)
6207
6209
*[get_keys](#ngxshareddictget_keys)
6210
+
*[capacity](#ngxshareddictcapacity)
6211
+
*[free_space](#ngxshareddictfree_space)
6208
6212
6209
6213
All these methods are *atomic* operations, that is, safe from concurrent accesses from multiple nginx worker processes for the same `lua_shared_dict` zone.
6210
6214
@@ -6669,6 +6673,79 @@ This feature was first introduced in the `v0.7.3` release.
Retrieves the capacity in bytes for the shm-based dictionary [ngx.shared.DICT](#ngxshareddict) declared with
6685
+
the [lua_shared_dict](#lua_shared_dict) directive.
6686
+
6687
+
Example:
6688
+
6689
+
```lua
6690
+
6691
+
require"resty.core.shdict"
6692
+
6693
+
localcats=ngx.shared.cats
6694
+
localcapacity_bytes=cats:capacity()
6695
+
```
6696
+
6697
+
This feature was first introduced in the `v0.10.11` release.
6698
+
6699
+
**Note:** This method requires the `resty.core.shdict` or `resty.core` modules from the [lua-resty-core](https://github.com/openresty/lua-resty-core) library.
6700
+
6701
+
This feature requires at least nginx core version `0.7.3`.
Retrieves the free page size in bytes for the shm-based dictionary [ngx.shared.DICT](#ngxshareddict).
6716
+
6717
+
**Note:** The memory for ngx.shared.DICT is allocated via the nginx slab allocator which has each slot for
6718
+
data size ranges like ~8, 9~16, 17~32, ..., 1025~2048, 2048~ bytes. And pages are assigned to a slot if there
6719
+
is no room in already assigned pages for the slot.
6720
+
6721
+
So even if the return value of the `free_space` method is zero, there may be room in already assigned pages, so
6722
+
you may successfully set a new key value pair to the shared dict without getting `true` for `forcible` or
6723
+
non nil `err` from the `ngx.shared.DICT.set`.
6724
+
6725
+
On the other hand, if already assigned pages for a slot are full and a new key value pair is added to the
6726
+
slot and there is no free page, you may get `true` for `forcible` or non nil `err` from the
6727
+
`ngx.shared.DICT.set` method.
6728
+
6729
+
Example:
6730
+
6731
+
```lua
6732
+
6733
+
require"resty.core.shdict"
6734
+
6735
+
localcats=ngx.shared.cats
6736
+
localfree_page_bytes=cats:free_space()
6737
+
```
6738
+
6739
+
This feature was first introduced in the `v0.10.11` release.
6740
+
6741
+
**Note:** This method requires the `resty.core.shdict` or `resty.core` modules from the [lua-resty-core](https://github.com/openresty/lua-resty-core) library.
6742
+
6743
+
This feature requires at least nginx core version `1.11.7`.
All these methods are ''atomic'' operations, that is, safe from concurrent accesses from multiple nginx worker processes for the same <code>lua_shared_dict</code> zone.
5206
5208
@@ -5598,6 +5600,71 @@ By default, only the first 1024 keys (if any) are returned. When the <code><max_
5598
5600
5599
5601
This feature was first introduced in the <code>v0.7.3</code> release.
'''requires:''' <code>resty.core.shdict</code> or <code>resty.core</code>
5609
+
5610
+
Retrieves the capacity in bytes for the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]] declared with
5611
+
the [[#lua_shared_dict|lua_shared_dict]] directive.
5612
+
5613
+
Example:
5614
+
5615
+
<geshi lang="lua">
5616
+
require "resty.core.shdict"
5617
+
5618
+
local cats = ngx.shared.cats
5619
+
local capacity_bytes = cats:capacity()
5620
+
</geshi>
5621
+
5622
+
This feature was first introduced in the <code>v0.10.11</code> release.
5623
+
5624
+
'''Note:''' This method requires the <code>resty.core.shdict</code> or <code>resty.core</code> modules from the [https://github.com/openresty/lua-resty-core lua-resty-core] library.
5625
+
5626
+
This feature requires at least nginx core version <code>0.7.3</code>.
'''requires:''' <code>resty.core.shdict</code> or <code>resty.core</code>
5636
+
5637
+
Retrieves the free page size in bytes for the shm-based dictionary [[#ngx.shared.DICT|ngx.shared.DICT]].
5638
+
5639
+
'''Note:''' The memory for ngx.shared.DICT is allocated via the nginx slab allocator which has each slot for
5640
+
data size ranges like ~8, 9~16, 17~32, ..., 1025~2048, 2048~ bytes. And pages are assigned to a slot if there
5641
+
is no room in already assigned pages for the slot.
5642
+
5643
+
So even if the return value of the <code>free_space</code> method is zero, there may be room in already assigned pages, so
5644
+
you may successfully set a new key value pair to the shared dict without getting <code>true</code> for <code>forcible</code> or
5645
+
non nil <code>err</code> from the <code>ngx.shared.DICT.set</code>.
5646
+
5647
+
On the other hand, if already assigned pages for a slot are full and a new key value pair is added to the
5648
+
slot and there is no free page, you may get <code>true</code> for <code>forcible</code> or non nil <code>err</code> from the
5649
+
<code>ngx.shared.DICT.set</code> method.
5650
+
5651
+
Example:
5652
+
5653
+
<geshi lang="lua">
5654
+
require "resty.core.shdict"
5655
+
5656
+
local cats = ngx.shared.cats
5657
+
local free_page_bytes = cats:free_space()
5658
+
</geshi>
5659
+
5660
+
This feature was first introduced in the <code>v0.10.11</code> release.
5661
+
5662
+
'''Note:''' This method requires the <code>resty.core.shdict</code> or <code>resty.core</code> modules from the [https://github.com/openresty/lua-resty-core lua-resty-core] library.
5663
+
5664
+
This feature requires at least nginx core version <code>1.11.7</code>.
0 commit comments