Skip to content

redis加错未采用原子操作 #1

Description

@li-shaoke
boolean isSuccess = redisTemplate.opsForValue().setIfAbsent(businessKey, uniqueValue);
        if (!isSuccess) {
            throw new Exception("You can't do it,because another has get the lock =-=");
        }
        redisTemplate.expire(businessKey, annotation.lockTime(), TimeUnit.SECONDS);

这块redis操作,不是原子的,如果在设置过期时间前,突然宕机了,则加锁后的key将长时间存在,
应该用
Boolean setIfAbsent(K key, V value, long timeout, TimeUnit unit);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions