nginx / njs

A subset of JavaScript language to use in nginx
http://nginx.org/en/docs/njs/
BSD 2-Clause "Simplified" License
1.02k stars 147 forks source link

Will shared-memory be implemented or considered? #437

Closed HermannLizard closed 1 year ago

HermannLizard commented 2 years ago

https://github.com/nginx/njs/issues/431 https://github.com/nginx/njs/issues/354#issuecomment-723712610

For instance, this can be used in web gray-release solution, totally replace the "redis+nginx+lua" solution, since web maintainers is usually more familiar with JavaScript than lua, like, me. More controllable, more flexible. Sincerely looking forward to it.

xiaoxiangmoe commented 1 year ago

Hi @xeioex, do you know when will https://github.com/nginxinc/docker-nginx update njs version to 0.8.0?

xeioex commented 1 year ago

Hi @xiaoxiangmoe,

I think @thresheek, may answer this question.

jirutka commented 1 year ago

do you know when will https://github.com/nginxinc/docker-nginx update njs version to 0.8.0?

Or you can just use a bare image with Alpine Linux Edge and install nginx, nginx-mod-http-js and any other modules you need. We also package dozens of third-party modules. ;)

xeioex commented 1 year ago

@xiaoxiangmoe the image will be updated with new nginx release.

rikatz commented 1 year ago

Hey folks,

I think there's just a small mistake on docs, apparently "delete" is a reserved word and cannot be used as a function name?

When using it as

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

it gives me Unexpected token "delete" while if the function is called "del(r)" it works fine.

jirutka commented 1 year ago

it gives me Unexpected token "delete" while if the function is called "del(r)" it works fine.

So don’t name it delete… Functions can be named delete, but you cannot declare it like this. For example, Foo.prototype.delete = function() { } is allowed.

rikatz commented 1 year ago

I just copied the example from docs, that’s why I’ve commented it :)

jirutka commented 1 year ago

Aha, I see now, you’re right.

@xeioex, where can I find repository for https://nginx.org/en/docs/njs/ ?

xiaoxiangmoe commented 1 year ago

https://nginx.org/en/docs/http/ngx_http_js_module.html#js_shared_dict_zone

js_shared_dict_zone

Sets the name and size of the shared memory zone that keeps the key-value dictionary shared between worker processes.

Is there anything that will define a shared variable between all requests for each single worker process?