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
Default port to 11211 #222
Conversation
@@ -129,6 +129,12 @@ Client.config = { | |||
} | |||
|
|||
// No connection factory created yet, so we must build one | |||
|
|||
// Default port to 11211 | |||
if(!server.match(/(.*):(\d+){1,}$/)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the (.*)
adds nothing to the expression (since you're not pegging the expression to the starting point of the string). Also not sure what the point of the {1,}
is here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The (.*) is to match any IP address that is defined when connecting. The {1,} is for (\d+), in other words (\d+){1,}$ is to detect any presence of port number. If no port number is detected regardless of any IP address, the 11211 will be appended as default port. Actually i just used the same regular expression as originally defined in line 140.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks. It's good to know where that regex originated.
You don't see anything wrong with it though?
(.*)
does not match IP addresses (or really anything for that matter), right?
And {,1}
seems redundant to me, am I wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(.*) is required to detect not only IP address e.g. 127.0.0.1 but also domain name e.g. mymemcached.example.com. You are right, {1,} is redundant because the + is actually equivalent to {1,}. Let me update the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.*
literally means "any type of character, repeated zero or more times". It adds nothing to the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then let's use (.+) expression. I just pushed up an update.
Could you add a unit test to prove this works? I think there's already a test file around connections that you could extend. |
Sure, i just pushed up the unit test for it. |
I think that an ipv6 address will break horribly by this |
Correct me if i'm wrong but i think node-memcached currently doesn't support ipv6 address...yet. i don't see any related tests or examples. Are we going to provide ipv6 support in the upcoming new versions? If yes, how can i update this current change to fit into the big picture? |
i did a quick test on node REPL:-
My part can still handle ipv6 address unless maybe i have to do more thorough tests. |
Why on earth would it break ip6? Before the colon it'll match any character(s). In case of doubt, just augment the unit test to have a wide variation of host types (domain name, ipv4, ipv6), and no matter how people change this regex, your test will find breakage. |
@ronkorving I must have been looking at old cold as I thought it assume that numbers that are followed after a |
Here we go! :) |
Thanks @jolks |
Cheers @ronkorving and @3rd-Eden ! |
This code is breaking when I passed multiple hosts as an array |
@kmanoraj The (private) |
Update for Default port to 11211 in URLs #207