You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?php
|
|
|
|
class RedisTool {
|
|
|
|
private static $bizRedis = null;
|
|
|
|
const redisLockDefaultExpireTime = 300;
|
|
|
|
private static function getBizRedis() {
|
|
if (empty(self::$bizRedis)) {
|
|
self::$bizRedis = RedisExt::factory('bizCache');
|
|
}
|
|
return self::$bizRedis;
|
|
}
|
|
|
|
public static function addProductToDsItemLock($productId, $intExpireTime = self::redisLockDefaultExpireTime) {
|
|
if (empty($productId) || $intExpireTime <= 0) {
|
|
return false;
|
|
}
|
|
$bizRedis = self::getBizRedis();
|
|
$strKey = self::getProductToDsItemLock($productId);
|
|
$res = $bizRedis->set($strKey, 1, ['nx', 'ex' => $intExpireTime]);
|
|
return $res;
|
|
}
|
|
|
|
private static function getProductToDsItemLock($productId) {
|
|
return sprintf('productToDsItemLock_%s', $productId);
|
|
}
|
|
|
|
public static function releaseProductToDsItemLock($productId) {
|
|
if (empty($productId)) {
|
|
return false;
|
|
}
|
|
$bizRedis = self::getBizRedis();
|
|
$strKey = self::getProductToDsItemLock($productId);
|
|
|
|
return $bizRedis->del($strKey);
|
|
}
|
|
} |