BinaryClient is born
This commit is contained in:
714
src/main/java/redis/clients/jedis/BinaryClient.java
Normal file
714
src/main/java/redis/clients/jedis/BinaryClient.java
Normal file
@@ -0,0 +1,714 @@
|
|||||||
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Protocol.Command;
|
||||||
|
import redis.clients.jedis.Protocol.Keyword;
|
||||||
|
import static redis.clients.jedis.Protocol.toByteArray;
|
||||||
|
|
||||||
|
import static redis.clients.jedis.Protocol.Command.*;
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.*;
|
||||||
|
public class BinaryClient extends Connection {
|
||||||
|
public enum LIST_POSITION {
|
||||||
|
BEFORE, AFTER;
|
||||||
|
public final byte[] raw;
|
||||||
|
private LIST_POSITION() {
|
||||||
|
raw = name().getBytes(Protocol.UTF8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isInMulti;
|
||||||
|
|
||||||
|
public boolean isInMulti() {
|
||||||
|
return isInMulti;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BinaryClient(final String host) {
|
||||||
|
super(host);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BinaryClient(final String host, final int port) {
|
||||||
|
super(host, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ping() {
|
||||||
|
sendCommand(PING);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(final byte[] key, final byte[] value) {
|
||||||
|
sendCommand(Command.SET, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void get(final byte[] key) {
|
||||||
|
sendCommand(Command.GET, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void quit() {
|
||||||
|
sendCommand(QUIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exists(final byte[] key) {
|
||||||
|
sendCommand(EXISTS, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void del(final byte[]... keys) {
|
||||||
|
sendCommand(DEL, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void type(final byte[] key) {
|
||||||
|
sendCommand(TYPE, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void flushDB() {
|
||||||
|
sendCommand(FLUSHDB);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keys(final byte[] pattern) {
|
||||||
|
sendCommand(KEYS, pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void randomKey() {
|
||||||
|
sendCommand(RANDOMKEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rename(final byte[] oldkey, final byte[] newkey) {
|
||||||
|
sendCommand(RENAME, oldkey, newkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void renamenx(final byte[] oldkey, final byte[] newkey) {
|
||||||
|
sendCommand(RENAMENX, oldkey, newkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dbSize() {
|
||||||
|
sendCommand(DBSIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void expire(final byte[] key, final int seconds) {
|
||||||
|
sendCommand(EXPIRE, key, toByteArray(seconds));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void expireAt(final byte[] key, final long unixTime) {
|
||||||
|
sendCommand(EXPIREAT, key, toByteArray(unixTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ttl(final byte[] key) {
|
||||||
|
sendCommand(TTL, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void select(final int index) {
|
||||||
|
sendCommand(SELECT, toByteArray(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void move(final byte[] key, final int dbIndex) {
|
||||||
|
sendCommand(MOVE, key, toByteArray(dbIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void flushAll() {
|
||||||
|
sendCommand(FLUSHALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getSet(final byte[] key, final byte[] value) {
|
||||||
|
sendCommand(GETSET, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mget(final byte[]... keys) {
|
||||||
|
sendCommand(MGET, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setnx(final byte[] key, final byte[] value) {
|
||||||
|
sendCommand(SETNX, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setex(
|
||||||
|
final byte[] key,
|
||||||
|
final int seconds,
|
||||||
|
final byte[] value) {
|
||||||
|
sendCommand(SETEX, key, toByteArray(seconds), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mset(final byte[]... keysvalues) {
|
||||||
|
sendCommand(MSET, keysvalues);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void msetnx(final byte[]... keysvalues) {
|
||||||
|
sendCommand(MSETNX, keysvalues);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void decrBy(final byte[] key, final int integer) {
|
||||||
|
sendCommand(DECRBY, key, toByteArray(integer));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void decr(final byte[] key) {
|
||||||
|
sendCommand(DECR, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void incrBy(final byte[] key, final int integer) {
|
||||||
|
sendCommand(INCRBY, key, toByteArray(integer));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void incr(final byte[] key) {
|
||||||
|
sendCommand(INCR, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void append(final byte[] key, final byte[] value) {
|
||||||
|
sendCommand(APPEND, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void substr(final byte[] key, final int start, final int end) {
|
||||||
|
sendCommand(SUBSTR, key, toByteArray(start), toByteArray(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hset(
|
||||||
|
final byte[] key,
|
||||||
|
final byte[] field,
|
||||||
|
final byte[] value) {
|
||||||
|
sendCommand(HSET, key, field, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hget(final byte[] key, final byte[] field) {
|
||||||
|
sendCommand(HGET, key, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hsetnx(
|
||||||
|
final byte[] key,
|
||||||
|
final byte[] field,
|
||||||
|
final byte[] value) {
|
||||||
|
sendCommand(HSETNX, key, field, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hmset(final byte[] key, final Map<byte[], byte[]> hash) {
|
||||||
|
final List<byte[]> params = new ArrayList<byte[]>();
|
||||||
|
params.add(key);
|
||||||
|
|
||||||
|
for (final byte[] field : hash.keySet()) {
|
||||||
|
params.add(field);
|
||||||
|
params.add(hash.get(field));
|
||||||
|
}
|
||||||
|
sendCommand(HMSET, params.toArray(new byte[params.size()][]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hmget(final byte[] key, final byte[]... fields) {
|
||||||
|
final byte[][] params = new byte[fields.length + 1][];
|
||||||
|
params[0] = key;
|
||||||
|
System.arraycopy(fields, 0, params, 1, fields.length);
|
||||||
|
sendCommand(HMGET, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hincrBy(final byte[] key, final byte[] field, final int value) {
|
||||||
|
sendCommand(HINCRBY, key, field, toByteArray(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hexists(final byte[] key, final byte[] field) {
|
||||||
|
sendCommand(HEXISTS, key, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hdel(final byte[] key, final byte[] field) {
|
||||||
|
sendCommand(HDEL, key, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hlen(final byte[] key) {
|
||||||
|
sendCommand(HLEN, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hkeys(final byte[] key) {
|
||||||
|
sendCommand(HKEYS, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hvals(final byte[] key) {
|
||||||
|
sendCommand(HVALS, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hgetAll(final byte[] key) {
|
||||||
|
sendCommand(HGETALL, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rpush(final byte[] key, final byte[] string) {
|
||||||
|
sendCommand(RPUSH, key, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lpush(final byte[] key, final byte[] string) {
|
||||||
|
sendCommand(LPUSH, key, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void llen(final byte[] key) {
|
||||||
|
sendCommand(LLEN, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lrange(final byte[] key, final int start, final int end) {
|
||||||
|
sendCommand(LRANGE, key, toByteArray(start), toByteArray(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ltrim(final byte[] key, final int start, final int end) {
|
||||||
|
sendCommand(LTRIM, key, toByteArray(start), toByteArray(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lindex(final byte[] key, final int index) {
|
||||||
|
sendCommand(LINDEX, key, toByteArray(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lset(final byte[] key, final int index, final byte[] value) {
|
||||||
|
sendCommand(LSET, key, toByteArray(index), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lrem(final byte[] key, int count, final byte[] value) {
|
||||||
|
sendCommand(LREM, key, toByteArray(count), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lpop(final byte[] key) {
|
||||||
|
sendCommand(LPOP, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rpop(final byte[] key) {
|
||||||
|
sendCommand(RPOP, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rpoplpush(final byte[] srckey, final byte[] dstkey) {
|
||||||
|
sendCommand(RPOPLPUSH, srckey, dstkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sadd(final byte[] key, final byte[] member) {
|
||||||
|
sendCommand(SADD, key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void smembers(final byte[] key) {
|
||||||
|
sendCommand(SMEMBERS, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void srem(final byte[] key, final byte[] member) {
|
||||||
|
sendCommand(SREM, key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void spop(final byte[] key) {
|
||||||
|
sendCommand(SPOP, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void smove(
|
||||||
|
final byte[] srckey,
|
||||||
|
final byte[] dstkey,
|
||||||
|
final byte[] member) {
|
||||||
|
sendCommand(SMOVE, srckey, dstkey, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void scard(final byte[] key) {
|
||||||
|
sendCommand(SCARD, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sismember(final byte[] key, final byte[] member) {
|
||||||
|
sendCommand(SISMEMBER, key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sinter(final byte[]... keys) {
|
||||||
|
sendCommand(SINTER, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sinterstore(final byte[] dstkey, final byte[]... keys) {
|
||||||
|
final byte[][] params = new byte[keys.length + 1][];
|
||||||
|
params[0] = dstkey;
|
||||||
|
System.arraycopy(keys, 0, params, 1, keys.length);
|
||||||
|
sendCommand(SINTERSTORE, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sunion(final byte[]... keys) {
|
||||||
|
sendCommand(SUNION, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sunionstore(final byte[] dstkey, final byte[]... keys) {
|
||||||
|
byte[][] params = new byte[keys.length + 1][];
|
||||||
|
params[0] = dstkey;
|
||||||
|
System.arraycopy(keys, 0, params, 1, keys.length);
|
||||||
|
sendCommand(SUNIONSTORE, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sdiff(final byte[]... keys) {
|
||||||
|
sendCommand(SDIFF, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sdiffstore(final byte[] dstkey, final byte[]... keys) {
|
||||||
|
byte[][] params = new byte[keys.length + 1][];
|
||||||
|
params[0] = dstkey;
|
||||||
|
System.arraycopy(keys, 0, params, 1, keys.length);
|
||||||
|
sendCommand(SDIFFSTORE, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void srandmember(final byte[] key) {
|
||||||
|
sendCommand(SRANDMEMBER, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zadd(
|
||||||
|
final byte[] key,
|
||||||
|
final double score,
|
||||||
|
final byte[] member) {
|
||||||
|
sendCommand(ZADD, key, toByteArray(score), member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrange(final byte[] key, final int start, final int end) {
|
||||||
|
sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrem(final byte[] key, final byte[] member) {
|
||||||
|
sendCommand(ZREM, key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zincrby(
|
||||||
|
final byte[] key,
|
||||||
|
final double score,
|
||||||
|
final byte[] member) {
|
||||||
|
sendCommand(ZINCRBY, key, toByteArray(score), member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrank(final byte[] key, final byte[] member) {
|
||||||
|
sendCommand(ZRANK, key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrevrank(final byte[] key, final byte[] member) {
|
||||||
|
sendCommand(ZREVRANK, key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrevrange(
|
||||||
|
final byte[] key,
|
||||||
|
final int start,
|
||||||
|
final int end) {
|
||||||
|
sendCommand(
|
||||||
|
ZREVRANGE,
|
||||||
|
key,
|
||||||
|
toByteArray(start),
|
||||||
|
toByteArray(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrangeWithScores(
|
||||||
|
final byte[] key,
|
||||||
|
final int start,
|
||||||
|
final int end) {
|
||||||
|
sendCommand(
|
||||||
|
ZRANGE,
|
||||||
|
key,
|
||||||
|
toByteArray(start),
|
||||||
|
toByteArray(end),
|
||||||
|
WITHSCORES.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrevrangeWithScores(
|
||||||
|
final byte[] key,
|
||||||
|
final int start,
|
||||||
|
final int end) {
|
||||||
|
sendCommand(
|
||||||
|
ZREVRANGE,
|
||||||
|
key,
|
||||||
|
toByteArray(start),
|
||||||
|
toByteArray(end),
|
||||||
|
WITHSCORES.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zcard(final byte[] key) {
|
||||||
|
sendCommand(ZCARD, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zscore(final byte[] key, final byte[] member) {
|
||||||
|
sendCommand(ZSCORE, key, member);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void multi() {
|
||||||
|
sendCommand(MULTI);
|
||||||
|
isInMulti = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void discard() {
|
||||||
|
sendCommand(DISCARD);
|
||||||
|
isInMulti = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exec() {
|
||||||
|
sendCommand(EXEC);
|
||||||
|
isInMulti = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void watch(final byte[] key) {
|
||||||
|
sendCommand(WATCH, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unwatch() {
|
||||||
|
sendCommand(UNWATCH);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sort(final byte[] key) {
|
||||||
|
sendCommand(SORT, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sort(final byte[] key, final SortingParams sortingParameters) {
|
||||||
|
final List<byte[]> args = new ArrayList<byte[]>();
|
||||||
|
args.add(key);
|
||||||
|
args.addAll(sortingParameters.getParams());
|
||||||
|
sendCommand(SORT, args.toArray(new byte[args.size()][]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void blpop(final byte[][] args) {
|
||||||
|
sendCommand(BLPOP, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sort(
|
||||||
|
final byte[] key,
|
||||||
|
final SortingParams sortingParameters,
|
||||||
|
final byte[] dstkey) {
|
||||||
|
final List<byte[]> args = new ArrayList<byte[]>();
|
||||||
|
args.add(key);
|
||||||
|
args.addAll(sortingParameters.getParams());
|
||||||
|
args.add(STORE.raw);
|
||||||
|
args.add(dstkey);
|
||||||
|
sendCommand(SORT, args.toArray(new byte[args.size()][]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sort(final byte[] key, final byte[] dstkey) {
|
||||||
|
sendCommand(SORT, key, STORE.raw, dstkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void brpop(final byte[][] args) {
|
||||||
|
sendCommand(BRPOP, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void auth(final String password) {
|
||||||
|
sendCommand(AUTH, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void subscribe(final String... channels) {
|
||||||
|
sendCommand(SUBSCRIBE, channels);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void publish(final String channel, final String message) {
|
||||||
|
sendCommand(PUBLISH, channel, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsubscribe() {
|
||||||
|
sendCommand(UNSUBSCRIBE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsubscribe(final String... channels) {
|
||||||
|
sendCommand(UNSUBSCRIBE, channels);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void psubscribe(final String[] patterns) {
|
||||||
|
sendCommand(PSUBSCRIBE, patterns);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void punsubscribe() {
|
||||||
|
sendCommand(PUNSUBSCRIBE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void punsubscribe(final String... patterns) {
|
||||||
|
sendCommand(PUNSUBSCRIBE, patterns);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zcount(final byte[] key, final double min, final double max) {
|
||||||
|
sendCommand(ZCOUNT, key, toByteArray(min), toByteArray(max));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrangeByScore(
|
||||||
|
final byte[] key,
|
||||||
|
final double min,
|
||||||
|
final double max) {
|
||||||
|
sendCommand(
|
||||||
|
ZRANGEBYSCORE,
|
||||||
|
key,
|
||||||
|
toByteArray(min),
|
||||||
|
toByteArray(max));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrangeByScore(
|
||||||
|
final byte[] key,
|
||||||
|
final byte[] min,
|
||||||
|
final byte[] max) {
|
||||||
|
sendCommand(ZRANGEBYSCORE, key, min, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrangeByScore(
|
||||||
|
final byte[] key,
|
||||||
|
final double min,
|
||||||
|
final double max,
|
||||||
|
final int offset,
|
||||||
|
int count) {
|
||||||
|
sendCommand(
|
||||||
|
ZRANGEBYSCORE,
|
||||||
|
key,
|
||||||
|
toByteArray(min),
|
||||||
|
toByteArray(max),
|
||||||
|
LIMIT.raw,
|
||||||
|
toByteArray(offset),
|
||||||
|
toByteArray(count));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrangeByScoreWithScores(
|
||||||
|
final byte[] key,
|
||||||
|
final double min,
|
||||||
|
final double max) {
|
||||||
|
sendCommand(
|
||||||
|
ZRANGEBYSCORE,
|
||||||
|
key,
|
||||||
|
toByteArray(min),
|
||||||
|
toByteArray(max),
|
||||||
|
WITHSCORES.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zrangeByScoreWithScores(
|
||||||
|
final byte[] key,
|
||||||
|
final double min,
|
||||||
|
final double max,
|
||||||
|
final int offset,
|
||||||
|
final int count) {
|
||||||
|
sendCommand(
|
||||||
|
ZRANGEBYSCORE,
|
||||||
|
key,
|
||||||
|
toByteArray(min),
|
||||||
|
toByteArray(max),
|
||||||
|
LIMIT.raw,
|
||||||
|
toByteArray(offset),
|
||||||
|
toByteArray(count),
|
||||||
|
WITHSCORES.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zremrangeByRank(
|
||||||
|
final byte[] key,
|
||||||
|
final int start,
|
||||||
|
final int end) {
|
||||||
|
sendCommand(
|
||||||
|
ZREMRANGEBYRANK,
|
||||||
|
key,
|
||||||
|
toByteArray(start),
|
||||||
|
toByteArray(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zremrangeByScore(
|
||||||
|
final byte[] key,
|
||||||
|
final double start,
|
||||||
|
final double end) {
|
||||||
|
sendCommand(
|
||||||
|
ZREMRANGEBYSCORE,
|
||||||
|
key,
|
||||||
|
toByteArray(start),
|
||||||
|
toByteArray(end));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zunionstore(final byte[] dstkey, final byte[]... sets) {
|
||||||
|
final byte[][] params = new byte[sets.length + 2][];
|
||||||
|
params[0] = dstkey;
|
||||||
|
params[1] = toByteArray(sets.length);
|
||||||
|
System.arraycopy(sets, 0, params, 2, sets.length);
|
||||||
|
sendCommand(ZUNIONSTORE, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zunionstore(
|
||||||
|
final byte[] dstkey,
|
||||||
|
final ZParams params,
|
||||||
|
final byte[]... sets) {
|
||||||
|
final List<byte[]> args = new ArrayList<byte[]>();
|
||||||
|
args.add(dstkey);
|
||||||
|
args.add(Protocol.toByteArray(sets.length));
|
||||||
|
for (final byte[] set : sets) {
|
||||||
|
args.add(set);
|
||||||
|
}
|
||||||
|
args.addAll(params.getParams());
|
||||||
|
sendCommand(ZUNIONSTORE, args.toArray(new byte[args.size()][]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zinterstore(final byte[] dstkey, final byte[]... sets) {
|
||||||
|
final byte[][] params = new byte[sets.length + 2][];
|
||||||
|
params[0] = dstkey;
|
||||||
|
params[1] = Protocol.toByteArray(sets.length);
|
||||||
|
System.arraycopy(sets, 0, params, 2, sets.length);
|
||||||
|
sendCommand(ZINTERSTORE, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zinterstore(
|
||||||
|
final byte[] dstkey,
|
||||||
|
final ZParams params,
|
||||||
|
final byte[]... sets) {
|
||||||
|
final List<byte[]> args = new ArrayList<byte[]>();
|
||||||
|
args.add(dstkey);
|
||||||
|
args.add(Protocol.toByteArray(sets.length));
|
||||||
|
for (final byte[] set : sets) {
|
||||||
|
args.add(set);
|
||||||
|
}
|
||||||
|
args.addAll(params.getParams());
|
||||||
|
sendCommand(ZINTERSTORE, args.toArray(new byte[args.size()][]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
sendCommand(SAVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bgsave() {
|
||||||
|
sendCommand(BGSAVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bgrewriteaof() {
|
||||||
|
sendCommand(BGREWRITEAOF);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lastsave() {
|
||||||
|
sendCommand(LASTSAVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shutdown() {
|
||||||
|
sendCommand(SHUTDOWN);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void info() {
|
||||||
|
sendCommand(INFO);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void monitor() {
|
||||||
|
sendCommand(MONITOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void slaveof(final String host, final int port) {
|
||||||
|
sendCommand(SLAVEOF, host, String.valueOf(port));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void slaveofNoOne() {
|
||||||
|
sendCommand(SLAVEOF, NO.raw, ONE.raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void configGet(final String pattern) {
|
||||||
|
sendCommand(CONFIG, Keyword.GET.name(), pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void configSet(final String parameter, final String value) {
|
||||||
|
sendCommand(CONFIG, Keyword.SET.name(), parameter, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void strlen(final byte[] key) {
|
||||||
|
sendCommand(STRLEN, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sync() {
|
||||||
|
sendCommand(SYNC);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void lpushx(final byte[] key, final byte[] string) {
|
||||||
|
sendCommand(LPUSHX, key, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void persist(final byte[] key) {
|
||||||
|
sendCommand(PERSIST, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rpushx(final byte[] key, final byte[] string) {
|
||||||
|
sendCommand(RPUSHX, key, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void echo(final byte[] string) {
|
||||||
|
sendCommand(ECHO, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void linsert(
|
||||||
|
final byte[] key,
|
||||||
|
final LIST_POSITION where,
|
||||||
|
final byte[] pivot,
|
||||||
|
final byte[] value) {
|
||||||
|
sendCommand(LINSERT, key, where.raw, pivot, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void debug(final DebugParams params) {
|
||||||
|
sendCommand(DEBUG, params.getCommand());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import java.net.UnknownHostException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import redis.clients.jedis.Protocol.Command;
|
||||||
import redis.clients.util.RedisInputStream;
|
import redis.clients.util.RedisInputStream;
|
||||||
import redis.clients.util.RedisOutputStream;
|
import redis.clients.util.RedisOutputStream;
|
||||||
|
|
||||||
@@ -49,7 +50,15 @@ public class Connection {
|
|||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Connection sendCommand(final String name, final String... args) {
|
protected Connection sendCommand(final Command cmd, final String... args) {
|
||||||
|
final byte[][] bargs = new byte[args.length][];
|
||||||
|
for(int i=0; i < args.length; i++) {
|
||||||
|
bargs[i] = args[i].getBytes(Protocol.UTF8);
|
||||||
|
}
|
||||||
|
return sendCommand(cmd, bargs);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Connection sendCommand(final Command cmd, final byte[]... args) {
|
||||||
try {
|
try {
|
||||||
connect();
|
connect();
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
@@ -57,12 +66,12 @@ public class Connection {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new JedisException("Could not connect to redis-server", e);
|
throw new JedisException("Could not connect to redis-server", e);
|
||||||
}
|
}
|
||||||
protocol.sendCommand(outputStream, name, args);
|
protocol.sendCommand(outputStream, cmd, args);
|
||||||
pipelinedCommands++;
|
pipelinedCommands++;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Connection sendCommand(final String name, final byte[]... args) {
|
protected Connection sendCommand(final Command cmd) {
|
||||||
try {
|
try {
|
||||||
connect();
|
connect();
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
@@ -70,7 +79,7 @@ public class Connection {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new JedisException("Could not connect to redis-server", e);
|
throw new JedisException("Could not connect to redis-server", e);
|
||||||
}
|
}
|
||||||
protocol.sendCommand(outputStream, name, args);
|
protocol.sendCommand(outputStream, cmd, (byte[])null);
|
||||||
pipelinedCommands++;
|
pipelinedCommands++;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public final class Protocol {
|
|||||||
public static final byte PLUS_BYTE = '+';
|
public static final byte PLUS_BYTE = '+';
|
||||||
public static final byte MINUS_BYTE = '-';
|
public static final byte MINUS_BYTE = '-';
|
||||||
public static final byte COLON_BYTE = ':';
|
public static final byte COLON_BYTE = ':';
|
||||||
|
/*
|
||||||
public void sendCommand(final RedisOutputStream os, final String name, final String... args) {
|
public void sendCommand(final RedisOutputStream os, final String name, final String... args) {
|
||||||
try {
|
try {
|
||||||
os.write(ASTERISK_BYTE);
|
os.write(ASTERISK_BYTE);
|
||||||
@@ -43,14 +43,20 @@ public final class Protocol {
|
|||||||
throw new JedisException(e);
|
throw new JedisException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
public void sendCommand(final RedisOutputStream os, final Command command, final byte[]... args) {
|
||||||
|
sendCommand(os, command.raw, args);
|
||||||
|
}
|
||||||
|
|
||||||
public void sendCommand(final RedisOutputStream os, final String name, final byte[]... args) {
|
private void sendCommand(final RedisOutputStream os, final byte[] command, final byte[]... args) {
|
||||||
try {
|
try {
|
||||||
os.write(ASTERISK_BYTE);
|
os.write(ASTERISK_BYTE);
|
||||||
os.writeIntCrLf(args.length + 1);
|
os.writeIntCrLf(args.length + 1);
|
||||||
os.write(DOLLAR_BYTE);
|
os.write(DOLLAR_BYTE);
|
||||||
os.writeIntCrLf(name.length());
|
os.writeIntCrLf(command.length);
|
||||||
os.writeAsciiCrLf(name);
|
os.write(command);
|
||||||
|
os.writeCrLf();
|
||||||
|
// os.writeAsciiCrLf(command);
|
||||||
|
|
||||||
for (final byte[] arg : args) {
|
for (final byte[] arg : args) {
|
||||||
os.write(DOLLAR_BYTE);
|
os.write(DOLLAR_BYTE);
|
||||||
@@ -136,4 +142,163 @@ public final class Protocol {
|
|||||||
public Object read(final RedisInputStream is) {
|
public Object read(final RedisInputStream is) {
|
||||||
return process(is);
|
return process(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final byte[] toByteArray(final int value) {
|
||||||
|
return String.valueOf(value).getBytes(Protocol.UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final byte[] toByteArray(final long value) {
|
||||||
|
return String.valueOf(value).getBytes(Protocol.UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final byte[] toByteArray(final double value) {
|
||||||
|
return String.valueOf(value).getBytes(Protocol.UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum Command {
|
||||||
|
PING,
|
||||||
|
SET,
|
||||||
|
GET,
|
||||||
|
QUIT,
|
||||||
|
EXISTS,
|
||||||
|
DEL,
|
||||||
|
TYPE,
|
||||||
|
FLUSHDB,
|
||||||
|
KEYS,
|
||||||
|
RANDOMKEY,
|
||||||
|
RENAME,
|
||||||
|
RENAMENX,
|
||||||
|
RENAMEX,
|
||||||
|
DBSIZE,
|
||||||
|
EXPIRE,
|
||||||
|
EXPIREAT,
|
||||||
|
TTL,
|
||||||
|
SELECT,
|
||||||
|
MOVE,
|
||||||
|
FLUSHALL,
|
||||||
|
GETSET,
|
||||||
|
MGET,
|
||||||
|
SETNX,
|
||||||
|
SETEX,
|
||||||
|
MSET,
|
||||||
|
MSETNX,
|
||||||
|
DECRBY,
|
||||||
|
DECR,
|
||||||
|
INCRBY,
|
||||||
|
INCR,
|
||||||
|
APPEND,
|
||||||
|
SUBSTR,
|
||||||
|
HSET,
|
||||||
|
HGET,
|
||||||
|
HSETNX,
|
||||||
|
HMSET,
|
||||||
|
HMGET,
|
||||||
|
HINCRBY,
|
||||||
|
HEXISTS,
|
||||||
|
HDEL,
|
||||||
|
HLEN,
|
||||||
|
HKEYS,
|
||||||
|
HVALS,
|
||||||
|
HGETALL,
|
||||||
|
RPUSH,
|
||||||
|
LPUSH,
|
||||||
|
LLEN,
|
||||||
|
LRANGE,
|
||||||
|
LTRIM,
|
||||||
|
LINDEX,
|
||||||
|
LSET,
|
||||||
|
LREM,
|
||||||
|
LPOP,
|
||||||
|
RPOP,
|
||||||
|
RPOPLPUSH,
|
||||||
|
SADD,
|
||||||
|
SMEMBERS,
|
||||||
|
SREM,
|
||||||
|
SPOP,
|
||||||
|
SMOVE,
|
||||||
|
SCARD,
|
||||||
|
SISMEMBER,
|
||||||
|
SINTER,
|
||||||
|
SINTERSTORE,
|
||||||
|
SUNION,
|
||||||
|
SUNIONSTORE,
|
||||||
|
SDIFF,
|
||||||
|
SDIFFSTORE,
|
||||||
|
SRANDMEMBER,
|
||||||
|
ZADD,
|
||||||
|
ZRANGE,
|
||||||
|
ZREM,
|
||||||
|
ZINCRBY,
|
||||||
|
ZRANK,
|
||||||
|
ZREVRANK,
|
||||||
|
ZREVRANGE,
|
||||||
|
ZCARD,
|
||||||
|
ZSCORE,
|
||||||
|
MULTI,
|
||||||
|
DISCARD,
|
||||||
|
EXEC,
|
||||||
|
WATCH,
|
||||||
|
UNWATCH,
|
||||||
|
SORT,
|
||||||
|
BLPOP,
|
||||||
|
BRPOP,
|
||||||
|
AUTH,
|
||||||
|
SUBSCRIBE,
|
||||||
|
PUBLISH,
|
||||||
|
UNSUBSCRIBE,
|
||||||
|
PSUBSCRIBE,
|
||||||
|
PUNSUBSCRIBE,
|
||||||
|
ZCOUNT,
|
||||||
|
ZRANGEBYSCORE,
|
||||||
|
ZREMRANGEBYRANK,
|
||||||
|
ZREMRANGEBYSCORE,
|
||||||
|
ZUNIONSTORE,
|
||||||
|
ZINTERSTORE,
|
||||||
|
SAVE,
|
||||||
|
BGSAVE,
|
||||||
|
BGREWRITEAOF,
|
||||||
|
LASTSAVE,
|
||||||
|
SHUTDOWN,
|
||||||
|
INFO,
|
||||||
|
MONITOR,
|
||||||
|
SLAVEOF,
|
||||||
|
CONFIG,
|
||||||
|
STRLEN,
|
||||||
|
SYNC,
|
||||||
|
LPUSHX,
|
||||||
|
PERSIST,
|
||||||
|
RPUSHX,
|
||||||
|
ECHO,
|
||||||
|
LINSERT,
|
||||||
|
DEBUG;
|
||||||
|
|
||||||
|
public final byte[] raw;
|
||||||
|
|
||||||
|
Command() {
|
||||||
|
raw = this.name().getBytes(UTF8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum Keyword {
|
||||||
|
AGGREGATE,
|
||||||
|
ALPHA,
|
||||||
|
ASC,
|
||||||
|
BY,
|
||||||
|
DESC,
|
||||||
|
GET,
|
||||||
|
NO,
|
||||||
|
NOSORT,
|
||||||
|
ONE,
|
||||||
|
LIMIT,
|
||||||
|
SET,
|
||||||
|
STORE,
|
||||||
|
WEIGHTS,
|
||||||
|
WITHSCORES;
|
||||||
|
public final byte[] raw;
|
||||||
|
|
||||||
|
Keyword() {
|
||||||
|
raw = this.name().getBytes(UTF8);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,13 +4,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.*;
|
||||||
/**
|
/**
|
||||||
* Builder Class for {@link Jedis#sort(String, SortingParams) SORT} Parameters.
|
* Builder Class for {@link Jedis#sort(String, SortingParams) SORT} Parameters.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class SortingParams {
|
public class SortingParams {
|
||||||
private List<String> params = new ArrayList<String>();
|
private List<byte[]> params = new ArrayList<byte[]>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort by weight in keys.
|
* Sort by weight in keys.
|
||||||
@@ -25,9 +25,9 @@ public class SortingParams {
|
|||||||
* @param pattern
|
* @param pattern
|
||||||
* @return the SortingParams Object
|
* @return the SortingParams Object
|
||||||
*/
|
*/
|
||||||
public SortingParams by(String pattern) {
|
public SortingParams by(final String pattern) {
|
||||||
params.add("BY");
|
params.add(BY.raw);
|
||||||
params.add(pattern);
|
params.add(pattern.getBytes(Protocol.UTF8));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,11 +40,12 @@ public class SortingParams {
|
|||||||
* @return the SortingParams Object
|
* @return the SortingParams Object
|
||||||
*/
|
*/
|
||||||
public SortingParams nosort() {
|
public SortingParams nosort() {
|
||||||
params.add("BY nosort");
|
params.add(BY.raw);
|
||||||
|
params.add(NOSORT.raw);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<String> getParams() {
|
public Collection<byte[]> getParams() {
|
||||||
return Collections.unmodifiableCollection(params);
|
return Collections.unmodifiableCollection(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ public class SortingParams {
|
|||||||
* @return the sortingParams Object
|
* @return the sortingParams Object
|
||||||
*/
|
*/
|
||||||
public SortingParams desc() {
|
public SortingParams desc() {
|
||||||
params.add("DESC");
|
params.add(DESC.raw);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +65,7 @@ public class SortingParams {
|
|||||||
* @return the SortingParams Object
|
* @return the SortingParams Object
|
||||||
*/
|
*/
|
||||||
public SortingParams asc() {
|
public SortingParams asc() {
|
||||||
params.add("ASC");
|
params.add(ASC.raw);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,10 +77,10 @@ public class SortingParams {
|
|||||||
* @param count
|
* @param count
|
||||||
* @return the SortingParams Object
|
* @return the SortingParams Object
|
||||||
*/
|
*/
|
||||||
public SortingParams limit(int start, int count) {
|
public SortingParams limit(final int start, final int count) {
|
||||||
params.add("LIMIT");
|
params.add(LIMIT.raw);
|
||||||
params.add(String.valueOf(start));
|
params.add(Protocol.toByteArray(start));
|
||||||
params.add(String.valueOf(count));
|
params.add(Protocol.toByteArray(count));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +91,7 @@ public class SortingParams {
|
|||||||
* @return the SortingParams Object
|
* @return the SortingParams Object
|
||||||
*/
|
*/
|
||||||
public SortingParams alpha() {
|
public SortingParams alpha() {
|
||||||
params.add("ALPHA");
|
params.add(ALPHA.raw);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,9 +111,9 @@ public class SortingParams {
|
|||||||
* @return the SortingParams Object
|
* @return the SortingParams Object
|
||||||
*/
|
*/
|
||||||
public SortingParams get(String... patterns) {
|
public SortingParams get(String... patterns) {
|
||||||
for (String pattern : patterns) {
|
for (final String pattern : patterns) {
|
||||||
params.add("GET");
|
params.add(GET.raw);
|
||||||
params.add(pattern);
|
params.add(pattern.getBytes(Protocol.UTF8));
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,29 +5,36 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.*;
|
||||||
|
|
||||||
public class ZParams {
|
public class ZParams {
|
||||||
public enum Aggregate {
|
public enum Aggregate {
|
||||||
SUM, MIN, MAX
|
SUM, MIN, MAX;
|
||||||
|
|
||||||
|
public final byte[] raw;
|
||||||
|
Aggregate() {
|
||||||
|
raw = name().getBytes(Protocol.UTF8);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> params = new ArrayList<String>();
|
private List<byte[]> params = new ArrayList<byte[]>();
|
||||||
|
|
||||||
public ZParams weights(int... weights) {
|
public ZParams weights(final int... weights) {
|
||||||
params.add("WEIGHTS");
|
params.add(WEIGHTS.raw);
|
||||||
for (int weight : weights) {
|
for (final int weight : weights) {
|
||||||
params.add(String.valueOf(weight));
|
params.add(Protocol.toByteArray(weight));
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<String> getParams() {
|
public Collection<byte[]> getParams() {
|
||||||
return Collections.unmodifiableCollection(params);
|
return Collections.unmodifiableCollection(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZParams aggregate(Aggregate aggregate) {
|
public ZParams aggregate(final Aggregate aggregate) {
|
||||||
params.add("AGGREGATE");
|
params.add(AGGREGATE.raw);
|
||||||
params.add(aggregate.name());
|
params.add(aggregate.raw);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ public final class RedisOutputStream extends FilterOutputStream {
|
|||||||
|
|
||||||
protected int count;
|
protected int count;
|
||||||
|
|
||||||
public RedisOutputStream(OutputStream out) {
|
public RedisOutputStream(final OutputStream out) {
|
||||||
this(out, 8192);
|
this(out, 8192);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RedisOutputStream(OutputStream out, int size) {
|
public RedisOutputStream(final OutputStream out, final int size) {
|
||||||
super(out);
|
super(out);
|
||||||
if (size <= 0) {
|
if (size <= 0) {
|
||||||
throw new IllegalArgumentException("Buffer size <= 0");
|
throw new IllegalArgumentException("Buffer size <= 0");
|
||||||
@@ -31,14 +31,18 @@ public final class RedisOutputStream extends FilterOutputStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(int b) throws IOException {
|
public void write(final byte b) throws IOException {
|
||||||
buf[count++] = (byte) b;
|
buf[count++] = b;
|
||||||
if (count == buf.length) {
|
if (count == buf.length) {
|
||||||
flushBuffer();
|
flushBuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void write(final byte[] b) throws IOException {
|
||||||
|
write(b, 0, b.length);
|
||||||
|
}
|
||||||
|
|
||||||
public void write(byte b[], int off, int len) throws IOException {
|
public void write(final byte b[], final int off, final int len) throws IOException {
|
||||||
if (len >= buf.length) {
|
if (len >= buf.length) {
|
||||||
flushBuffer();
|
flushBuffer();
|
||||||
out.write(b, off, len);
|
out.write(b, off, len);
|
||||||
@@ -52,7 +56,7 @@ public final class RedisOutputStream extends FilterOutputStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeAsciiCrLf(String in) throws IOException {
|
public void writeAsciiCrLf(final String in) throws IOException {
|
||||||
final int size = in.length();
|
final int size = in.length();
|
||||||
|
|
||||||
for (int i = 0; i != size; ++i) {
|
for (int i = 0; i != size; ++i) {
|
||||||
@@ -65,11 +69,11 @@ public final class RedisOutputStream extends FilterOutputStream {
|
|||||||
writeCrLf();
|
writeCrLf();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSurrogate(char ch) {
|
public static boolean isSurrogate(final char ch) {
|
||||||
return ch >= Character.MIN_SURROGATE && ch <= Character.MAX_SURROGATE;
|
return ch >= Character.MIN_SURROGATE && ch <= Character.MAX_SURROGATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int utf8Length (String str) {
|
public static int utf8Length (final String str) {
|
||||||
int strLen = str.length(), utfLen = 0;
|
int strLen = str.length(), utfLen = 0;
|
||||||
for(int i = 0; i != strLen; ++i) {
|
for(int i = 0; i != strLen; ++i) {
|
||||||
char c = str.charAt(i);
|
char c = str.charAt(i);
|
||||||
@@ -96,7 +100,7 @@ public final class RedisOutputStream extends FilterOutputStream {
|
|||||||
buf[count++] = '\n';
|
buf[count++] = '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeUtf8CrLf(String str) throws IOException {
|
public void writeUtf8CrLf(final String str) throws IOException {
|
||||||
int strLen = str.length();
|
int strLen = str.length();
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|||||||
Reference in New Issue
Block a user