# HG changeset patch # User Yaroslav Zhuravlev # Date 1692184342 -3600 # Node ID 3184864bbb3fbce414d41bf4afac2518912d5e73 # Parent 0e805229dd19577f6a494901b60f8e36e482e075 Added SharedDict to njs Reference. diff -r 0e805229dd19 -r 3184864bbb3f xml/en/docs/http/ngx_http_js_module.xml --- a/xml/en/docs/http/ngx_http_js_module.xml Sat Sep 02 13:01:52 2023 -0400 +++ b/xml/en/docs/http/ngx_http_js_module.xml Wed Aug 16 12:12:22 2023 +0100 @@ -9,7 +9,7 @@ + rev="41">
@@ -637,7 +637,8 @@ Sets the name and size of the shared memory zone -that keeps the key-value dictionary +that keeps the +key-value dictionary shared between worker processes. diff -r 0e805229dd19 -r 3184864bbb3f xml/en/docs/njs/changes.xml --- a/xml/en/docs/njs/changes.xml Sat Sep 02 13:01:52 2023 -0400 +++ b/xml/en/docs/njs/changes.xml Wed Aug 16 12:12:22 2023 +0100 @@ -9,7 +9,7 @@
@@ -59,7 +59,8 @@ Feature: -introduced global nginx properties: +introduced more global +nginx properties: ngx.build, ngx.conf_file_path, ngx.error_log_path, @@ -84,6 +85,15 @@ +Feature: +introduced global +nginx.shared +methods and properties for working with shared dictionaries. + + + + + Improvement: added compile-time options to disable njs modules. For example, to disable libxslt-related code: diff -r 0e805229dd19 -r 3184864bbb3f xml/en/docs/njs/compatibility.xml --- a/xml/en/docs/njs/compatibility.xml Sat Sep 02 13:01:52 2023 -0400 +++ b/xml/en/docs/njs/compatibility.xml Wed Aug 16 12:12:22 2023 +0100 @@ -9,7 +9,7 @@
@@ -1116,6 +1116,23 @@ log + +ngx.shared +(0.8.0): +add, +clear, +delete, +incr, +freeSpace, +get, +has, +keys, +pop, +replace, +set, +size + + @@ -1207,6 +1224,14 @@ (0.8.0) + +ngx.shared +(0.8.0): +capacity, +name, +type + + diff -r 0e805229dd19 -r 3184864bbb3f xml/en/docs/njs/reference.xml --- a/xml/en/docs/njs/reference.xml Sat Sep 02 13:01:52 2023 -0400 +++ b/xml/en/docs/njs/reference.xml Wed Aug 16 12:12:22 2023 +0100 @@ -9,7 +9,7 @@
+ rev="115">
@@ -1584,6 +1584,208 @@
+
+ + +The ngx.shared global object is available +since 0.8.0. + + + +
+ + + + + + + + + + + + + + + + + +
ngx.shared.SharedDict.add()
ngx.shared.SharedDict.capacity
ngx.shared.SharedDict.clear()
ngx.shared.SharedDict.delete()
ngx.shared.SharedDict.incr()
ngx.shared.SharedDict.freeSpace()
ngx.shared.SharedDict.get()
ngx.shared.SharedDict.has()
ngx.shared.SharedDict.keys()
ngx.shared.SharedDict.name
ngx.shared.SharedDict.pop()
ngx.shared.SharedDict.replace()
ngx.shared.SharedDict.set()
ngx.shared.SharedDict.size()
ngx.shared.SharedDict.type
+
+ + +The shared dictionary object is available +since 0.8.0. +The shared dictionary name, type, and size +are set with the js_shared_dict_zone directive in +http +or +stream. + + + +A SharedDict() object +has the following properties and methods: + + +ngx.shared.SharedDict.add(key, +value) + +Sets the value +for the specified key in the dictionary +only if the key does not exist yet. +The key is a string representing +the key of the item to add, +the value is the value of the item to add. +Returns true if the value has been successfully added +to the SharedDict dictionary, +false if the key already exists in the dictionary. +Throws SharedMemoryError if +there is not enough free space in the SharedDict dictionary. +Throws TypeError if the value is +of a different type than expected by this dictionary. + + +ngx.shared.SharedDict.capacity + +Returns the capacity of the SharedDict dictionary, +corresponds to the size parameter of +js_shared_dict_zone directive in +http +or +stream. + + +ngx.shared.SharedDict.clear() + +Removes all items from the SharedDict dictionary. + + +ngx.shared.SharedDict.delete(key) + +Removes the item associated with the specified key +from the SharedDict dictionary, +true if the item in the dictionary existed and was removed, +false otherwise. + + +ngx.shared.SharedDict.incr(key,delta[,init]) + +Increments the integer value associated with the key +by delta. +If the key does not exist, +the item will be initialized to init. +The key is a string, +the delta is the number +to increment or decrement the value by, +the init is a number to initialize the item with +if it does not exist, by default is 0. +Returns the new value. +Throws SharedMemoryError if +there is not enough free space in the SharedDict dictionary. +Throws TypeError if this dictionary does not expect numbers. + +This method can be used only if the dictionary type was declared with +type=number parameter of the +js_shared_dict_zone directive in +http +or +stream. + + + +ngx.shared.SharedDict.freeSpace() + +Returns the free page size in bytes. +If the size is zero, the SharedDict dictionary +will still accept new values if there is space in the occupied pages. + + +ngx.shared.SharedDict.get(key) + +Retrieves the item by its key, +returns the value associated with the key +or undefined if there is none. + + +ngx.shared.SharedDict.has(key) + +Searches for an item by its key, +returns true if such item exists or +false otherwise. + + +ngx.shared.SharedDict.keys([maxCount]) + +Returns an array of the SharedDict dictionary keys. +The maxCount parameter +sets maximum number of keys to retrieve, +by default is 1024. + + + +ngx.shared.SharedDict.name + +Returns the name of the SharedDict dictionary, +corresponds to the zone= parameter of +js_shared_dict_zone directive in +http +or +stream. + + +ngx.shared.SharedDict.pop(key) + +Removes the item associated with the specified key +from the SharedDict dictionary, +returns the value associated with the key +or undefined if there is none. + + +ngx.shared.SharedDict.replace(key, +value) + +Replaces the value +for the specified key only if the key already exists, +returns true if the value was successfully replaced, +false if the key does not exist +in the SharedDict dictionary. +Throws SharedMemoryError if +there is not enough free space in the SharedDict dictionary. +Throws TypeError if the value is +of a different type than expected by this dictionary. + + +ngx.shared.SharedDict.set(key, +value) + +Sets the value for the specified key, +returns this SharedDict dictionary (for method chaining). + + +ngx.shared.SharedDict.size() + +Returns the number of items for the SharedDict dictionary. + + +ngx.shared.SharedDict.type + +Returns string or number that +corresponds to the SharedDict dictionary type +set by the type= parameter of +js_shared_dict_zone directive in +http +or +stream. + + + + + +
+ +
+
diff -r 0e805229dd19 -r 3184864bbb3f xml/en/docs/stream/ngx_stream_js_module.xml --- a/xml/en/docs/stream/ngx_stream_js_module.xml Sat Sep 02 13:01:52 2023 -0400 +++ b/xml/en/docs/stream/ngx_stream_js_module.xml Wed Aug 16 12:12:22 2023 +0100 @@ -9,7 +9,7 @@ + rev="39">
@@ -622,7 +622,8 @@ Sets the name and size of the shared memory zone -that keeps the key-value dictionary +that keeps the +key-value dictionary shared between worker processes. diff -r 0e805229dd19 -r 3184864bbb3f xml/ru/docs/http/ngx_http_js_module.xml --- a/xml/ru/docs/http/ngx_http_js_module.xml Sat Sep 02 13:01:52 2023 -0400 +++ b/xml/ru/docs/http/ngx_http_js_module.xml Wed Aug 16 12:12:22 2023 +0100 @@ -9,7 +9,7 @@ + rev="41">
@@ -638,7 +638,8 @@ Задаёт имя и размер зоны разделяемой памяти, -в которой хранится словарь ключей и значений, +в которой хранится +словарь ключей и значений, разделяемый между рабочими процессами. diff -r 0e805229dd19 -r 3184864bbb3f xml/ru/docs/njs/compatibility.xml --- a/xml/ru/docs/njs/compatibility.xml Sat Sep 02 13:01:52 2023 -0400 +++ b/xml/ru/docs/njs/compatibility.xml Wed Aug 16 12:12:22 2023 +0100 @@ -9,7 +9,7 @@
@@ -1116,6 +1116,23 @@ log + +ngx.shared +(0.8.0): +add, +clear, +delete, +incr, +freeSpace, +get, +has, +keys, +pop, +replace, +set, +size + + @@ -1207,6 +1224,14 @@ (0.8.0) + +ngx.shared +(0.8.0): +capacity, +name, +type + + diff -r 0e805229dd19 -r 3184864bbb3f xml/ru/docs/stream/ngx_stream_js_module.xml --- a/xml/ru/docs/stream/ngx_stream_js_module.xml Sat Sep 02 13:01:52 2023 -0400 +++ b/xml/ru/docs/stream/ngx_stream_js_module.xml Wed Aug 16 12:12:22 2023 +0100 @@ -9,7 +9,7 @@ + rev="39">
@@ -621,7 +621,8 @@ Задаёт имя и размер зоны разделяемой памяти, -в которой хранится словарь ключей и значений, +в которой хранится +словарь ключей и значений, разделяемый между рабочими процессами.