Skip to content

Remove Redis.exists warning#46

Merged
claudioprocore merged 1 commit intoprocore-oss:masterfrom
claudioprocore:fix_exists
Jun 10, 2021
Merged

Remove Redis.exists warning#46
claudioprocore merged 1 commit intoprocore-oss:masterfrom
claudioprocore:fix_exists

Conversation

@claudioprocore
Copy link
Copy Markdown
Contributor

This commit removes the following warning when using the gem

Redis#exists(key) will return an Integer in redis-rb 4.3. exists?
returns a boolean, you should use it instead. To opt-in to the new behavior
now you can set Redis.exists_returns_integer = true. To disable this message
and keep the current (boolean) behaviour of 'exists' you can set
Redis.exists_returns_integer = false, but this option will be removed in 5.0.

@bpross
Copy link
Copy Markdown

bpross commented Jun 10, 2021

Can you add a comment to the changelog?

This commit removes the following warning when using the gem

> `Redis#exists(key)` will return an Integer in redis-rb 4.3. `exists?`
> returns a boolean, you should use it instead. To opt-in to the new behavior
> now you can set Redis.exists_returns_integer =  true. To disable this message
> and keep the current (boolean) behaviour of 'exists' you can set
> `Redis.exists_returns_integer = false`, but this option will be removed in 5.0.
@claudioprocore
Copy link
Copy Markdown
Contributor Author

@bpross Thanks! Can you ping me when a new version of this gem is released?
I would need it for https://github.com/procore/dev-portal/pull/2370

@bpross
Copy link
Copy Markdown

bpross commented Jun 10, 2021

@claudioprocore will do. Once this is approved: #45 we will be pushing out a new release.

@claudioprocore claudioprocore merged commit d36bad5 into procore-oss:master Jun 10, 2021
@claudioprocore claudioprocore deleted the fix_exists branch June 10, 2021 16:37

def fetch
return unless redis.exists(redis_key)
return unless redis.exists?(redis_key)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could bypass the issue and instead of hitting redis with an exists followed by a get (which returns nil if the key is not present, just ask for it.

json_token = redis.get(redis_key) || return
token = JSON.parse(json_token)
...

or

json_token = redis.get(redis_key)
return if json_token.nil?

token = JSON.parse(json_token)
...

whichever feels cleaner to you

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

Successfully merging this pull request may close these issues.

3 participants