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

The match spec in the doc should be of size 5 instead of size 4 #146

Closed
blisscs opened this issue Feb 24, 2022 · 4 comments
Closed

The match spec in the doc should be of size 5 instead of size 4 #146

blisscs opened this issue Feb 24, 2022 · 4 comments

Comments

@blisscs
Copy link

blisscs commented Feb 24, 2022

Recently, we had to update our app from using nebulex from 1.2.2 which was running on elixir 1.8.2 and otp 22.0 to nebulex version 2.3.0 on elixir 1.12 and otp 24.0. We were facing errors that our Ex2ms queries that we were using in the form of a tuple of four values {key, value, version, expire_at} got failed.

I've looked everywhere including hex document, elixirforum, and other sources of what could go wrong. but eventually, I found out in the spec that we are supposed to use is a tuple of 5 values instead.

test_ms =
fun do
{_, _, value, _, _} when value > 10 -> value
end

So we updated our code according to use tuples of 5 values instead. And our tests got passed successfully.

Could you explain more in term of a tuple of 5 values what each value are? As my current try I found out that only that what are the value for key, value and expire_at which are in the form of {_, key, value, expire_at, _}. I wonder what are the rest of the two values are.

And also please let's me know if you need me to make a pull request to update the doc also.

@cabol
Copy link
Owner

cabol commented Feb 24, 2022

Hey! First of all, sorry about that, I was checking out the docs and there are parts outdated, so that is an issue, I will try to fix the docs accordingly. Regarding the tuple, in the local adapter, the entry is an Elixir record, like so:

defrecord(:entry,
    key: nil,
    value: nil,
    touched: nil,
    ttl: nil
  )

This means it would be a tuple with 5 element like so: {:entry, key, value, touched, ttl}.

There is also an example in the docs c:Nebulex.Cache.all/2

Please let me know if that helps, and also I will try to fix the wrong docs ASAP. Thanks!

@blisscs
Copy link
Author

blisscs commented Feb 24, 2022

Thank you very much Cabol.
I already edited the code to make things work.

I have some questions concerning checking for expiry.
Since I see from the code that if I want to check if a record is already expired. using the query How do I check it.
I will have to check with something like below right?

Nebulex.Time.now() > (touched + ttl)

Or I can just skip that expiry check since the query will guarantee that I will always get unexpired results.

@cabol
Copy link
Owner

cabol commented Feb 24, 2022

You have to validate it in the query. There is a build-in query for retrieving the unexpired entries MyApp.Cache.all:unexpired), so maybe you can do something similar by adding that unexpired condition plus the ones you want. For example:

spec = [
  {{:entry, :"$1", :"$2", :_, :_},
  [{:orelse, {:==, :"$4", :infinity}, {:<, {:-, Nebulex .Time.now(), :"$3"}, :"$4"}}],
  [{{:"$1", :"$2"}}]}
]

MyCache.all(spec)

@blisscs
Copy link
Author

blisscs commented Feb 25, 2022

Thank you Cabol I will try what you suggested.

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