com.aliyun.tair.tairts.params.ExtsAttributesParams Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of alibabacloud-tairjedis-sdk Show documentation
Show all versions of alibabacloud-tairjedis-sdk Show documentation
Aliyun Tair Redis client for Java
Copyright (C) Alibaba Cloud Computing
All rights reserved.
版权所有 (C)阿里云计算有限公司
http://www.aliyun.com
package com.aliyun.tair.tairts.params;
import redis.clients.jedis.params.Params;
import redis.clients.jedis.util.SafeEncoder;
import java.util.ArrayList;
import static redis.clients.jedis.Protocol.toByteArray;
public class ExtsAttributesParams extends Params {
private static final String UNCOMPRESSED = "UNCOMPRESSED";
private static final String DATA_ET = "DATA_ET";
private static final String CHUNK_SIZE = "CHUNK_SIZE";
private static final String LABELS = "LABELS";
/**
* set the skey if compressed.
* @return SetParams
*/
public ExtsAttributesParams uncompressed() {
addParam(UNCOMPRESSED);
return this;
}
/**
* Set the specified expire time, in milliseconds.
* @param millisecondsToExpire
* @return SetParams
*/
public ExtsAttributesParams dataEt(long millisecondsToExpire) {
addParam(DATA_ET, millisecondsToExpire);
return this;
}
/**
* Set the skey's chunk size: 256~1024.
* @param maxDataPointsPerChunk
* @return SetParams
*/
public ExtsAttributesParams chunkSize(long maxDataPointsPerChunk) {
addParam(CHUNK_SIZE, maxDataPointsPerChunk);
return this;
}
/**
* Set the skey's labels.
* @param labels
* @return SetParams
*/
public ExtsAttributesParams labels(ArrayList labels) {
addParam(LABELS, labels);
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))));
}
}
private void addParamWithLabel(ArrayList byteParams, String option) {
if (contains(option)) {
byteParams.add(SafeEncoder.encode(option));
ArrayList labels = (ArrayList)getParam(option);
for (String label : labels) {
byteParams.add(SafeEncoder.encode(label));
}
}
}
public byte[][] getByteParams(String... args) {
ArrayList byteParams = new ArrayList();
for (String arg : args) {
byteParams.add(SafeEncoder.encode(arg));
}
if (contains(UNCOMPRESSED)) {
byteParams.add(SafeEncoder.encode(UNCOMPRESSED));
}
addParamWithValue(byteParams, DATA_ET);
addParamWithValue(byteParams, CHUNK_SIZE);
addParamWithLabel(byteParams, LABELS);
return byteParams.toArray(new byte[byteParams.size()][]);
}
public byte[][] getByteParams(byte[]... args) {
ArrayList byteParams = new ArrayList();
for (byte[] arg : args) {
byteParams.add(arg);
}
if (contains(UNCOMPRESSED)) {
byteParams.add(SafeEncoder.encode(UNCOMPRESSED));
}
addParamWithValue(byteParams, DATA_ET);
addParamWithValue(byteParams, CHUNK_SIZE);
addParamWithLabel(byteParams, LABELS);
return byteParams.toArray(new byte[byteParams.size()][]);
}
public byte[][] getByteParams(String pkey, ArrayList> args) {
ArrayList byteParams = new ArrayList();
byteParams.add(SafeEncoder.encode(pkey));
byteParams.add(SafeEncoder.encode(String.valueOf(args.size())));
for (ExtsDataPoint arg : args) {
byteParams.add(SafeEncoder.encode(arg.getSkey()));
byteParams.add(SafeEncoder.encode(arg.getTs()));
byteParams.add(SafeEncoder.encode(String.valueOf(arg.getValue())));
}
if (contains(UNCOMPRESSED)) {
byteParams.add(SafeEncoder.encode(UNCOMPRESSED));
}
addParamWithValue(byteParams, DATA_ET);
addParamWithValue(byteParams, CHUNK_SIZE);
addParamWithLabel(byteParams, LABELS);
return byteParams.toArray(new byte[byteParams.size()][]);
}
public byte[][] getByteParams(byte[] pkey, ArrayList> args) {
ArrayList byteParams = new ArrayList();
byteParams.add(pkey);
byteParams.add(toByteArray(args.size()));
for (ExtsDataPoint arg : args) {
byteParams.add(arg.getSkey());
byteParams.add(arg.getTs());
byteParams.add(toByteArray(arg.getValue()));
}
if (contains(UNCOMPRESSED)) {
byteParams.add(SafeEncoder.encode(UNCOMPRESSED));
}
addParamWithValue(byteParams, DATA_ET);
addParamWithValue(byteParams, CHUNK_SIZE);
addParamWithLabel(byteParams, LABELS);
return byteParams.toArray(new byte[byteParams.size()][]);
}
public byte[][] getByteParamsStr(String pkey, ArrayList> args) {
ArrayList byteParams = new ArrayList();
byteParams.add(SafeEncoder.encode(pkey));
byteParams.add(SafeEncoder.encode(String.valueOf(args.size())));
for (ExtsStringDataPoint arg : args) {
byteParams.add(SafeEncoder.encode(arg.getSkey()));
byteParams.add(SafeEncoder.encode(arg.getTs()));
byteParams.add(SafeEncoder.encode(arg.getValue()));
}
if (contains(UNCOMPRESSED)) {
byteParams.add(SafeEncoder.encode(UNCOMPRESSED));
}
addParamWithValue(byteParams, DATA_ET);
addParamWithValue(byteParams, CHUNK_SIZE);
addParamWithLabel(byteParams, LABELS);
return byteParams.toArray(new byte[byteParams.size()][]);
}
public byte[][] getByteParamsStr(byte[] pkey, ArrayList> args) {
ArrayList byteParams = new ArrayList();
byteParams.add(pkey);
byteParams.add(toByteArray(args.size()));
for (ExtsStringDataPoint arg : args) {
byteParams.add(arg.getSkey());
byteParams.add(arg.getTs());
byteParams.add(arg.getValue());
}
if (contains(UNCOMPRESSED)) {
byteParams.add(SafeEncoder.encode(UNCOMPRESSED));
}
addParamWithValue(byteParams, DATA_ET);
addParamWithValue(byteParams, CHUNK_SIZE);
addParamWithLabel(byteParams, LABELS);
return byteParams.toArray(new byte[byteParams.size()][]);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy