-
Notifications
You must be signed in to change notification settings - Fork 228
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
model name prefix is not always unique #231
Comments
Nested class names are a problem because I stole the original code from Sinatra, and unfortunately I didn't notice that it cropped the class down past the final |
I finally have an idea. If we bumped the version to |
@nateware I think you might want to provide this as an option at the object level as well so that if you were using redis objects for a namespaced class upgrading wouldnt break existing code. Meaning you can turn on new behavior and get benefits of namespaced keys without breaking currently functioning code in your app. |
Good point. How about at the class level? Eg a class could set
self.long_namespace = false
…On Fri, Nov 15, 2019 at 9:02 PM Artin Boghosian ***@***.***> wrote:
@nateware <https://github.com/nateware> I think you might want to provide
this as an option at the object level as well so that if you were using
redis objects for a namespaced class currently upgrading would break
existing code. Meaning you can turn on new behavior and get benefits of
namespaced keys without breaking currently functioning code in your app.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#231?email_source=notifications&email_token=AAABZIHZYFZ2VLFWSYQWR3TQT55HLA5CNFSM4FSPDI62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEHJUFI#issuecomment-554605077>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAABZIFMCRQQAAJ5I4HCSU3QT55HLANCNFSM4FSPDI6Q>
.
|
@nateware class level makes sense. Although it's probably an edge case this still wouldn't support existing namespaced classes with a mixture of new and old functionality. Say you add redis type after upgrading and want new definition to use namespaced keys even though existing ones wouldn't without migrating. Maybe we don't care about this but thought it might be worth mentioning. If we did care than it might make sense to add option at the instance level when defining new redis types on class. |
Like @khiav223577 said, developer barely cannot notice that models in different namespace could have same name. We set redis_prefix in every included class, If the new one does not know to set this, there will be problems. Still think that using model_name by default is not very reasonable. |
By the way, why redis_prefix should use sub and gsub? def redis_prefix(klass = self) #:nodoc:
@redis_prefix ||= klass.name.to_s.
sub(%r{(.*::)}, '').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
downcase
end Can we just change it as follow: def redis_prefix(klass = self) #:nodoc:
@redis_prefix ||= klass.name.to_s.
gsub(/::/, '_').
downcase
end |
Update on the design to fix this longstanding issue. The new code for def modern_redis_prefix(klass = self) #:nodoc:
klass.name.to_s.
gsub(/::/, '__'). # Nested::Class => Nested__Class
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). # ClassName => Class_Name
gsub(/([a-z\d])([A-Z])/,'\1_\2'). # className => class_Name
downcase
end The reason I chose class Group::PlayerType # group__player_type
class GroupPlayer::Type # group_player__type To cause the legacy key naming behavior, there is a new flag class MyClass
include Redis::Objects
self.redis_legacy_naming = true A warning will be emitted if This is being developed in the |
Backwards incompatible change to redis_prefix to address longstanding bug #231
This has been fixed in |
Also fixed in |
The document here says:
But if two models in different namespace have same name. The generated key will be the same.
For example:
The text was updated successfully, but these errors were encountered: