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

Support configuring custom keys via method invocation #84

Merged
merged 2 commits into from
Apr 25, 2022

Conversation

jorgemanrubia
Copy link
Collaborator

@jorgemanrubia jorgemanrubia commented Apr 13, 2022

This adds support to generate keys via a method name passed as a symbol:

class Person
  kredis_list :names, key: :generate_key

  private
    def generate_key
      "some generated key"
    end
end

Currently, the only way to customize keys is via a lambda, lilke key: ->(p) { "person:#{p.id}:names_customized" }. The problem with that approach is that, when you want to invoke a method to determine the key, you need to make that method public. This is also a more concise way of covering a pretty common use case: using an instance method to determine keys.

@jeremy jeremy merged commit cbdc2cc into rails:main Apr 25, 2022
@jeremy jeremy deleted the key-method branch April 25, 2022 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants