]> git.kaiwu.me - njs.git/commit
Modules: introduced js_shared_dict_zone directive.
authorDmitry Volyntsev <xeioex@nginx.com>
Mon, 3 Jul 2023 20:32:41 +0000 (13:32 -0700)
committerDmitry Volyntsev <xeioex@nginx.com>
Mon, 3 Jul 2023 20:32:41 +0000 (13:32 -0700)
commit1fe63aba30cd828c46cd12ea7057c9a2f58b45f6
tree49fb4305dd33c31d93ef276bf701738e998598e4
parent40b01ac098d7835263b1ab80bb040edc3d98b29b
Modules: introduced js_shared_dict_zone directive.

The directive allows to declare a dictionary that is shared among the
working processes. A dictionary expects strings as keys. It stores
string or number as values. The value type is declared using
type= argument of the directive. The default type is string.

example.conf:
    # Declares a shared dictionary of strings of size 1 Mb that
    # removes key-value after 60 seconds of inactivity.
    js_shared_dict_zone zone=foo:1M timeout=60s;

    # Declares a shared dictionary of strings of size 512Kb that
    # forcibly remove oldest key-value pairs when memory is not enough.
    js_shared_dict_zone zone=bar:512K timeout=30s evict;

    # Declares a permanent number shared dictionary of size 32Kb.
    js_shared_dict_zone zone=num:32k type=number;

example.js:
    function get(r) {
        r.return(200, ngx.shared.foo.get(r.args.key));
    }

    function set(r) {
        r.return(200, ngx.shared.foo.set(r.args.key, r.args.value));
    }

    function delete(r) {
        r.return(200, ngx.shared.bar.delete(r.args.key));
    }

    function increment(r) {
        r.return(200, ngx.shared.num.incr(r.args.key, 2));
    }

In collaboration with Artem S. Povalyukhin, Jakub Jirutka and
洪志道 (Hong Zhi Dao).

This closes #437 issue on Github.
nginx/config
nginx/ngx_http_js_module.c
nginx/ngx_js.c
nginx/ngx_js.h
nginx/ngx_js_shared_dict.c [new file with mode: 0644]
nginx/ngx_js_shared_dict.h [new file with mode: 0644]
nginx/ngx_stream_js_module.c
nginx/t/js_shared_dict.t [new file with mode: 0644]
nginx/t/stream_js_shared_dict.t [new file with mode: 0644]
ts/ngx_core.d.ts