| package com.mzl.flower.service.payment; | 
|   | 
| import com.mzl.flower.service.BaseService; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.data.redis.core.RedisTemplate; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.transaction.annotation.Transactional; | 
|   | 
| import java.util.concurrent.TimeUnit; | 
|   | 
| @Service | 
| @Transactional | 
| public class RedisLockService extends BaseService { | 
|   | 
|     @Autowired | 
|     private RedisTemplate<String, String> redisTemplate; | 
|   | 
|     public static final String LOCK_KEY_PAYMENT_NOTIFY_ = "LOCK_KEY_PAYMENT_NOTIFY_"; | 
|     public static final String LOCK_KEY_CART_ = "LOCK_KEY_CART_"; | 
|   | 
|     public boolean getObjectLock(String key, String objectId){ | 
|         String kk = key + objectId; | 
|         return redisTemplate.opsForValue().setIfAbsent(kk, "1", 30, TimeUnit.SECONDS); | 
|     } | 
|   | 
|     public void releaseObjectLock(String key, String objectId){ | 
|         String kk = key + objectId; | 
|         redisTemplate.delete(kk); | 
|     } | 
|   | 
| } |