diff --git a/.gitignore b/.gitignore
index 982e6b6..181df84 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,6 @@ target/
build/
bin/
tags
+.idea
+*.aof
+*.rdb
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..aa9797b
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,7 @@
+language: java
+jdk:
+ - openjdk6
+ - openjdk7
+ - oraclejdk7
+install: make travis-install
+script: make test
diff --git a/Makefile b/Makefile
index e00fb83..6a784d8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,5 @@
+PATH := ./redis-git/src:${PATH}
+
define REDIS1_CONF
daemonize yes
port 6379
@@ -23,6 +25,7 @@ define REDIS3_CONF
daemonize yes
port 6381
requirepass foobared
+masterauth foobared
pidfile /tmp/redis3.pid
logfile /tmp/redis3.log
save ""
@@ -50,7 +53,7 @@ pidfile /tmp/redis5.pid
logfile /tmp/redis5.log
save ""
appendonly no
-slaveof localhost 6381
+slaveof localhost 6379
endef
define REDIS6_CONF
@@ -62,7 +65,18 @@ pidfile /tmp/redis6.pid
logfile /tmp/redis6.log
save ""
appendonly no
-slaveof localhost 6379
+endef
+
+define REDIS7_CONF
+daemonize yes
+port 6385
+requirepass foobared
+masterauth foobared
+pidfile /tmp/redis7.pid
+logfile /tmp/redis7.log
+save ""
+appendonly no
+slaveof localhost 6384
endef
# SENTINELS
@@ -71,8 +85,8 @@ port 26379
daemonize yes
sentinel monitor mymaster 127.0.0.1 6379 1
sentinel auth-pass mymaster foobared
-sentinel down-after-milliseconds mymaster 3000
-sentinel failover-timeout mymaster 900000
+sentinel down-after-milliseconds mymaster 2000
+sentinel failover-timeout mymaster 120000
sentinel parallel-syncs mymaster 1
pidfile /tmp/sentinel1.pid
logfile /tmp/sentinel1.log
@@ -81,11 +95,11 @@ endef
define REDIS_SENTINEL2
port 26380
daemonize yes
-sentinel monitor mymaster 127.0.0.1 6381 2
+sentinel monitor mymaster 127.0.0.1 6381 1
sentinel auth-pass mymaster foobared
-sentinel down-after-milliseconds mymaster 3000
+sentinel down-after-milliseconds mymaster 2000
sentinel parallel-syncs mymaster 1
-sentinel failover-timeout mymaster 900000
+sentinel failover-timeout mymaster 120000
pidfile /tmp/sentinel2.pid
logfile /tmp/sentinel2.log
endef
@@ -93,11 +107,11 @@ endef
define REDIS_SENTINEL3
port 26381
daemonize yes
-sentinel monitor mymaster 127.0.0.1 6381 2
-sentinel auth-pass mymaster foobared
-sentinel down-after-milliseconds mymaster 3000
-sentinel parallel-syncs mymaster 1
-sentinel failover-timeout mymaster 900000
+sentinel monitor mymasterfailover 127.0.0.1 6384 1
+sentinel auth-pass mymasterfailover foobared
+sentinel down-after-milliseconds mymasterfailover 2000
+sentinel failover-timeout mymasterfailover 120000
+sentinel parallel-syncs mymasterfailover 1
pidfile /tmp/sentinel3.pid
logfile /tmp/sentinel3.log
endef
@@ -106,6 +120,7 @@ endef
define REDIS_CLUSTER_NODE1_CONF
daemonize yes
port 7379
+cluster-node-timeout 50
pidfile /tmp/redis_cluster_node1.pid
logfile /tmp/redis_cluster_node1.log
save ""
@@ -117,6 +132,7 @@ endef
define REDIS_CLUSTER_NODE2_CONF
daemonize yes
port 7380
+cluster-node-timeout 50
pidfile /tmp/redis_cluster_node2.pid
logfile /tmp/redis_cluster_node2.log
save ""
@@ -128,6 +144,7 @@ endef
define REDIS_CLUSTER_NODE3_CONF
daemonize yes
port 7381
+cluster-node-timeout 50
pidfile /tmp/redis_cluster_node3.pid
logfile /tmp/redis_cluster_node3.log
save ""
@@ -136,18 +153,58 @@ cluster-enabled yes
cluster-config-file /tmp/redis_cluster_node3.conf
endef
+define REDIS_CLUSTER_NODE4_CONF
+daemonize yes
+port 7382
+cluster-node-timeout 50
+pidfile /tmp/redis_cluster_node4.pid
+logfile /tmp/redis_cluster_node4.log
+save ""
+appendonly no
+cluster-enabled yes
+cluster-config-file /tmp/redis_cluster_node4.conf
+endef
+
+define REDIS_CLUSTER_NODE5_CONF
+daemonize yes
+port 7383
+cluster-node-timeout 5000
+pidfile /tmp/redis_cluster_node5.pid
+logfile /tmp/redis_cluster_node5.log
+save ""
+appendonly no
+cluster-enabled yes
+cluster-config-file /tmp/redis_cluster_node5.conf
+endef
+
+define REDIS_CLUSTER_NODE6_CONF
+daemonize yes
+port 7384
+cluster-node-timeout 5000
+pidfile /tmp/redis_cluster_node6.pid
+logfile /tmp/redis_cluster_node6.log
+save ""
+appendonly no
+cluster-enabled yes
+cluster-config-file /tmp/redis_cluster_node6.conf
+endef
+
export REDIS1_CONF
export REDIS2_CONF
export REDIS3_CONF
export REDIS4_CONF
export REDIS5_CONF
export REDIS6_CONF
+export REDIS7_CONF
export REDIS_SENTINEL1
export REDIS_SENTINEL2
export REDIS_SENTINEL3
export REDIS_CLUSTER_NODE1_CONF
export REDIS_CLUSTER_NODE2_CONF
export REDIS_CLUSTER_NODE3_CONF
+export REDIS_CLUSTER_NODE4_CONF
+export REDIS_CLUSTER_NODE5_CONF
+export REDIS_CLUSTER_NODE6_CONF
start: cleanup
echo "$$REDIS1_CONF" | redis-server -
@@ -156,6 +213,7 @@ start: cleanup
echo "$$REDIS4_CONF" | redis-server -
echo "$$REDIS5_CONF" | redis-server -
echo "$$REDIS6_CONF" | redis-server -
+ echo "$$REDIS7_CONF" | redis-server -
echo "$$REDIS_SENTINEL1" > /tmp/sentinel1.conf && redis-server /tmp/sentinel1.conf --sentinel
@sleep 0.5
echo "$$REDIS_SENTINEL2" > /tmp/sentinel2.conf && redis-server /tmp/sentinel2.conf --sentinel
@@ -164,27 +222,40 @@ start: cleanup
echo "$$REDIS_CLUSTER_NODE1_CONF" | redis-server -
echo "$$REDIS_CLUSTER_NODE2_CONF" | redis-server -
echo "$$REDIS_CLUSTER_NODE3_CONF" | redis-server -
+ echo "$$REDIS_CLUSTER_NODE4_CONF" | redis-server -
+ echo "$$REDIS_CLUSTER_NODE5_CONF" | redis-server -
+ echo "$$REDIS_CLUSTER_NODE6_CONF" | redis-server -
cleanup:
- rm -vf /tmp/redis_cluster_node*.conf
+ - rm -vf /tmp/redis_cluster_node*.conf 2>/dev/null
+ - rm dump.rdb appendonly.aof - 2>/dev/null
stop:
kill `cat /tmp/redis1.pid`
kill `cat /tmp/redis2.pid`
- # this get's segfaulted by the tests
- kill `cat /tmp/redis3.pid` || true
- kill `cat /tmp/redis4.pid` || true
- kill `cat /tmp/redis5.pid` || true
- kill `cat /tmp/redis6.pid` || true
+ kill `cat /tmp/redis3.pid`
+ kill `cat /tmp/redis4.pid`
+ kill `cat /tmp/redis5.pid`
+ kill `cat /tmp/redis6.pid`
+ kill `cat /tmp/redis7.pid`
kill `cat /tmp/sentinel1.pid`
kill `cat /tmp/sentinel2.pid`
kill `cat /tmp/sentinel3.pid`
kill `cat /tmp/redis_cluster_node1.pid` || true
kill `cat /tmp/redis_cluster_node2.pid` || true
kill `cat /tmp/redis_cluster_node3.pid` || true
+ kill `cat /tmp/redis_cluster_node4.pid` || true
+ kill `cat /tmp/redis_cluster_node5.pid` || true
+ kill `cat /tmp/redis_cluster_node6.pid` || true
+ rm -f /tmp/sentinel1.conf
+ rm -f /tmp/sentinel2.conf
+ rm -f /tmp/sentinel3.conf
rm -f /tmp/redis_cluster_node1.conf
rm -f /tmp/redis_cluster_node2.conf
rm -f /tmp/redis_cluster_node3.conf
+ rm -f /tmp/redis_cluster_node4.conf
+ rm -f /tmp/redis_cluster_node5.conf
+ rm -f /tmp/redis_cluster_node6.conf
test:
make start
@@ -192,6 +263,11 @@ test:
mvn -Dtest=${TEST} clean compile test
make stop
+package:
+ make start
+ mvn clean package
+ make stop
+
deploy:
make start
mvn clean deploy
@@ -204,4 +280,8 @@ release:
mvn release:perform
make stop
+travis-install:
+ [ ! -e redis-git ] && git clone https://github.com/antirez/redis.git redis-git || true
+ make -C redis-git -j4
+
.PHONY: test
diff --git a/README.md b/README.md
index b5b7219..bce8aa1 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,12 @@
+[](https://travis-ci.org/xetorthio/jedis)
+
# Jedis
Jedis is a blazingly small and sane [Redis](http://github.com/antirez/redis "Redis") java client.
Jedis was conceived to be EASY to use.
-Jedis is fully compatible with redis 2.6.14.
+Jedis is fully compatible with redis 2.8.5.
## Community
@@ -38,7 +40,7 @@ All of the following redis features are supported:
## How do I use it?
You can download the latest build at:
- http://github.com/xetorthio/jedis/downloads
+ http://github.com/xetorthio/jedis/releases
Or use it as a maven dependency:
@@ -46,7 +48,7 @@ Or use it as a maven dependency:
redis.clientsjedis
- 2.2.1
+ 2.4.2jarcompile
@@ -73,8 +75,8 @@ Redis cluster [specification](http://redis.io/topics/cluster-spec) (still under
```java
Set jedisClusterNodes = new HashSet();
//Jedis Cluster will attempt to discover cluster nodes automatically
-jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
-JedisCluster jc = new JedisCluster(jedisClusterNode);
+jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7379));
+JedisCluster jc = new JedisCluster(jedisClusterNodes);
jc.set("foo", "bar");
String value = jc.get("foo");
```
diff --git a/build.gradle b/build.gradle
index 30af731..3905e3e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,7 +3,7 @@ apply plugin: 'maven'
apply plugin: 'eclipse'
group = 'com.googlecode.jedis'
-archiveBaseName = 'jedis'
+archivesBaseName = 'jedis'
version = '1.5.0'
repositories {
diff --git a/pom.xml b/pom.xml
index f6575eb..2ad2a55 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
jarredis.clientsjedis
- 2.2.2-SNAPSHOT
+ 2.5.2-SNAPSHOTJedisJedis is a blazingly small and sane Redis java client.https://github.com/xetorthio/jedis
@@ -45,9 +45,9 @@
- localhost:6379,localhost:6380,localhost:6381,localhost:6382,localhost:6383,localhost:6384
+ localhost:6379,localhost:6380,localhost:6381,localhost:6382,localhost:6383,localhost:6384,localhost:6385localhost:26379,localhost:26380,localhost:26381
- localhost:7379,localhost:7380,localhost:7381
+ localhost:7379,localhost:7380,localhost:7381,localhost:7382,localhost:7383,localhost:7384,localhost:7385github
diff --git a/src/main/java/redis/clients/jedis/AdvancedBinaryJedisCommands.java b/src/main/java/redis/clients/jedis/AdvancedBinaryJedisCommands.java
index 51b4879..224dd11 100644
--- a/src/main/java/redis/clients/jedis/AdvancedBinaryJedisCommands.java
+++ b/src/main/java/redis/clients/jedis/AdvancedBinaryJedisCommands.java
@@ -1,6 +1,5 @@
package redis.clients.jedis;
-
import java.util.List;
public interface AdvancedBinaryJedisCommands {
diff --git a/src/main/java/redis/clients/jedis/AdvancedJedisCommands.java b/src/main/java/redis/clients/jedis/AdvancedJedisCommands.java
index 5ed50eb..45e825b 100644
--- a/src/main/java/redis/clients/jedis/AdvancedJedisCommands.java
+++ b/src/main/java/redis/clients/jedis/AdvancedJedisCommands.java
@@ -1,9 +1,8 @@
package redis.clients.jedis;
-import redis.clients.util.Slowlog;
-
import java.util.List;
+import redis.clients.util.Slowlog;
public interface AdvancedJedisCommands {
List configGet(String pattern);
diff --git a/src/main/java/redis/clients/jedis/BasicCommands.java b/src/main/java/redis/clients/jedis/BasicCommands.java
index 5b7e995..c201e41 100644
--- a/src/main/java/redis/clients/jedis/BasicCommands.java
+++ b/src/main/java/redis/clients/jedis/BasicCommands.java
@@ -27,7 +27,7 @@ public interface BasicCommands {
String shutdown();
String info();
-
+
String info(String section);
String slaveof(String host, int port);
@@ -39,6 +39,6 @@ public interface BasicCommands {
String debug(DebugParams params);
String configResetStat();
-
+
Long waitReplicas(int replicas, long timeout);
}
diff --git a/src/main/java/redis/clients/jedis/BasicRedisPipeline.java b/src/main/java/redis/clients/jedis/BasicRedisPipeline.java
index a667ce9..c56a972 100644
--- a/src/main/java/redis/clients/jedis/BasicRedisPipeline.java
+++ b/src/main/java/redis/clients/jedis/BasicRedisPipeline.java
@@ -1,5 +1,6 @@
package redis.clients.jedis;
+import java.util.List;
/**
* Pipelined responses for all of the low level, non key related commands
@@ -25,6 +26,8 @@ public interface BasicRedisPipeline {
Response flushAll();
Response info();
+
+ Response> time();
Response dbSize();
diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java
index f1b167a..9f78d8e 100644
--- a/src/main/java/redis/clients/jedis/BinaryClient.java
+++ b/src/main/java/redis/clients/jedis/BinaryClient.java
@@ -34,10 +34,16 @@ public class BinaryClient extends Connection {
private long db;
+ private boolean isInWatch;
+
public boolean isInMulti() {
return isInMulti;
}
+ public boolean isInWatch() {
+ return isInWatch;
+ }
+
public BinaryClient(final String host) {
super(host);
}
@@ -82,11 +88,11 @@ public class BinaryClient extends Connection {
sendCommand(Command.SET, key, value);
}
- public void set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final long time) {
- sendCommand(Command.SET, key, value, nxxx, expx, toByteArray(time));
+ public void set(final byte[] key, final byte[] value, final byte[] nxxx,
+ final byte[] expx, final long time) {
+ sendCommand(Command.SET, key, value, nxxx, expx, toByteArray(time));
}
-
public void get(final byte[] key) {
sendCommand(Command.GET, key);
}
@@ -193,6 +199,10 @@ public class BinaryClient extends Connection {
sendCommand(INCRBY, key, toByteArray(integer));
}
+ public void incrByFloat(final byte[] key, final double value) {
+ sendCommand(INCRBYFLOAT, key, toByteArray(value));
+ }
+
public void incr(final byte[] key) {
sendCommand(INCR, key);
}
@@ -310,7 +320,7 @@ public class BinaryClient extends Connection {
public void sadd(final byte[] key, final byte[]... members) {
sendCommand(SADD, joinParameters(key, members));
}
-
+
public void smembers(final byte[] key) {
sendCommand(SMEMBERS, key);
}
@@ -377,15 +387,16 @@ public class BinaryClient extends Connection {
sendCommand(ZADD, key, toByteArray(score), member);
}
- public void zaddBinary(final byte[] key, Map scoreMembers) {
+ public void zaddBinary(final byte[] key,
+ final Map scoreMembers) {
+
ArrayList args = new ArrayList(
scoreMembers.size() * 2 + 1);
-
args.add(key);
- for (Map.Entry entry : scoreMembers.entrySet()) {
- args.add(toByteArray(entry.getKey()));
- args.add(entry.getValue());
+ for (Map.Entry entry : scoreMembers.entrySet()) {
+ args.add(toByteArray(entry.getValue()));
+ args.add(entry.getKey());
}
byte[][] argsArray = new byte[args.size()][];
@@ -447,19 +458,23 @@ public class BinaryClient extends Connection {
public void discard() {
sendCommand(DISCARD);
isInMulti = false;
+ isInWatch = false;
}
public void exec() {
sendCommand(EXEC);
isInMulti = false;
+ isInWatch = false;
}
public void watch(final byte[]... keys) {
sendCommand(WATCH, keys);
+ isInWatch = true;
}
public void unwatch() {
sendCommand(UNWATCH);
+ isInWatch = false;
}
public void sort(final byte[] key) {
@@ -476,14 +491,14 @@ public class BinaryClient extends Connection {
public void blpop(final byte[][] args) {
sendCommand(BLPOP, args);
}
-
+
public void blpop(final int timeout, final byte[]... keys) {
- final List args = new ArrayList();
- for (final byte[] arg : keys) {
- args.add(arg);
- }
- args.add(Protocol.toByteArray(timeout));
- blpop(args.toArray(new byte[args.size()][]));
+ final List args = new ArrayList();
+ for (final byte[] arg : keys) {
+ args.add(arg);
+ }
+ args.add(Protocol.toByteArray(timeout));
+ blpop(args.toArray(new byte[args.size()][]));
}
public void sort(final byte[] key, final SortingParams sortingParameters,
@@ -503,14 +518,14 @@ public class BinaryClient extends Connection {
public void brpop(final byte[][] args) {
sendCommand(BRPOP, args);
}
-
+
public void brpop(final int timeout, final byte[]... keys) {
- final List args = new ArrayList();
- for (final byte[] arg : keys) {
- args.add(arg);
- }
- args.add(Protocol.toByteArray(timeout));
- brpop(args.toArray(new byte[args.size()][]));
+ final List args = new ArrayList();
+ for (final byte[] arg : keys) {
+ args.add(arg);
+ }
+ args.add(Protocol.toByteArray(timeout));
+ brpop(args.toArray(new byte[args.size()][]));
}
public void auth(final String password) {
@@ -543,32 +558,39 @@ public class BinaryClient extends Connection {
}
public void punsubscribe(final byte[]... patterns) {
- sendCommand(PUNSUBSCRIBE, patterns);
+ sendCommand(PUNSUBSCRIBE, patterns);
+ }
+
+ public void pubsub(final byte[]... args) {
+ sendCommand(PUBSUB, args);
}
-
public void zcount(final byte[] key, final double min, final double max) {
- byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
- byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
+ byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
+ .getBytes() : toByteArray(min);
+ byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
+ .getBytes() : toByteArray(max);
- sendCommand(ZCOUNT, key, byteArrayMin, byteArrayMax);
+ sendCommand(ZCOUNT, key, byteArrayMin, byteArrayMax);
}
public void zcount(final byte[] key, final byte min[], final byte max[]) {
- sendCommand(ZCOUNT, key, min, max);
+ sendCommand(ZCOUNT, key, min, max);
}
public void zcount(final byte[] key, final String min, final String max) {
- sendCommand(ZCOUNT, key, min.getBytes(), max.getBytes());
+ sendCommand(ZCOUNT, key, min.getBytes(), max.getBytes());
}
public void zrangeByScore(final byte[] key, final double min,
- final double max) {
+ final double max) {
- byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
- byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
+ byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
+ .getBytes() : toByteArray(min);
+ byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
+ .getBytes() : toByteArray(max);
- sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax);
+ sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax);
}
public void zrangeByScore(final byte[] key, final byte[] min,
@@ -577,17 +599,19 @@ public class BinaryClient extends Connection {
}
public void zrangeByScore(final byte[] key, final String min,
- final String max) {
- sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes());
+ final String max) {
+ sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes());
}
public void zrevrangeByScore(final byte[] key, final double max,
- final double min) {
+ final double min) {
- byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
- byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
+ byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
+ .getBytes() : toByteArray(min);
+ byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
+ .getBytes() : toByteArray(max);
- sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin);
+ sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin);
}
public void zrevrangeByScore(final byte[] key, final byte[] max,
@@ -596,114 +620,125 @@ public class BinaryClient extends Connection {
}
public void zrevrangeByScore(final byte[] key, final String max,
- final String min) {
- sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes());
+ final String min) {
+ sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes());
}
public void zrangeByScore(final byte[] key, final double min,
- final double max, final int offset, int count) {
+ final double max, final int offset, int count) {
- byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
- byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
+ byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
+ .getBytes() : toByteArray(min);
+ byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
+ .getBytes() : toByteArray(max);
- sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax,
- LIMIT.raw, toByteArray(offset), toByteArray(count));
+ sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax, LIMIT.raw,
+ toByteArray(offset), toByteArray(count));
}
-
- public void zrangeByScore(final byte[] key, final String min,
- final String max, final int offset, int count) {
- sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(),
- LIMIT.raw, toByteArray(offset), toByteArray(count));
+ public void zrangeByScore(final byte[] key, final String min,
+ final String max, final int offset, int count) {
+
+ sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(),
+ LIMIT.raw, toByteArray(offset), toByteArray(count));
}
public void zrevrangeByScore(final byte[] key, final double max,
- final double min, final int offset, int count) {
+ final double min, final int offset, int count) {
- byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
- byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
+ byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
+ .getBytes() : toByteArray(min);
+ byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
+ .getBytes() : toByteArray(max);
- sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin,
- LIMIT.raw, toByteArray(offset), toByteArray(count));
- }
+ sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin,
+ LIMIT.raw, toByteArray(offset), toByteArray(count));
+ }
public void zrevrangeByScore(final byte[] key, final String max,
- final String min, final int offset, int count) {
+ final String min, final int offset, int count) {
- sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(),
- LIMIT.raw, toByteArray(offset), toByteArray(count));
+ sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(),
+ LIMIT.raw, toByteArray(offset), toByteArray(count));
}
public void zrangeByScoreWithScores(final byte[] key, final double min,
- final double max) {
+ final double max) {
- byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
- byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
+ byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
+ .getBytes() : toByteArray(min);
+ byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
+ .getBytes() : toByteArray(max);
- sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax,
- WITHSCORES.raw);
+ sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax,
+ WITHSCORES.raw);
}
public void zrangeByScoreWithScores(final byte[] key, final String min,
- final String max) {
+ final String max) {
- sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(),
- WITHSCORES.raw);
+ sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(),
+ WITHSCORES.raw);
}
public void zrevrangeByScoreWithScores(final byte[] key, final double max,
- final double min) {
+ final double min) {
- byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
- byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
+ byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
+ .getBytes() : toByteArray(min);
+ byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
+ .getBytes() : toByteArray(max);
- sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin,
- WITHSCORES.raw);
+ sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin,
+ WITHSCORES.raw);
}
public void zrevrangeByScoreWithScores(final byte[] key, final String max,
- final String min) {
- sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(),
- WITHSCORES.raw);
+ final String min) {
+ sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(),
+ WITHSCORES.raw);
}
public void zrangeByScoreWithScores(final byte[] key, final double min,
- final double max, final int offset, final int count) {
+ final double max, final int offset, final int count) {
- byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
- byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
+ byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
+ .getBytes() : toByteArray(min);
+ byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
+ .getBytes() : toByteArray(max);
- sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax,
- LIMIT.raw, toByteArray(offset), toByteArray(count),
- WITHSCORES.raw);
+ sendCommand(ZRANGEBYSCORE, key, byteArrayMin, byteArrayMax, LIMIT.raw,
+ toByteArray(offset), toByteArray(count), WITHSCORES.raw);
}
public void zrangeByScoreWithScores(final byte[] key, final String min,
- final String max, final int offset, final int count) {
- sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(),
- LIMIT.raw, toByteArray(offset), toByteArray(count),
- WITHSCORES.raw);
+ final String max, final int offset, final int count) {
+ sendCommand(ZRANGEBYSCORE, key, min.getBytes(), max.getBytes(),
+ LIMIT.raw, toByteArray(offset), toByteArray(count),
+ WITHSCORES.raw);
}
public void zrevrangeByScoreWithScores(final byte[] key, final double max,
- final double min, final int offset, final int count) {
+ final double min, final int offset, final int count) {
- byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf".getBytes() : toByteArray(min);
- byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf".getBytes() : toByteArray(max);
+ byte byteArrayMin[] = (min == Double.NEGATIVE_INFINITY) ? "-inf"
+ .getBytes() : toByteArray(min);
+ byte byteArrayMax[] = (max == Double.POSITIVE_INFINITY) ? "+inf"
+ .getBytes() : toByteArray(max);
- sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin,
- LIMIT.raw, toByteArray(offset), toByteArray(count),
- WITHSCORES.raw);
+ sendCommand(ZREVRANGEBYSCORE, key, byteArrayMax, byteArrayMin,
+ LIMIT.raw, toByteArray(offset), toByteArray(count),
+ WITHSCORES.raw);
}
public void zrevrangeByScoreWithScores(final byte[] key, final String max,
- final String min, final int offset, final int count) {
+ final String min, final int offset, final int count) {
- sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(),
- LIMIT.raw, toByteArray(offset), toByteArray(count),
- WITHSCORES.raw);
+ sendCommand(ZREVRANGEBYSCORE, key, max.getBytes(), min.getBytes(),
+ LIMIT.raw, toByteArray(offset), toByteArray(count),
+ WITHSCORES.raw);
}
-
+
public void zrangeByScore(final byte[] key, final byte[] min,
final byte[] max, final int offset, int count) {
sendCommand(ZRANGEBYSCORE, key, min, max, LIMIT.raw,
@@ -746,11 +781,11 @@ public class BinaryClient extends Connection {
public void zremrangeByScore(final byte[] key, final byte[] start,
final byte[] end) {
sendCommand(ZREMRANGEBYSCORE, key, start, end);
- }
+ }
public void zremrangeByScore(final byte[] key, final String start,
- final String end) {
- sendCommand(ZREMRANGEBYSCORE, key, start.getBytes(), end.getBytes());
+ final String end) {
+ sendCommand(ZREMRANGEBYSCORE, key, start.getBytes(), end.getBytes());
}
public void zunionstore(final byte[] dstkey, final byte[]... sets) {
@@ -816,7 +851,7 @@ public class BinaryClient extends Connection {
public void info() {
sendCommand(INFO);
}
-
+
public void info(final String section) {
sendCommand(INFO, section);
}
@@ -888,13 +923,21 @@ public class BinaryClient extends Connection {
}
public void setbit(byte[] key, long offset, boolean value) {
- sendCommand(SETBIT, key, toByteArray(offset), toByteArray(value));
+ sendCommand(SETBIT, key, toByteArray(offset), toByteArray(value));
}
public void getbit(byte[] key, long offset) {
sendCommand(GETBIT, key, toByteArray(offset));
}
-
+
+ public void bitpos(final byte[] key, final boolean value, final BitPosParams params) {
+ final List args = new ArrayList();
+ args.add(key);
+ args.add(toByteArray(value));
+ args.addAll(params.getParams());
+ sendCommand(BITPOS, args.toArray(new byte[args.size()][]));
+ }
+
public void setrange(byte[] key, long offset, byte[] value) {
sendCommand(SETRANGE, key, toByteArray(offset), value);
}
@@ -913,6 +956,17 @@ public class BinaryClient extends Connection {
super.disconnect();
}
+ @Override
+ public void close() {
+ db = 0;
+ super.close();
+ }
+
+ public void resetState() {
+ if (isInWatch())
+ unwatch();
+ }
+
private void sendEvalCommand(Command command, byte[] script,
byte[] keyCount, byte[][] params) {
@@ -932,7 +986,7 @@ public class BinaryClient extends Connection {
}
public void eval(byte[] script, int keyCount, byte[]... params) {
- eval(script, toByteArray(keyCount), params);
+ eval(script, toByteArray(keyCount), params);
}
public void evalsha(byte[] sha1, byte[] keyCount, byte[]... params) {
@@ -940,7 +994,7 @@ public class BinaryClient extends Connection {
}
public void evalsha(byte[] sha1, int keyCount, byte[]... params) {
- sendEvalCommand(EVALSHA, sha1, toByteArray(keyCount), params);
+ sendEvalCommand(EVALSHA, sha1, toByteArray(keyCount), params);
}
public void scriptFlush() {
@@ -993,153 +1047,232 @@ public class BinaryClient extends Connection {
}
public void bitcount(byte[] key) {
- sendCommand(BITCOUNT, key);
+ sendCommand(BITCOUNT, key);
}
public void bitcount(byte[] key, long start, long end) {
- sendCommand(BITCOUNT, key, toByteArray(start), toByteArray(end));
+ sendCommand(BITCOUNT, key, toByteArray(start), toByteArray(end));
}
public void bitop(BitOP op, byte[] destKey, byte[]... srcKeys) {
- Keyword kw = Keyword.AND;
- int len = srcKeys.length;
- switch (op) {
- case AND:
- kw = Keyword.AND;
- break;
- case OR:
- kw = Keyword.OR;
- break;
- case XOR:
- kw = Keyword.XOR;
- break;
- case NOT:
- kw = Keyword.NOT;
- len = Math.min(1, len);
- break;
- }
+ Keyword kw = Keyword.AND;
+ int len = srcKeys.length;
+ switch (op) {
+ case AND:
+ kw = Keyword.AND;
+ break;
+ case OR:
+ kw = Keyword.OR;
+ break;
+ case XOR:
+ kw = Keyword.XOR;
+ break;
+ case NOT:
+ kw = Keyword.NOT;
+ len = Math.min(1, len);
+ break;
+ }
- byte[][] bargs = new byte[len + 2][];
- bargs[0] = kw.raw;
- bargs[1] = destKey;
- for (int i = 0; i < len; ++i) {
- bargs[i + 2] = srcKeys[i];
- }
+ byte[][] bargs = new byte[len + 2][];
+ bargs[0] = kw.raw;
+ bargs[1] = destKey;
+ for (int i = 0; i < len; ++i) {
+ bargs[i + 2] = srcKeys[i];
+ }
- sendCommand(BITOP, bargs);
+ sendCommand(BITOP, bargs);
}
public void sentinel(final byte[]... args) {
- sendCommand(SENTINEL, args);
+ sendCommand(SENTINEL, args);
}
-
+
public void dump(final byte[] key) {
- sendCommand(DUMP, key);
+ sendCommand(DUMP, key);
}
-
- public void restore(final byte[] key, final int ttl, final byte[] serializedValue) {
- sendCommand(RESTORE, key, toByteArray(ttl), serializedValue);
+
+ public void restore(final byte[] key, final int ttl,
+ final byte[] serializedValue) {
+ sendCommand(RESTORE, key, toByteArray(ttl), serializedValue);
}
-
+
+ @Deprecated
public void pexpire(final byte[] key, final int milliseconds) {
- sendCommand(PEXPIRE, key, toByteArray(milliseconds));
+ pexpire(key, (long) milliseconds);
}
-
+
+ public void pexpire(final byte[] key, final long milliseconds) {
+ sendCommand(PEXPIRE, key, toByteArray(milliseconds));
+ }
+
public void pexpireAt(final byte[] key, final long millisecondsTimestamp) {
- sendCommand(PEXPIREAT, key, toByteArray(millisecondsTimestamp));
+ sendCommand(PEXPIREAT, key, toByteArray(millisecondsTimestamp));
}
-
+
public void pttl(final byte[] key) {
- sendCommand(PTTL, key);
+ sendCommand(PTTL, key);
}
-
- public void incrByFloat(final byte[] key, final double increment) {
- sendCommand(INCRBYFLOAT, key, toByteArray(increment));
+
+ public void psetex(final byte[] key, final int milliseconds,
+ final byte[] value) {
+ sendCommand(PSETEX, key, toByteArray(milliseconds), value);
}
-
- public void psetex(final byte[] key, final int milliseconds, final byte[] value) {
- sendCommand(PSETEX, key, toByteArray(milliseconds), value);
- }
-
+
public void set(final byte[] key, final byte[] value, final byte[] nxxx) {
- sendCommand(Command.SET, key, value, nxxx);
+ sendCommand(Command.SET, key, value, nxxx);
}
-
- public void set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final int time) {
- sendCommand(Command.SET, key, value, nxxx, expx, toByteArray(time));
+
+ public void set(final byte[] key, final byte[] value, final byte[] nxxx,
+ final byte[] expx, final int time) {
+ sendCommand(Command.SET, key, value, nxxx, expx, toByteArray(time));
}
-
+
public void srandmember(final byte[] key, final int count) {
- sendCommand(SRANDMEMBER, key, toByteArray(count));
+ sendCommand(SRANDMEMBER, key, toByteArray(count));
}
-
+
public void clientKill(final byte[] client) {
- sendCommand(CLIENT, Keyword.KILL.raw, client);
+ sendCommand(CLIENT, Keyword.KILL.raw, client);
}
-
+
public void clientGetname() {
- sendCommand(CLIENT, Keyword.GETNAME.raw);
+ sendCommand(CLIENT, Keyword.GETNAME.raw);
}
-
+
public void clientList() {
- sendCommand(CLIENT, Keyword.LIST.raw);
+ sendCommand(CLIENT, Keyword.LIST.raw);
}
-
+
public void clientSetname(final byte[] name) {
- sendCommand(CLIENT, Keyword.SETNAME.raw, name);
+ sendCommand(CLIENT, Keyword.SETNAME.raw, name);
}
-
+
public void time() {
- sendCommand(TIME);
+ sendCommand(TIME);
}
-
- public void migrate(final byte[] host, final int port, final byte[] key, final int destinationDb, final int timeout) {
- sendCommand(MIGRATE, host, toByteArray(port), key, toByteArray(destinationDb), toByteArray(timeout));
+
+ public void migrate(final byte[] host, final int port, final byte[] key,
+ final int destinationDb, final int timeout) {
+ sendCommand(MIGRATE, host, toByteArray(port), key,
+ toByteArray(destinationDb), toByteArray(timeout));
}
-
- public void hincrByFloat(final byte[] key, final byte[] field, double increment) {
- sendCommand(HINCRBYFLOAT, key, field, toByteArray(increment));
+
+ public void hincrByFloat(final byte[] key, final byte[] field,
+ double increment) {
+ sendCommand(HINCRBYFLOAT, key, field, toByteArray(increment));
}
-
+
+ @Deprecated
+ /**
+ * This method is deprecated due to bug (scan cursor should be unsigned long)
+ * And will be removed on next major release
+ * @see https://github.com/xetorthio/jedis/issues/531
+ */
public void scan(int cursor, final ScanParams params) {
final List args = new ArrayList();
args.add(toByteArray(cursor));
args.addAll(params.getParams());
sendCommand(SCAN, args.toArray(new byte[args.size()][]));
}
-
+
+ @Deprecated
+ /**
+ * This method is deprecated due to bug (scan cursor should be unsigned long)
+ * And will be removed on next major release
+ * @see https://github.com/xetorthio/jedis/issues/531
+ */
public void hscan(final byte[] key, int cursor, final ScanParams params) {
- final List args = new ArrayList();
- args.add(key);
- args.add(toByteArray(cursor));
- args.addAll(params.getParams());
- sendCommand(HSCAN, args.toArray(new byte[args.size()][]));
+ final List args = new ArrayList();
+ args.add(key);
+ args.add(toByteArray(cursor));
+ args.addAll(params.getParams());
+ sendCommand(HSCAN, args.toArray(new byte[args.size()][]));
}
+ @Deprecated
+ /**
+ * This method is deprecated due to bug (scan cursor should be unsigned long)
+ * And will be removed on next major release
+ * @see https://github.com/xetorthio/jedis/issues/531
+ */
public void sscan(final byte[] key, int cursor, final ScanParams params) {
- final List args = new ArrayList();
- args.add(key);
- args.add(toByteArray(cursor));
- args.addAll(params.getParams());
- sendCommand(SSCAN, args.toArray(new byte[args.size()][]));
+ final List args = new ArrayList();
+ args.add(key);
+ args.add(toByteArray(cursor));
+ args.addAll(params.getParams());
+ sendCommand(SSCAN, args.toArray(new byte[args.size()][]));
}
+ @Deprecated
+ /**
+ * This method is deprecated due to bug (scan cursor should be unsigned long)
+ * And will be removed on next major release
+ * @see https://github.com/xetorthio/jedis/issues/531
+ */
public void zscan(final byte[] key, int cursor, final ScanParams params) {
- final List args = new ArrayList();
- args.add(key);
- args.add(toByteArray(cursor));
- args.addAll(params.getParams());
- sendCommand(ZSCAN, args.toArray(new byte[args.size()][]));
+ final List args = new ArrayList();
+ args.add(key);
+ args.add(toByteArray(cursor));
+ args.addAll(params.getParams());
+ sendCommand(ZSCAN, args.toArray(new byte[args.size()][]));
}
+ public void scan(final byte[] cursor, final ScanParams params) {
+ final List args = new ArrayList();
+ args.add(cursor);
+ args.addAll(params.getParams());
+ sendCommand(SCAN, args.toArray(new byte[args.size()][]));
+ }
+
+ public void hscan(final byte[] key, final byte[] cursor, final ScanParams params) {
+ final List args = new ArrayList();
+ args.add(key);
+ args.add(cursor);
+ args.addAll(params.getParams());
+ sendCommand(HSCAN, args.toArray(new byte[args.size()][]));
+ }
+
+ public void sscan(final byte[] key, final byte[] cursor, final ScanParams params) {
+ final List args = new ArrayList();
+ args.add(key);
+ args.add(cursor);
+ args.addAll(params.getParams());
+ sendCommand(SSCAN, args.toArray(new byte[args.size()][]));
+ }
+
+ public void zscan(final byte[] key, final byte[] cursor, final ScanParams params) {
+ final List args = new ArrayList();
+ args.add(key);
+ args.add(cursor);
+ args.addAll(params.getParams());
+ sendCommand(ZSCAN, args.toArray(new byte[args.size()][]));
+ }
+
public void waitReplicas(int replicas, long timeout) {
sendCommand(WAIT, toByteArray(replicas), toByteArray(timeout));
}
public void cluster(final byte[]... args) {
- sendCommand(CLUSTER, args);
+ sendCommand(CLUSTER, args);
}
+
public void asking() {
- sendCommand(Command.ASKING);
+ sendCommand(Command.ASKING);
+ }
+
+ public void pfadd(final byte[] key, final byte[]... elements) {
+ sendCommand(PFADD, joinParameters(key, elements));
+ }
+
+ public void pfcount(final byte[] key) {
+ sendCommand(PFCOUNT, key);
+ }
+
+ public void pfcount(final byte[]...keys) {
+ sendCommand(PFCOUNT, keys);
+ }
+
+ public void pfmerge(final byte[] destkey, final byte[]... sourcekeys) {
+ sendCommand(PFMERGE, joinParameters(destkey, sourcekeys));
}
}
diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java
index af5a395..f76a391 100644
--- a/src/main/java/redis/clients/jedis/BinaryJedis.java
+++ b/src/main/java/redis/clients/jedis/BinaryJedis.java
@@ -1,18 +1,31 @@
package redis.clients.jedis;
+import static redis.clients.jedis.Protocol.toByteArray;
+
+import java.io.Closeable;
+import java.net.URI;
+import java.util.AbstractMap;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import redis.clients.jedis.BinaryClient.LIST_POSITION;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.exceptions.JedisException;
import redis.clients.util.JedisByteHashMap;
import redis.clients.util.SafeEncoder;
-import java.net.URI;
-import java.util.*;
+public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
+ MultiKeyBinaryCommands, AdvancedBinaryJedisCommands,
+ BinaryScriptingCommands, Closeable {
-import static redis.clients.jedis.Protocol.toByteArray;
-
-public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKeyBinaryCommands, AdvancedBinaryJedisCommands, BinaryScriptingCommands {
protected Client client = null;
+ protected Transaction transaction = null;
+ protected Pipeline pipeline = null;
public BinaryJedis(final String host) {
URI uri = URI.create(host);
@@ -75,18 +88,23 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
/**
* Set the string value as value of the key. The string can't be longer than
* 1073741824 bytes (1 GB).
+ *
* @param key
* @param value
- * @param nxxx NX|XX, NX -- Only set the key if it does not already exist.
- * XX -- Only set the key if it already exist.
- * @param expx EX|PX, expire time units: EX = seconds; PX = milliseconds
- * @param time expire time in the units of {@param #expx}
+ * @param nxxx
+ * NX|XX, NX -- Only set the key if it does not already exist. XX
+ * -- Only set the key if it already exist.
+ * @param expx
+ * EX|PX, expire time units: EX = seconds; PX = milliseconds
+ * @param time
+ * expire time in the units of {@param #expx}
* @return Status code reply
*/
- public String set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final long time) {
- checkIsInMulti();
- client.set(key, value, nxxx, expx, time);
- return client.getStatusCodeReply();
+ public String set(final byte[] key, final byte[] value, final byte[] nxxx,
+ final byte[] expx, final long time) {
+ checkIsInMulti();
+ client.set(key, value, nxxx, expx, time);
+ return client.getStatusCodeReply();
}
/**
@@ -147,9 +165,9 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
}
public Long del(final byte[] key) {
- checkIsInMulti();
- client.del(key);
- return client.getIntegerReply();
+ checkIsInMulti();
+ client.del(key);
+ return client.getIntegerReply();
}
/**
@@ -619,6 +637,37 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
return client.getIntegerReply();
}
+ /**
+ * INCRBYFLOAT work just like {@link #incrBy(byte[]) INCRBY} but increments
+ * by floats instead of integers.
+ *
+ * INCRBYFLOAT commands are limited to double precision floating point
+ * values.
+ *
+ * Note: this is actually a string operation, that is, in Redis there are
+ * not "double" types. Simply the string stored at the key is parsed as a
+ * base double precision floating point value, incremented, and then
+ * converted back as a string. There is no DECRYBYFLOAT but providing a
+ * negative value will work as expected.
+ *
+ * Time complexity: O(1)
+ *
+ * @see #incr(byte[])
+ * @see #decr(byte[])
+ * @see #decrBy(byte[], long)
+ *
+ * @param key
+ * @param integer
+ * @return Integer reply, this commands will reply with the new value of key
+ * after the increment.
+ */
+ public Double incrByFloat(final byte[] key, final double integer) {
+ checkIsInMulti();
+ client.incrByFloat(key, integer);
+ String dval = client.getBulkReply();
+ return (dval != null ? new Double(dval) : null);
+ }
+
/**
* Increment the number stored at key by one. If the key does not exist or
* contains a value of a wrong type, set the key to the value of "0" before
@@ -811,6 +860,33 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
return client.getIntegerReply();
}
+ /**
+ * Increment the number stored at field in the hash at key by a double
+ * precision floating point value. If key does not exist, a new key holding
+ * a hash is created. If field does not exist or holds a string, the value
+ * is set to 0 before applying the operation. Since the value argument is
+ * signed you can use this command to perform both increments and
+ * decrements.
+ *
+ * The range of values supported by HINCRBYFLOAT is limited to double
+ * precision floating point values.
+ *
+ * Time complexity: O(1)
+ *
+ * @param key
+ * @param field
+ * @param value
+ * @return Double precision floating point reply The new value at field
+ * after the increment operation.
+ */
+ public Double hincrByFloat(final byte[] key, final byte[] field,
+ final double value) {
+ checkIsInMulti();
+ client.hincrByFloat(key, field, value);
+ final String dval = client.getBulkReply();
+ return (dval != null ? new Double(dval) : null);
+ }
+
/**
* Test for existence of a specified field in a hash.
*
@@ -1006,7 +1082,8 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
* @return Multi bulk reply, specifically a list of elements in the
* specified range.
*/
- public List lrange(final byte[] key, final long start, final long end) {
+ public List lrange(final byte[] key, final long start,
+ final long end) {
checkIsInMulti();
client.lrange(key, start, end);
return client.getBinaryMultiBulkReply();
@@ -1468,11 +1545,11 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
client.srandmember(key);
return client.getBinaryBulkReply();
}
-
+
public List srandmember(final byte[] key, final int count) {
- checkIsInMulti();
- client.srandmember(key, count);
- return client.getBinaryMultiBulkReply();
+ checkIsInMulti();
+ client.srandmember(key, count);
+ return client.getBinaryMultiBulkReply();
}
/**
@@ -1502,7 +1579,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
return client.getIntegerReply();
}
- public Long zadd(final byte[] key, final Map scoreMembers) {
+ public Long zadd(final byte[] key, final Map scoreMembers) {
checkIsInMulti();
client.zaddBinary(key, scoreMembers);
return client.getIntegerReply();
@@ -1680,26 +1757,30 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
public Transaction multi() {
client.multi();
client.getOne(); // expected OK
- return new Transaction(client);
+ transaction = new Transaction(client);
+ return transaction;
}
+ @Deprecated
+ /**
+ * This method is deprecated due to its error prone
+ * and will be removed on next major release
+ * You can use multi() instead
+ * @see https://github.com/xetorthio/jedis/pull/498
+ */
public List