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

Values with linefeeds (\n) don't work properly #51

Open
alexdpoon opened this issue Jul 5, 2018 · 5 comments
Open

Values with linefeeds (\n) don't work properly #51

alexdpoon opened this issue Jul 5, 2018 · 5 comments

Comments

@alexdpoon
Copy link

When I set something into memcache where the value is a multi-lined string (delimiter of \n), when I get the value back, it contains only the last line.

@victorquinn
Copy link
Owner

Oh no, that's not great! This has to do with the line-level protocol we are using for interfacing with Memcache -- a new line will break it.

Need to find a good solution here. We could convert all \n to something else, then back when we pull it out, however doing that may break integrations with other systems. We should probably audit how other Memcache libraries deal with this and do the same.

Anyway, for your purposes until we can roll out a fix, you could convert \n to something else, then back when you pull out though I know this isn't ideal long-term

@alexdpoon
Copy link
Author

Ok, I hacked a solution together for what I'm doing. Rather than replacing the \n's with an arbitrary string and converting back (which is slow for very large strings), I instead wrap up the string in an object and unwrap it on retrieval.

So when I set the value, I do:

if (typeof value == 'string' && value.includes('\n')) value = { _alex_hack: value }

And then when I get the value I do:

if (typeof data == 'object' && data._alex_hack != null) data = data._alex_hack

I wonder if this is an approach you could take.

@niwinz
Copy link

niwinz commented Aug 1, 2018

memcache already returns the size of the stored value, you don't need to parse the line, just read the N bytes that memcache is reporting...

@ryanrubleycoates
Copy link

memcache already returns the size of the stored value, you don't need to parse the line, just read the N bytes that memcache is reporting...

Have you found any NodeJS modules that implement this properly? We ran into serious issues using memcache-plus or the forked memcache-pp when the value is an empty string or literally the string "END" because of the parsing here which does not use the length in the VALUE response at all.

@ryanrubleycoates
Copy link

I fixed this in https://github.com/ryanrubleycoates/memcache-ppp to read the proper number of bytes and not mangle newlines. It can still be made to work with carrier with a few changes here and there.

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

No branches or pull requests

4 participants