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

Modification in rpoplpush command #29

Closed
wants to merge 4 commits into from
Closed

Conversation

aallamaa
Copy link

Hello Antirez/Salvatore,

I have made a modification to the rpoplpush command, in the modification i am allowing a third optional parameters which will provide the following behavior:

allow as an option a third argument which would be pushed as new element
on the destination list instead of pushing the popped element.

RPOPLPUSH srclist dstlist element2:

IF LLEN(srclist) > 0
element = RPOP srclist
LPUSH dstlist element2
RETURN element
ELSE
RETURN nil
END
END

This is very useful in my opinion to provide a way to atomically remove an element from a list and pass a new one to another list.

Let me provide an example.

Script A receive an element to be processed on list_A.

Script a uses the traditional rpoplpush this way element = rpoplpush list_A list_A_processing.

The script is processing element, and modifying it.

Once the modification is done we need to atomically remove the element from list_A_processing and pass the modified element to another list so that script B can process the newly modified element.

So script will use the modified way of rpoplpush this way. rpoplpush list_A_processing list_B newelement

This is the only way in my understanding to pass the element to the other script (using redis of course) and at the same time remove it from the processing list without risking to break the atomicity of this action.

Imagine the script is killed in the middle of this operation (pop and then push, or push and then pop) we would have an issue of integrity.

I know this will affect brpoplpush but I think it will also be beneficial to it.

By the way I am not an expert in git/github so i dont know how to remove from this pull request the other pull request i have made regarding the list command.

Thanks in advance,
Kader

Python Example:

import desir

r=desir.Redis()

r.keys("*")

[]

r.lpush("list1","message 1")

1

r.rpoplpush("list1","list2")

'message 1'

r.rpoplpush("list2","list1")

'message 1'

r.rpoplpush("list1","list2","message 2")

'message 1'

r.rpoplpush("list2","list1")

'message 2'

… taken from readonlyCommandTable.

The parameter provided are name, arity, flags, vm_firstkey, vm_lastkey, vm_keystep
allow as an option a third argument which would be pushed as new element
on the destination list  instead of pushing the popped element.
  RPOPLPUSH srclist dstlist element2:
   IF LLEN(srclist) > 0
     element = RPOP srclist
     LPUSH dstlist element2
     RETURN element
   ELSE
     RETURN nil
   END
  END
@joshtriplett
Copy link

This seems like something better done with a custom transaction, rather than modifying rpoplpush.

@aallamaa
Copy link
Author

aallamaa commented Jan 7, 2011

yes that´s true, but it was so easy to modify the redis code to do it rather than make a few transactions :)
By the way you can see this custom transaction in https://github.com/aallamaa/desir/blob/master/desir/desir.py line 251-255

@s-tchaikovsky s-tchaikovsky mentioned this pull request Jul 26, 2013
ncopa pushed a commit to ncopa/redis that referenced this pull request Jan 7, 2016
@badboy badboy closed this Jul 3, 2017
KFilipek pushed a commit to KFilipek/redis that referenced this pull request Apr 18, 2018
info memory command extended to show memory allocated using memkind
fadidahanna added a commit to sjpotter/redis that referenced this pull request Feb 16, 2023
Co-authored-by: Hanna Fadida <hanna.fadida@redislabs.com>
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

Successfully merging this pull request may close these issues.

None yet

4 participants