week11/redis-lock-counter/src/main/java/cluster/redis/controller/CounterController.java
/**
     * incr or decr an counter
     *
     * @param counter counter name
     * @param method  incr/decr
     * @param volume  volume to update
     * @return
     */
incr or decr an counter
@param counter counter name
@param method  incr/decr
@param volume  volume to update
@return
incr or decr an counter @param counter counter name @param method incr / decr @param volume volume to update @return
@PostMapping("/{counter}")
    public Long updateCounter(@PathVariable("counter") final String counter,
                              @PathParam("method") final String method,
                              @PathParam("volume") final Long volume) {
        final String storeKey = "store-item-storeKey";
        try {
            locker.lock(storeKey);
            final DistributedCounter distributedCounter = new DistributedCounter(counter, jedis);
            Long delta = volume;
            if (delta == null) delta = 1L;
            if ("incr".equalsIgnoreCase(method)) {
                return distributedCounter.increment(delta);
            } else if ("decr".equalsIgnoreCase(method)) {
                return distributedCounter.decrement(delta);
            } else {
                throw new HttpClientErrorException(HttpStatus.BAD_REQUEST);
            }
        } finally {
            locker.unlock(storeKey);
        }
    }
@ PostMapping ( "/{counter}" ) public Long updateCounter ( @ PathVariable ( "counter" ) final String counter , @ PathParam ( "method" ) final String method , @ PathParam ( "volume" ) final Long volume ) { final String storeKey = "store-item-storeKey" ; try { locker . lock ( storeKey ) ; final DistributedCounter distributedCounter = new DistributedCounter ( counter , jedis ) ; Long delta = volume ; if ( delta == null ) delta = 1L ; if ( "incr" . equalsIgnoreCase ( method ) ) { return distributedCounter . increment ( delta ) ; } else if ( "decr" . equalsIgnoreCase ( method ) ) { return distributedCounter . decrement ( delta ) ; } else { throw new HttpClientErrorException ( HttpStatus . BAD_REQUEST ) ; } } finally { locker . unlock ( storeKey ) ; } }
incr or decr an counter
 @param counter counter name
 @param method  incr/decr
 @param volume  volume to update
 @return
incr or decr an counter @param counter counter name @param method incr / decr @param volume volume to update @return
// update db incr + // update db decr -