Class BootCache_RedisImple
java.lang.Object
org.summerboot.jexpress.integration.cache.BootCache_RedisImple
- All Implemented Interfaces:
Comparable,HealthInspector,AuthTokenCache,BootCache
1. download redis-cell from https://github.com/brandur/redis-cell/releases 2.
unzip 3. redis-cli>module load /path/to/libredis_cell.so
- Author:
- Changski Tie Zheng Zhang 张铁铮, 魏泽北, 杜旺财, 杜富贵
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.summerboot.jexpress.boot.instrumentation.HealthInspector
HealthInspector.InspectionType -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final org.apache.logging.log4j.Loggerprotected static final Stringprotected static final Stringprotected static final Stringprotected PostOfficeprotected static final RuntimeExceptionprotected static final Stringprotected static RedisConfigprotected static final Longprotected static final ThreadPoolExecutorFields inherited from interface org.summerboot.jexpress.boot.instrumentation.HealthInspector
retryIndex -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voidprotected voidprotected voidlongflashsaleAcquireQuota(String itemId, long requestAmount) flash sale - order competition before reducing inventoryvoidflashsaleEnable(String itemId, boolean isEnabled) flash sale - enablebooleanflashsaleInventoryInit(String itemId, long totalAmount, long limit) flash sale - init inventoryflashsaleInventoryReport(String itemId) flash sale - inventory reportlongflashsaleRevokeQuota(String itemId, long requestAmount) flash sale - revoke an order (undo order competition, normally happens when failed to pay within N minutes)booleanisBlacklist(String key) protected voidonNoticeAutoFailover(String info, String newNode) protected voidonNoticeRedisDown(String info, Throwable ex) protected voidonRedisDown(Throwable ex) longrateLimiterGetSlidingWindowRate(String key, int periodSecond) Deprecated.longrateLimiterGetWaitTime(String key, int initBurst, int maxBurstPerPeriod, int period, int requestQuota) Require Redis 4.0+ and Redis-CellbooleantryLock(String lockName, String unlockPassword, long ttlToExpireIncaseUnableToUnlock, TimeUnit timeUnit) this is a Distributed non-blocking version of lock() method; it attempts to acquire the lock immediately, return true if locking succeedsbooleanunlocks the Distributed Lock instanceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.summerboot.jexpress.integration.cache.AuthTokenCache
pingMethods inherited from interface org.summerboot.jexpress.integration.cache.BootCache
debounced, generateUnlockPasswordMethods inherited from interface org.summerboot.jexpress.boot.instrumentation.HealthInspector
compareTo, inspectionType, logLevel, pauseLockCode
-
Field Details
-
LUA_SCRIPT_UNLOCK
- See Also:
-
LUA_SCRIPT_THROTTLE
- See Also:
-
LUA_SCRIPT_FLASHSALE
- See Also:
-
REDIS_SUCCESS
- See Also:
-
RELEASE_SUCCESS
-
log
protected static final org.apache.logging.log4j.Logger log -
tpe
-
REDIS_MASTER_NULL_EX
-
redisCfg
-
po
-
-
Constructor Details
-
BootCache_RedisImple
public BootCache_RedisImple()
-
-
Method Details
-
execute
-
execute
-
executeEx
-
onRedisDown
-
onNoticeRedisDown
-
onNoticeAutoFailover
-
tryLock
public boolean tryLock(String lockName, String unlockPassword, long ttlToExpireIncaseUnableToUnlock, TimeUnit timeUnit) this is a Distributed non-blocking version of lock() method; it attempts to acquire the lock immediately, return true if locking succeeds- Specified by:
tryLockin interfaceBootCache- Parameters:
lockName- the name of the tryLockunlockPassword- unlockPassword is to be used for unlock. To protect a tryLock from being unlocked by anyone, a tryLock cannot be released when unlockPassword not matchttlToExpireIncaseUnableToUnlock- expire time of tryLock in case unable to unlock (e.g. exception/error before executing unlock)timeUnit-- Returns:
- the result of get tryLock
-
unlock
unlocks the Distributed Lock instance -
blacklist
- Specified by:
blacklistin interfaceAuthTokenCache
-
isBlacklist
- Specified by:
isBlacklistin interfaceAuthTokenCache
-
flashsaleInventoryInit
Description copied from interface:BootCacheflash sale - init inventory- Specified by:
flashsaleInventoryInitin interfaceBootCache- Parameters:
itemId-totalAmount- total inventorylimit- max orderAmount per order- Returns:
- true if success
-
flashsaleInventoryReport
Description copied from interface:BootCacheflash sale - inventory report- Specified by:
flashsaleInventoryReportin interfaceBootCache- Parameters:
itemId-- Returns:
-
flashsaleEnable
Description copied from interface:BootCacheflash sale - enable- Specified by:
flashsaleEnablein interfaceBootCache- Parameters:
itemId-isEnabled- sale enabled if true, else disabled
-
flashsaleAcquireQuota
Description copied from interface:BootCacheflash sale - order competition before reducing inventory- Specified by:
flashsaleAcquireQuotain interfaceBootCache- Parameters:
itemId-requestAmount-- Returns:
- confirmed order amount
-
flashsaleRevokeQuota
Description copied from interface:BootCacheflash sale - revoke an order (undo order competition, normally happens when failed to pay within N minutes)- Specified by:
flashsaleRevokeQuotain interfaceBootCache- Parameters:
itemId-requestAmount-- Returns:
- the updated inventory booked amount
-
rateLimiterGetWaitTime
public long rateLimiterGetWaitTime(String key, int initBurst, int maxBurstPerPeriod, int period, int requestQuota) Require Redis 4.0+ and Redis-Cell- Parameters:
key-initBurst-maxBurstPerPeriod-period- secondsrequestQuota-- Returns:
- The number of seconds until the user should retry, and always -1 if the action was allowed
-
rateLimiterGetSlidingWindowRate
Deprecated.Only good for: low rate, check if a user input wrong password more than X times within N minutes.Not good for: high rate
1. Implemented via ZSet, will keep a record/access, not memory friendly for high volumn access.
2. Not atomic, not accurite with high concurrent access
3. result is based on current burst ratet, it won't return true if the burst rate keeps high, no matter how long it lasts
- Parameters:
key-periodSecond-- Returns:
- the burst rate of the current period window
-