Skip to content

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

Open
@haohetao

Description

@haohetao

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions