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

The save() method is non-atomic and primary keys can be repeat #220

Open
haohetao opened this issue Jan 8, 2021 · 1 comment
Open

The save() method is non-atomic and primary keys can be repeat #220

haohetao opened this issue Jan 8, 2021 · 1 comment
Labels
status:ready for adoption Feel free to implement this issue. type:enhancement Enhancement

Comments

@haohetao
Copy link

haohetao commented Jan 8, 2021

What steps will reproduce the problem?

The save() method is non-atomic, various problems can occur in highly concurrent operations.
and it's inefficient.

What's expected?

Use the Lua script to implement the save operation, and primary keys must be unique.

What do you get instead?

Refactoring the insert method in ActiveRecord class.

$luaScript = <<<EOF
if redis.call('EXISTS', $key) == 0 then
    redis.call('RPUSH', $prefixKey, $pkKey)
end
redis.call('HMSET', $setArgs)
return 1
EOF;

Additional info

Q A
Yii vesion 2.0.40
PHP version 8.0.1
Operating system docker
@haohetao haohetao changed the title The save() method is non-atomic and primary keys cant be repeat The save() method is non-atomic and primary keys can be repeat Jan 8, 2021
@samdark samdark added the type:enhancement Enhancement label Jan 11, 2021
@samdark
Copy link
Member

samdark commented Jan 11, 2021

Sounds interesting. How about preparing a pull request with tests and implementation?

@samdark samdark added the status:ready for adoption Feel free to implement this issue. label Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready for adoption Feel free to implement this issue. type:enhancement Enhancement
Projects
None yet
Development

No branches or pull requests

2 participants