Hello! I've posted message to
openresty-en@googlegroups.com but do not get answer so address it agai to you:
> Thank you. Global variable in shared dict is ok but if I understand it correctly there are multiple lua threads in one nginx worker so synchronizaition is needed. I've looked for synchronization library for openresty to do mutex-like logic
Please tell my the way to synchronize access to variable to get unique id among nginx workers and multiple (if there are multiple?) lua threads in the same nginx-locations content-by-lua-sections.
Also I'v got the error while doing set-keepalive at mysql connection: cannot put connection in this state: 2. What state is it?
> Best regards, Kosenko Vitaly
>
> ---------- Forwarded message ----------
> From: Yichun Zhang (agentzh) <
age...@gmail.com>
> Date: 2015-03-20 0:33 GMT+05:00
> Subject: Re: Question about resty-lock
> To: Vitaly Kosenko <
vitaly...@gmail.com>
>
>
> Hello!
>
> On Thu, Mar 19, 2015 at 5:07 AM, Vitaly Kosenko wrote:
>>
>> How do I understand if lock is free or not?
>>
>
> If you mean checking if a lock is free or not without waiting. Then
> you can just use a zero timeout value and wait() on it. If the wait()
> succeeds, then you know it's free (and then immediately release the
> lock if you don't really need it yourself).
>
>> For information: I need a logic of generating unique id in web server using openresty.
>> As a simpliest way I want to use single variable for id and get its current value and
>> increment it in one atomic operation
>
> I don't know why this is related to lua-resty-lock. Usually you just
> generate a UUID with some existing libraries or just use shared dict
> to maintain a global counter (on the level of a single server, for
> multiple servers, just append the server ID like its hostname to the
> counter to make it truly globally unique).
>
> BTW, please join the openresty-en mailing list for such discussions
> instead of sending emails directly to me. Thank you for your
> cooperation! Please see
http://openresty.org/#Community for more
> details.
>
> Best regards,
> -agentzh
>
> Regards,
> -agentzh
>
>