22
33import static redis .clients .jedis .Protocol .toByteArray ;
44import static redis .clients .jedis .Protocol .Command .*;
5- import static redis .clients .jedis .Protocol .Keyword .ENCODING ;
6- import static redis .clients .jedis .Protocol .Keyword .IDLETIME ;
7- import static redis .clients .jedis .Protocol .Keyword .LEN ;
8- import static redis .clients .jedis .Protocol .Keyword .LIMIT ;
9- import static redis .clients .jedis .Protocol .Keyword .NO ;
10- import static redis .clients .jedis .Protocol .Keyword .ONE ;
11- import static redis .clients .jedis .Protocol .Keyword .REFCOUNT ;
12- import static redis .clients .jedis .Protocol .Keyword .RESET ;
13- import static redis .clients .jedis .Protocol .Keyword .STORE ;
14- import static redis .clients .jedis .Protocol .Keyword .WITHSCORES ;
15- import static redis .clients .jedis .Protocol .Keyword .FREQ ;
16- import static redis .clients .jedis .Protocol .Keyword .HELP ;
5+ import static redis .clients .jedis .Protocol .Command .EXISTS ;
6+ import static redis .clients .jedis .Protocol .Command .GET ;
7+ import static redis .clients .jedis .Protocol .Command .INCR ;
8+ import static redis .clients .jedis .Protocol .Command .KEYS ;
9+ import static redis .clients .jedis .Protocol .Command .PING ;
10+ import static redis .clients .jedis .Protocol .Command .PSUBSCRIBE ;
11+ import static redis .clients .jedis .Protocol .Command .PUNSUBSCRIBE ;
12+ import static redis .clients .jedis .Protocol .Command .SAVE ;
13+ import static redis .clients .jedis .Protocol .Command .SET ;
14+ import static redis .clients .jedis .Protocol .Command .SUBSCRIBE ;
15+ import static redis .clients .jedis .Protocol .Command .TIME ;
16+ import static redis .clients .jedis .Protocol .Command .UNSUBSCRIBE ;
17+ import static redis .clients .jedis .Protocol .Keyword .*;
1718
1819import java .util .ArrayList ;
1920import java .util .Collections ;
2627import javax .net .ssl .SSLSocketFactory ;
2728
2829import redis .clients .jedis .Protocol .Keyword ;
29- import redis .clients .jedis .params .ClientKillParams ;
30- import redis .clients .jedis .params .GeoAddParams ;
31- import redis .clients .jedis .params .GeoRadiusParam ;
32- import redis .clients .jedis .params .GeoRadiusStoreParam ;
33- import redis .clients .jedis .params .GetExParams ;
34- import redis .clients .jedis .params .MigrateParams ;
35- import redis .clients .jedis .params .SetParams ;
36- import redis .clients .jedis .params .ZAddParams ;
37- import redis .clients .jedis .params .ZIncrByParams ;
38- import redis .clients .jedis .params .LPosParams ;
30+ import redis .clients .jedis .args .UnblockType ;
31+ import redis .clients .jedis .params .*;
3932import redis .clients .jedis .util .SafeEncoder ;
4033
4134public class BinaryClient extends Connection {
@@ -414,6 +407,18 @@ public void hgetAll(final byte[] key) {
414407 sendCommand (HGETALL , key );
415408 }
416409
410+ public void hrandfield (final byte [] key ) {
411+ sendCommand (HRANDFIELD , key );
412+ }
413+
414+ public void hrandfield (final byte [] key , final long count ) {
415+ sendCommand (HRANDFIELD , key , toByteArray (count ));
416+ }
417+
418+ public void hrandfieldWithValues (final byte [] key , final long count ) {
419+ sendCommand (HRANDFIELD , key , toByteArray (count ), WITHVALUES .getRaw ());
420+ }
421+
417422 public void rpush (final byte [] key , final byte []... strings ) {
418423 sendCommand (RPUSH , joinParameters (key , strings ));
419424 }
@@ -1228,6 +1233,14 @@ public void clientId() {
12281233 sendCommand (CLIENT , Keyword .ID .getRaw ());
12291234 }
12301235
1236+ public void clientUnblock (final long clientId , final UnblockType unblockType ) {
1237+ if (unblockType == null ) {
1238+ sendCommand (CLIENT , Keyword .UNBLOCK .getRaw (), toByteArray (clientId ));
1239+ } else {
1240+ sendCommand (CLIENT , Keyword .UNBLOCK .getRaw (), toByteArray (clientId ), unblockType .getRaw ());
1241+ }
1242+ }
1243+
12311244 public void time () {
12321245 sendCommand (TIME );
12331246 }
@@ -1576,6 +1589,11 @@ public void xrevrange(final byte[] key, final byte[] end, final byte[] start, fi
15761589 sendCommand (XREVRANGE , key , end , start , Keyword .COUNT .getRaw (), toByteArray (count ));
15771590 }
15781591
1592+ /**
1593+ * @deprecated This method will be removed due to bug regarding {@code block} param. Use
1594+ * {@link #xread(redis.clients.jedis.params.XReadParams, java.util.Map.Entry...)}.
1595+ */
1596+ @ Deprecated
15791597 public void xread (final int count , final long block , final Map <byte [], byte []> streams ) {
15801598 final byte [][] params = new byte [3 + streams .size () * 2 + (block > 0 ? 2 : 0 )][];
15811599
@@ -1598,6 +1616,24 @@ public void xread(final int count, final long block, final Map<byte[], byte[]> s
15981616 sendCommand (XREAD , params );
15991617 }
16001618
1619+ public void xread (final XReadParams params , final Entry <byte [], byte []>... streams ) {
1620+ final byte [][] bparams = params .getByteParams ();
1621+ final int paramLength = bparams .length ;
1622+
1623+ final byte [][] args = new byte [paramLength + 1 + streams .length * 2 ][];
1624+ System .arraycopy (bparams , 0 , args , 0 , paramLength );
1625+
1626+ args [paramLength ] = Keyword .STREAMS .raw ;
1627+ int keyIndex = paramLength + 1 ;
1628+ int idsIndex = keyIndex + streams .length ;
1629+ for (final Entry <byte [], byte []> entry : streams ) {
1630+ args [keyIndex ++] = entry .getKey ();
1631+ args [idsIndex ++] = entry .getValue ();
1632+ }
1633+
1634+ sendCommand (XREAD , args );
1635+ }
1636+
16011637 public void xack (final byte [] key , final byte [] group , final byte []... ids ) {
16021638 final byte [][] params = new byte [2 + ids .length ][];
16031639 int index = 0 ;
@@ -1648,6 +1684,11 @@ public void xtrim(byte[] key, long maxLen, boolean approximateLength) {
16481684 }
16491685 }
16501686
1687+ /**
1688+ * @deprecated This method will be removed due to bug regarding {@code block} param. Use
1689+ * {@link #xreadGroup(byte..., byte..., redis.clients.jedis.params.XReadGroupParams, java.util.Map.Entry...)}.
1690+ */
1691+ @ Deprecated
16511692 public void xreadGroup (byte [] groupname , byte [] consumer , int count , long block , boolean noAck ,
16521693 Map <byte [], byte []> streams ) {
16531694
@@ -1690,6 +1731,30 @@ public void xreadGroup(byte[] groupname, byte[] consumer, int count, long block,
16901731 sendCommand (XREADGROUP , params );
16911732 }
16921733
1734+ public void xreadGroup (byte [] groupname , byte [] consumer , final XReadGroupParams params ,
1735+ final Entry <byte [], byte []>... streams ) {
1736+ final byte [][] bparams = params .getByteParams ();
1737+ final int paramLength = bparams .length ;
1738+
1739+ final byte [][] args = new byte [3 + paramLength + 1 + streams .length * 2 ][];
1740+ int index = 0 ;
1741+ args [index ++] = Keyword .GROUP .raw ;
1742+ args [index ++] = groupname ;
1743+ args [index ++] = consumer ;
1744+ System .arraycopy (bparams , 0 , args , index , paramLength );
1745+ index += paramLength ;
1746+
1747+ args [index ++] = Keyword .STREAMS .raw ;
1748+ int keyIndex = index ;
1749+ int idsIndex = keyIndex + streams .length ;
1750+ for (final Entry <byte [], byte []> entry : streams ) {
1751+ args [keyIndex ++] = entry .getKey ();
1752+ args [idsIndex ++] = entry .getValue ();
1753+ }
1754+
1755+ sendCommand (XREADGROUP , args );
1756+ }
1757+
16931758 public void xpending (byte [] key , byte [] groupname , byte [] start , byte [] end , int count ,
16941759 byte [] consumername ) {
16951760 if (consumername == null ) {
@@ -1706,7 +1771,7 @@ public void xpendingSummary(final byte[] key, final byte[] groupname) {
17061771 public void xclaim (byte [] key , byte [] groupname , byte [] consumername , long minIdleTime ,
17071772 long newIdleTime , int retries , boolean force , byte [][] ids ) {
17081773
1709- ArrayList <byte []> arguments = new ArrayList <>(10 + ids .length );
1774+ List <byte []> arguments = new ArrayList <>(10 + ids .length );
17101775
17111776 arguments .add (key );
17121777 arguments .add (groupname );
@@ -1729,6 +1794,37 @@ public void xclaim(byte[] key, byte[] groupname, byte[] consumername, long minId
17291794 sendCommand (XCLAIM , arguments .toArray (new byte [arguments .size ()][]));
17301795 }
17311796
1797+ private void xclaim (byte [] key , byte [] groupname , byte [] consumername , long minIdleTime ,
1798+ XClaimParams params , byte [][] ids , boolean justId ) {
1799+ final byte [][] bparams = params .getByteParams ();
1800+ final int paramLength = bparams .length ;
1801+ final int idsLength = ids .length ;
1802+ final byte [][] args = new byte [4 + paramLength + idsLength + (justId ? 1 : 0 )][];
1803+ int index = 0 ;
1804+ args [index ++] = key ;
1805+ args [index ++] = groupname ;
1806+ args [index ++] = consumername ;
1807+ args [index ++] = toByteArray (minIdleTime );
1808+ System .arraycopy (ids , 0 , args , index , idsLength );
1809+ index += idsLength ;
1810+ System .arraycopy (bparams , 0 , args , index , paramLength );
1811+ index += paramLength ;
1812+ if (justId ) {
1813+ args [index ++] = Keyword .JUSTID .getRaw ();
1814+ }
1815+ sendCommand (XCLAIM , args );
1816+ }
1817+
1818+ public void xclaim (byte [] key , byte [] groupname , byte [] consumername , long minIdleTime ,
1819+ XClaimParams params , byte []... ids ) {
1820+ xclaim (key , groupname , consumername , minIdleTime , params , ids , false );
1821+ }
1822+
1823+ public void xclaimJustId (byte [] key , byte [] groupname , byte [] consumername , long minIdleTime ,
1824+ XClaimParams params , byte []... ids ) {
1825+ xclaim (key , groupname , consumername , minIdleTime , params , ids , true );
1826+ }
1827+
17321828 public void xinfoStream (byte [] key ) {
17331829 sendCommand (XINFO , Keyword .STREAM .getRaw (), key );
17341830 }
0 commit comments