com.aliyun.tair.tairhash.TairHashPipeline 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.tairhash;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import com.aliyun.tair.ModuleCommand;
import com.aliyun.tair.tairhash.params.*;
import com.aliyun.tair.tairhash.factory.HashBuilderFactory;
import com.aliyun.tair.util.JoinParameters;
import redis.clients.jedis.BuilderFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;
import redis.clients.jedis.Response;
import redis.clients.jedis.ScanParams;
import redis.clients.jedis.ScanResult;
import redis.clients.jedis.util.SafeEncoder;
import static redis.clients.jedis.Protocol.toByteArray;
public class TairHashPipeline extends Pipeline {
public Response exhset(final String key, final String field, final String value) {
getClient("").sendCommand(ModuleCommand.EXHSET, key, field, value);
return getResponse(BuilderFactory.LONG);
}
public Response exhset(final byte[] key, final byte[] field, final byte[] value) {
getClient("").sendCommand(ModuleCommand.EXHSET, key, field, value);
return getResponse(BuilderFactory.LONG);
}
public Response exhset(final String key, final String field, final String value, final ExhsetParams params) {
getClient("").sendCommand(ModuleCommand.EXHSET,
params.getByteParams(SafeEncoder.encode(key), SafeEncoder.encode(field), SafeEncoder.encode(value)));
return getResponse(BuilderFactory.LONG);
}
public Response exhset(final byte[] key, final byte[] field, final byte[] value, final ExhsetParams params) {
getClient("").sendCommand(ModuleCommand.EXHSET, params.getByteParams(key, field, value));
return getResponse(BuilderFactory.LONG);
}
public Response exhsetnx(final String key, final String field, final String value) {
getClient("").sendCommand(ModuleCommand.EXHSETNX, key, field, value);
return getResponse(BuilderFactory.LONG);
}
public Response exhsetnx(final byte[] key, final byte[] field, final byte[] value) {
getClient("").sendCommand(ModuleCommand.EXHSETNX, key, field, value);
return getResponse(BuilderFactory.LONG);
}
public Response exhmset(final String key, final Map hash) {
final Map bhash = new HashMap(hash.size());
for (final Entry entry : hash.entrySet()) {
bhash.put(SafeEncoder.encode(entry.getKey()), SafeEncoder.encode(entry.getValue()));
}
return exhmset(SafeEncoder.encode(key), bhash);
}
public Response exhmset(final byte[] key, final Map hash) {
final List params = new ArrayList();
params.add(key);
for (final Entry entry : hash.entrySet()) {
params.add(entry.getKey());
params.add(entry.getValue());
}
getClient("").sendCommand(ModuleCommand.EXHMSET, params.toArray(new byte[params.size()][]));
return getResponse(BuilderFactory.STRING);
}
public Response exhmsetwithopts(final String key, final List> params) {
List> bexhash = new ArrayList>();
for (ExhmsetwithoptsParams entry : params) {
bexhash.add(new ExhmsetwithoptsParams(SafeEncoder.encode(entry.getField()),
SafeEncoder.encode(entry.getValue()), entry.getVer(), entry.getExp()));
}
return exhmsetwithopts(SafeEncoder.encode(key), bexhash);
}
public Response exhmsetwithopts(final byte[] key, final List> params) {
final List p = new ArrayList();
p.add(key);
for (final ExhmsetwithoptsParams entry : params) {
p.add(entry.getField());
p.add(entry.getValue());
p.add(toByteArray(entry.getVer()));
p.add(toByteArray(entry.getExp()));
}
getClient("").sendCommand(ModuleCommand.EXHMSETWITHOPTS, p.toArray(new byte[params.size()][]));
return getResponse(BuilderFactory.STRING);
}
public Response exhpexpire(final String key, final String field, final int milliseconds) {
return exhpexpire(SafeEncoder.encode(key), SafeEncoder.encode(field), milliseconds);
}
public Response exhpexpire(final String key, final String field, final int milliseconds,boolean noactive) {
return exhpexpire(SafeEncoder.encode(key), SafeEncoder.encode(field), milliseconds,noactive);
}
public Response exhpexpire(final byte[] key, final byte[] field, final int milliseconds) {
getClient("").sendCommand(ModuleCommand.EXHPEXPIRE, key, field, toByteArray(milliseconds));
return getResponse(BuilderFactory.BOOLEAN);
}
public Response exhpexpire(final byte[] key, final byte[] field, final int milliseconds,boolean noactive) {
if(noactive){
getClient("").sendCommand(ModuleCommand.EXHPEXPIRE, key, field, toByteArray(milliseconds),SafeEncoder.encode("noactive"));
}else {
getClient("").sendCommand(ModuleCommand.EXHPEXPIRE, key, field, toByteArray(milliseconds));
}
return getResponse(BuilderFactory.BOOLEAN);
}
public Response exhpexpireAt(final String key, final String field, final long unixTime) {
return exhpexpireAt(SafeEncoder.encode(key), SafeEncoder.encode(field), unixTime);
}
public Response exhpexpireAt(final String key, final String field, final long unixTime,boolean noactive) {
return exhpexpireAt(SafeEncoder.encode(key), SafeEncoder.encode(field), unixTime,noactive);
}
public Response exhpexpireAt(final byte[] key, final byte[] field, final long unixTime) {
getClient("").sendCommand(ModuleCommand.EXHPEXPIREAT, key, field, toByteArray(unixTime));
return getResponse(BuilderFactory.BOOLEAN);
}
public Response exhpexpireAt(final byte[] key, final byte[] field, final long unixTime,boolean noactive) {
if(noactive) {
getClient("").sendCommand(ModuleCommand.EXHPEXPIREAT, key, field, toByteArray(unixTime),SafeEncoder.encode("noactive"));
}else {
getClient("").sendCommand(ModuleCommand.EXHPEXPIREAT, key, field, toByteArray(unixTime));
}
return getResponse(BuilderFactory.BOOLEAN);
}
public Response exhexpire(final String key, final String field, final int seconds) {
return exhexpire(SafeEncoder.encode(key), SafeEncoder.encode(field), seconds);
}
public Response exhexpire(final String key, final String field, final int seconds,boolean noactive) {
return exhexpire(SafeEncoder.encode(key), SafeEncoder.encode(field), seconds,noactive);
}
public Response exhexpire(final byte[] key, final byte[] field, final int seconds) {
getClient("").sendCommand(ModuleCommand.EXHEXPIRE, key, field, toByteArray(seconds));
return getResponse(BuilderFactory.BOOLEAN);
}
public Response exhexpire(final byte[] key, final byte[] field, final int seconds,boolean noactive) {
if(noactive) {
getClient("").sendCommand(ModuleCommand.EXHEXPIRE, key, field, toByteArray(seconds),SafeEncoder.encode("noactive"));
}else {
getClient("").sendCommand(ModuleCommand.EXHEXPIRE, key, field, toByteArray(seconds));
}
return getResponse(BuilderFactory.BOOLEAN);
}
public Response exhexpireAt(final String key, final String field, final long unixTime) {
return exhexpireAt(SafeEncoder.encode(key), SafeEncoder.encode(field), unixTime);
}
public Response exhexpireAt(final String key, final String field, final long unixTime,boolean noactive) {
return exhexpireAt(SafeEncoder.encode(key), SafeEncoder.encode(field), unixTime,noactive);
}
public Response exhexpireAt(final byte[] key, final byte[] field, final long unixTime) {
getClient("").sendCommand(ModuleCommand.EXHEXPIREAT, key, field, toByteArray(unixTime));
return getResponse(BuilderFactory.BOOLEAN);
}
public Response exhexpireAt(final byte[] key, final byte[] field, final long unixTime,boolean noactive) {
if(noactive) {
getClient("").sendCommand(ModuleCommand.EXHEXPIREAT, key, field, toByteArray(unixTime),SafeEncoder.encode("noactive"));
}else {
getClient("").sendCommand(ModuleCommand.EXHEXPIREAT, key, field, toByteArray(unixTime));
}
return getResponse(BuilderFactory.BOOLEAN);
}
public Response exhpttl(final String key, final String field) {
return exhpttl(SafeEncoder.encode(key), SafeEncoder.encode(field));
}
public Response exhpttl(final byte[] key, final byte[] field) {
getClient("").sendCommand(ModuleCommand.EXHPTTL, key, field);
return getResponse(BuilderFactory.LONG);
}
public Response exhttl(final String key, final String field) {
return exhttl(SafeEncoder.encode(key), SafeEncoder.encode(field));
}
public Response exhttl(final byte[] key, final byte[] field) {
getClient("").sendCommand(ModuleCommand.EXHTTL, key, field);
return getResponse(BuilderFactory.LONG);
}
public Response exhver(final String key, final String field) {
return exhver(SafeEncoder.encode(key), SafeEncoder.encode(field));
}
public Response exhver(final byte[] key, final byte[] field) {
getClient("").sendCommand(ModuleCommand.EXHVER, key, field);
return getResponse(BuilderFactory.LONG);
}
public Response exhsetver(final String key, final String field, final long version) {
return exhsetver(SafeEncoder.encode(key), SafeEncoder.encode(field), version);
}
public Response exhsetver(final byte[] key, final byte[] field, final long version) {
getClient("").sendCommand(ModuleCommand.EXHSETVER, key, field, toByteArray(version));
return getResponse(BuilderFactory.BOOLEAN);
}
public Response exhincrBy(final String key, final String field, final long value) {
return exhincrBy(SafeEncoder.encode(key), SafeEncoder.encode(field), value);
}
public Response exhincrBy(byte[] key, byte[] field, long value) {
getClient("").sendCommand(ModuleCommand.EXHINCRBY, key, field, toByteArray(value));
return getResponse(BuilderFactory.LONG);
}
public Response exhincrBy(final String key, final String field, final long value, final ExhincrByParams params) {
return exhincrBy(SafeEncoder.encode(key), SafeEncoder.encode(field), value, params);
}
public Response exhincrBy(final byte[] key, final byte[] field, final long value, final ExhincrByParams params) {
getClient("").sendCommand(ModuleCommand.EXHINCRBY,
params.getByteParams(key, field, toByteArray(value)));
return getResponse(BuilderFactory.LONG);
}
public Response exhincrByFloat(final String key, final String field, final double value) {
return exhincrByFloat(SafeEncoder.encode(key), SafeEncoder.encode(field), value);
}
public Response exhincrByFloat(byte[] key, byte[] field, final double value) {
getClient("").sendCommand(ModuleCommand.EXHINCRBYFLOAT, key, field, toByteArray(value));
return getResponse(BuilderFactory.DOUBLE);
}
public Response exhincrByFloat(final String key, final String field, final double value,
final ExhincrByFloatParams params) {
return exhincrByFloat(SafeEncoder.encode(key), SafeEncoder.encode(field), value, params);
}
public Response exhincrByFloat(byte[] key, byte[] field, double value, ExhincrByFloatParams params) {
getClient("").sendCommand(ModuleCommand.EXHINCRBYFLOAT,
params.getByteParams(key, field, toByteArray(value)));
return getResponse(BuilderFactory.DOUBLE);
}
public Response exhget(final String key, final String field) {
getClient("").sendCommand(ModuleCommand.EXHGET, key, field);
return getResponse(BuilderFactory.STRING);
}
public Response exhget(final byte[] key, final byte[] field) {
getClient("").sendCommand(ModuleCommand.EXHGET, key, field);
return getResponse(BuilderFactory.BYTE_ARRAY);
}
public Response> exhgetwithver(final String key, final String field) {
getClient("").sendCommand(ModuleCommand.EXHGETWITHVER, key, field);
return getResponse(HashBuilderFactory.EXHGETWITHVER_RESULT_STRING);
}
public Response> exhgetwithver(byte[] key, byte[] field) {
getClient("").sendCommand(ModuleCommand.EXHGETWITHVER, key, field);
return getResponse(HashBuilderFactory.EXHGETWITHVER_RESULT_BYTE);
}
public Response> exhmget(final String key, final String... fields) {
getClient("").sendCommand(ModuleCommand.EXHMGET,
JoinParameters.joinParameters(SafeEncoder.encode(key), SafeEncoder.encodeMany(fields)));
return getResponse(BuilderFactory.STRING_LIST);
}
public Response> exhmget(byte[] key, byte[]... fields) {
getClient("").sendCommand(ModuleCommand.EXHMGET, JoinParameters.joinParameters(key, fields));
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
}
public Response>> exhmgetwithver(final String key, final String... fields) {
getClient("").sendCommand(ModuleCommand.EXHMGETWITHVER,
JoinParameters.joinParameters(SafeEncoder.encode(key), SafeEncoder.encodeMany(fields)));
return getResponse(HashBuilderFactory.EXHMGETWITHVER_RESULT_STRING_LIST);
}
public Response>> exhmgetwithver(byte[] key, byte[]... fields) {
getClient("").sendCommand(ModuleCommand.EXHMGETWITHVER, JoinParameters.joinParameters(key, fields));
return getResponse(HashBuilderFactory.EXHMGETWITHVER_RESULT_BYTE_LIST);
}
public Response exhdel(final String key, final String... fields) {
return exhdel(SafeEncoder.encode(key), SafeEncoder.encodeMany(fields));
}
public Response exhdel(byte[] key, byte[]... fields) {
getClient("").sendCommand(ModuleCommand.EXHDEL, JoinParameters.joinParameters(key, fields));
return getResponse(BuilderFactory.LONG);
}
public Response exhlen(final String key) {
return exhlen(SafeEncoder.encode(key));
}
public Response exhlen(final String key,boolean noexp) {
return exhlen(SafeEncoder.encode(key),noexp);
}
public Response exhlen(byte[] key) {
getClient("").sendCommand(ModuleCommand.EXHLEN, key);
return getResponse(BuilderFactory.LONG);
}
public Response exhlen(byte[] key,boolean noexp) {
if(noexp){
getClient("").sendCommand(ModuleCommand.EXHLEN, key,SafeEncoder.encode("noexp"));
}else {
getClient("").sendCommand(ModuleCommand.EXHLEN, key);
}
return getResponse(BuilderFactory.LONG);
}
public Response exhexists(final String key, final String field) {
return exhexists(SafeEncoder.encode(key), SafeEncoder.encode(field));
}
public Response exhexists(byte[] key, byte[] field) {
getClient("").sendCommand(ModuleCommand.EXHEXISTS, key, field);
return getResponse(BuilderFactory.BOOLEAN);
}
public Response exhstrlen(final String key, final String field) {
return exhstrlen(SafeEncoder.encode(key), SafeEncoder.encode(field));
}
public Response exhstrlen(byte[] key, byte[] field) {
getClient("").sendCommand(ModuleCommand.EXHSTRLEN, key, field);
return getResponse(BuilderFactory.LONG);
}
public Response> exhkeys(final String key) {
getClient("").sendCommand(ModuleCommand.EXHKEYS, key);
return getResponse(BuilderFactory.STRING_ZSET);
}
public Response> exhkeys(byte[] key) {
getClient("").sendCommand(ModuleCommand.EXHKEYS, key);
return getResponse(BuilderFactory.BYTE_ARRAY_ZSET);
}
public Response> exhvals(final String key) {
getClient("").sendCommand(ModuleCommand.EXHVALS, key);
return getResponse(BuilderFactory.STRING_LIST);
}
public Response> exhvals(byte[] key) {
getClient("").sendCommand(ModuleCommand.EXHVALS, key);
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
}
public Response
© 2015 - 2025 Weber Informatics LLC | Privacy Policy