Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time filter for shdict get_keys #2305

Open
Rockybilly opened this issue Apr 18, 2024 · 2 comments
Open

time filter for shdict get_keys #2305

Rockybilly opened this issue Apr 18, 2024 · 2 comments

Comments

@Rockybilly
Copy link

I have stumbled on a use case where I need to get to most recent items from the shared dict on the get_keys method. For example the ones added in the last 60 seconds. I didn't find a way yet, probably has to be implemented. I think of two ways.

  1. Add a creation_time to the ngx_http_lua_shdict_node_t struct, but I didn't go through all the code to say that this is really needed. This doesn't seem favorable as it increases the memory usage,
  2. add a parameter to get_keys function like ttl_remaining_above? so that this value can be used as a condition while getting the keys (expiry_time - now > param). This seems easier to implement and less taxing.

I think this would be a nice addition, what do you think?

@tzssangglass
Copy link
Contributor

in your case, you could perhaps add a shared dictionary named recent_keys. when writing data to other shared dictionaries, also write a key with a TTL of 60 seconds to recent_keys. this way, when you need to retrieve keys written in the past 60 seconds, you can use recent_keys:get_keys().
just an idea.

@Rockybilly
Copy link
Author

in your case, you could perhaps add a shared dictionary named recent_keys. when writing data to other shared dictionaries, also write a key with a TTL of 60 seconds to recent_keys. this way, when you need to retrieve keys written in the past 60 seconds, you can use recent_keys:get_keys(). just an idea.

Yes I thought of this. Also looping through all keys and getting all the ttl values and do like ttl_init - ttl type of filtering, however first one is not flexible if I want to filter by a parameter, and second one is just inefficient.

As I go through the docs I feel more like ngx.shared.DICT is lacking very trivial features although it was implemented a long time ago :) Just a comment and not a criticism.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants