All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliyun.tair.tairhash.params.ExhincrByParams Maven / Gradle / Ivy

package com.aliyun.tair.tairhash.params;

import redis.clients.jedis.params.Params;
import redis.clients.jedis.util.SafeEncoder;

import java.util.ArrayList;


public class ExhincrByParams extends Params {
    private static final String EX = "ex";
    private static final String EXAT = "exat";
    private static final String PX = "px";
    private static final String PXAT = "pxat";
    private static final String VER = "ver";
    private static final String ABS = "abs";
    private static final String MIN = "min";
    private static final String MAX = "max";
    private static final String NOACTIVE = "noactive";

    public ExhincrByParams() {
    }

    public static ExhincrByParams ExhincrByParams() {
        return new ExhincrByParams();
    }

    public ExhincrByParams ex(int secondsToExpire) {
        if (!contains(EXAT)) {
            addParam(EX, secondsToExpire);
        }
        return this;
    }

    public ExhincrByParams exat(long unixTime) {
        if (!contains(EX)) {
            addParam(EXAT, unixTime);
        }
        return this;
    }

    public ExhincrByParams px(long millisecondsToExpire) {
        if (!contains(PXAT)) {
            addParam(PX, millisecondsToExpire);
        }
        return this;
    }

    public ExhincrByParams pxat(long millisecondsToExpire) {
        if (!contains(PX)) {
            addParam(PXAT, millisecondsToExpire);
        }
        return this;
    }

    public ExhincrByParams ver(long version) {
        addParam(VER, version);
        return this;
    }

    public ExhincrByParams abs(long absoluteVersion) {
        addParam(ABS, absoluteVersion);
        return this;
    }

    public ExhincrByParams max(long max) {
        addParam(MAX, max);
        return this;
    }

    public ExhincrByParams min(long min) {
        addParam(MIN, min);
        return this;
    }

    public ExhincrByParams noactive( ) {
        addParam(NOACTIVE, "");
        return this;
    }

    private void addParamWithValue(ArrayList byteParams, String option) {
        if (contains(option)) {
            byteParams.add(SafeEncoder.encode(option));
            byteParams.add(SafeEncoder.encode(String.valueOf((Object)getParam(option))));
        }
    }

    public byte[][] getByteParams(byte[]... args) {
        ArrayList byteParams = new ArrayList();
        for (byte[] arg : args) {
            byteParams.add(arg);
        }

        addParamWithValue(byteParams, EX);
        addParamWithValue(byteParams, PX);
        addParamWithValue(byteParams, EXAT);
        addParamWithValue(byteParams, PXAT);
        addParamWithValue(byteParams, MAX);
        addParamWithValue(byteParams, MIN);
        addParamWithValue(byteParams, VER);
        addParamWithValue(byteParams, ABS);
        if(contains(NOACTIVE)){
            byteParams.add(SafeEncoder.encode(NOACTIVE));
        }
        return byteParams.toArray(new byte[byteParams.size()][]);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy