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

command suggestion: string "get and delete" #12

Open
mgravell opened this issue May 8, 2017 · 4 comments
Open

command suggestion: string "get and delete" #12

mgravell opened this issue May 8, 2017 · 4 comments

Comments

@mgravell
Copy link

mgravell commented May 8, 2017

Possible suggestion for rxstrings - for context see StackExchange/StackExchange.Redis#622

@mgravell mgravell changed the title string "get and delete" command suggestion: string "get and delete" May 8, 2017
neomantra added a commit to neomantra/redex that referenced this issue Jul 17, 2017
Includes test and documentation.
@neomantra
Copy link
Contributor

So I created this command and called it STRPOP. Is that a decent name?

Should it accept multiple keys?

@itamarhaber
Copy link
Contributor

Name-wise: sounds like a good solid name
Multi-wise: I prefer to do these in a MULTI/EXEC block or Lua... multi-key commands are notoriously and obviously harder to support in a cluster, which leads to these becoming unsupported in it, which is kind of a shame.

Suggestion: what do you think about popping ranges? I.e. if ungiven to STRPOP, the range default to all (i.e. 0 -1), but I can just trim the end (i.e. -1 -1) the beginning (0 0) or anything else I want, LTRIM-like.

@neomantra
Copy link
Contributor

I like your range idea. I see two ways of going with it:

  1. Go very general/flexible. In a way, CHOP is a subset of that range pop, except it doesn't return the value. [I'm chopping 10MB long strings and don't need the result so don't waste time copying/transmitting it.] We could have a command modifier which selects whether to return the value or an integer count. Also you can't CHOP the middle of a string. So we could create one uber-command that can do CHOP, STRPOP, TRIMS, etc.

  2. Go very specific. Have a STRPOP, CHOP, STRPOPRANGE, whatever else. I do like some of the fine-grained aspects.. makes it easy to write stuff without the documentation and code that uses these commands are read clearly.

@neomantra
Copy link
Contributor

How about something like this:

STRPOP key [start [end]] [NODELETE] [LENGTH]

Removes the substring of the string value stored at key and returns it. If the resulting string value is empty, then the key is deleted. This can be overridden with the optional NODELETE argument, which will leave an empty string at key.

The range determined by the offsets start and end (both are inclusive). Negative offsets can be used in order to provide an offset starting from the end of the string. So -1 means the last character, -2 the penultimate and so forth. The function handles out of range requests by limiting the resulting range to the actual length of the string.

start and end are optional and default to 0 and -1. When used with the other default arguments, STRPOP is equivalent to an atomic GET and DEL of key.

Normally, the substring is returned as a reply. If the optional LENGTH argument is specified, the length of the remaining string value is returned instead. This is useful when one doesn't need the results, saving on copies and transfers.

An error is returned if the key exists and does not hold a string.

Reply: String, the substring of key or NULL if key didn't exist. If LENGTH is specified, it is an Integer length of the key's value after the STRPOP operation.

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

3 participants