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

introduce CAS commands #1033

Open
romange opened this issue Apr 3, 2023 · 3 comments
Open

introduce CAS commands #1033

romange opened this issue Apr 3, 2023 · 3 comments

Comments

@romange
Copy link
Collaborator

romange commented Apr 3, 2023

we should support conditional commands on server side to reduce dependence on lua scripts.

Inspiration: redlock https://redis.io/docs/manual/patterns/distributed-locks/ implementations that use

 if redis.call("get",KEYS[1]) == ARGV[1] then
        return redis.call("del",KEYS[1])
    else
        return 0
    end'

there are more - TBD

@dranikpg
Copy link
Contributor

dranikpg commented Apr 5, 2023

  1. Instead of extending separate commands, I'd look into separate commands for MULTI/EXEC to allow simple conditional aborts and conditional skips. Many scripts can be reduced to such multi tx'es with such conditional checks and maybe simple if's

  2. There is already WATCH and the script from your example could be replaced with watch in theory, but now with two round trips the delete op can be much more costly

  3. We can look into a simple optimizer for lua scripts that together with the squasher will predict the shard flow of the script.

for example, if we have

if redis.call('CMD-1', key1) then
  redis.call('CMD-2', key1)

then the executor can "infere" that the next key access will to the very same key (thus on the same shard), so it can execute the script interpreter right after the command without returning from the hop

@romange
Copy link
Collaborator Author

romange commented Apr 5, 2023 via email

@dranikpg
Copy link
Contributor

dranikpg commented Apr 5, 2023

  1. We'll just pass the interpreter. The squashed executor will have all the context

  2. In what sense is the problem hops? Do you mean that we can't squash a conditional? Yes, its true in general and its a problem for long sequences. But if all squashed commands are on one shard, we can do it. It's not difficult to detect.

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

2 participants