-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
using the results of "KEYS" when a keyPrefix
option is being used
#381
Comments
There're already several related issues posted: #254 #359 #325. A warning is added to the "Transparent Key Prefixing" section in README for this matter. Currently I'm not planning to add support for prefixing patterns and replies given it's not a good practice to use key prefix as namespace to allow multiple applications share a same redis database. PS - thank you for using ioredis 😆 |
hi, I was aware of the related issues and the relevant part of the README. I am confused about your second comment ... are you saying it is NOT good practice to use a So is your advice to not use a |
Like @iamjochem, I too am confused. From reading and watching talks about Redis I was under the impression that name spacing was recommended. |
Name spacing is recommended only when it's used in the same application. For example, it's useful to store users and posts details in the same database by prefixing them with
userRedis.set(`${id}.name`, 'bob')
postRedis.set(`${id}.name`, 'Welcome to the WordPress') In the above case, However, it's not recommended to have multiple application sharing the same database:
You should setup a single Redis database for each application. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 7 days if no further activity occurs, but feel free to re-open a closed issue if needed. |
hi there,
when a
keyPrefix
option is used is becomes a little tricky to work with the KEYS command:that match
the following example shows searching for keys and then attempting to deleting them (nothing is deleted because
redis.del()
will actually attempt to delete "foo:foo:bar:baz")I think it would be nice if
redis.keys()
supported a second argument of options so that you could do something like this (I'm hoping that the suggestedkeysOptions
are self explanatory):Granted you may not agree with this idea, regardless I'm interested to know if you have any suggestions/advice for using the results of "KEYS" when a
keyPrefix
option is being used.Currently I'm using something akin to the following for stripping the
keyPrefix
value from the returned keys (bare in mind that thekeyPrefix
may contain a regex meta-character that needs to be escaped):IMO this is a bit inelegant (and error prone) to have to always do this in consuming code.
rgds,
Jochem
PS - enjoying using your lib, especially the
defineCommand
functionality! nice work!The text was updated successfully, but these errors were encountered: