Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.net.ssl.SSLSocketFactory;

import redis.clients.jedis.Protocol.Keyword;
import redis.clients.jedis.args.ListDirection;
import redis.clients.jedis.args.FlushMode;
import redis.clients.jedis.args.UnblockType;
import redis.clients.jedis.params.*;
Expand Down Expand Up @@ -719,6 +720,14 @@ public void sort(final byte[] key, final SortingParams sortingParameters) {
sendCommand(SORT, args.toArray(new byte[args.size()][]));
}

public void lmove(byte[] srcKey, byte[] dstKey, ListDirection from, ListDirection to) {
sendCommand(LMOVE, srcKey, dstKey, from.getRaw(), to.getRaw());
}

public void blmove(byte[] srcKey, byte[] dstKey, ListDirection from, ListDirection to, int timeout) {
sendCommand(BLMOVE, srcKey, dstKey, from.getRaw(), to.getRaw(), toByteArray(timeout));
}

public void blpop(final byte[][] args) {
sendCommand(BLPOP, args);
}
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocketFactory;

import redis.clients.jedis.args.ListDirection;
import redis.clients.jedis.args.FlushMode;
import redis.clients.jedis.args.UnblockType;
import redis.clients.jedis.commands.AdvancedBinaryJedisCommands;
Expand Down Expand Up @@ -2370,6 +2371,42 @@ public List<byte[]> sort(final byte[] key, final SortingParams sortingParameters
return client.getBinaryMultiBulkReply();
}

/**
* Pop an element from a list, push it to another list and return it
* @param srcKey
* @param dstKey
* @param from
* @param to
* @return
*/
@Override
public byte[] lmove(byte[] srcKey, byte[] dstKey, ListDirection from, ListDirection to) {
checkIsInMultiOrPipeline();
client.lmove(srcKey, dstKey, from, to);
return client.getBinaryBulkReply();
}

/**
* Pop an element from a list, push it to another list and return it; or block until one is available
* @param srcKey
* @param dstKey
* @param from
* @param to
* @param timeout
* @return
*/
@Override
public byte[] blmove(byte[] srcKey, byte[] dstKey, ListDirection from, ListDirection to, int timeout) {
checkIsInMultiOrPipeline();
client.blmove(srcKey, dstKey, from, to, timeout);
client.setTimeoutInfinite();
try {
return client.getBinaryBulkReply();
} finally {
client.rollbackTimeout();
}
}

/**
* BLPOP (and BRPOP) is a blocking list pop primitive. You can see this commands as blocking
* versions of LPOP and RPOP able to block if the specified keys don't exist or contain empty
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedisCluster.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package redis.clients.jedis;

import redis.clients.jedis.args.ListDirection;
import redis.clients.jedis.args.FlushMode;
import redis.clients.jedis.commands.BinaryJedisClusterCommands;
import redis.clients.jedis.commands.JedisClusterBinaryScriptingCommands;
Expand Down Expand Up @@ -1752,6 +1753,28 @@ public Long execute(Jedis connection) {
}.runBinary(keys.length, keys);
}

@Override
public byte[] lmove(final byte[] srcKey, final byte[] dstKey, final ListDirection from,
final ListDirection to) {
return new JedisClusterCommand<byte[]>(connectionHandler, maxAttempts) {
@Override
public byte[] execute(Jedis connection) {
return connection.lmove(srcKey, dstKey, from, to);
}
}.runBinary(2, srcKey, dstKey);
}

@Override
public byte[] blmove(final byte[] srcKey, final byte[] dstKey, final ListDirection from,
final ListDirection to, final int timeout) {
return new JedisClusterCommand<byte[]>(connectionHandler, maxAttempts) {
@Override
public byte[] execute(Jedis connection) {
return connection.blmove(srcKey, dstKey, from, to, timeout);
}
}.runBinary(2, srcKey, dstKey);
}

@Override
public List<byte[]> blpop(final int timeout, final byte[]... keys) {
return new JedisClusterCommand<List<byte[]>>(connectionHandler, maxAttempts) {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/redis/clients/jedis/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocketFactory;

import redis.clients.jedis.args.ListDirection;
import redis.clients.jedis.commands.Commands;
import redis.clients.jedis.params.*;
import redis.clients.jedis.util.SafeEncoder;
Expand Down Expand Up @@ -610,6 +611,16 @@ public void sort(final String key, final SortingParams sortingParameters) {
sort(SafeEncoder.encode(key), sortingParameters);
}

@Override
public void lmove(String srcKey, String dstKey, ListDirection from, ListDirection to) {
lmove(SafeEncoder.encode(srcKey), SafeEncoder.encode(dstKey), from, to);
}

@Override
public void blmove(String srcKey, String dstKey, ListDirection from, ListDirection to, int timeout) {
blmove(SafeEncoder.encode(srcKey), SafeEncoder.encode(dstKey), from, to, timeout);
}

@Override
public void blpop(final String[] args) {
blpop(SafeEncoder.encodeMany(args));
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocketFactory;

import redis.clients.jedis.args.ListDirection;
import redis.clients.jedis.commands.*;
import redis.clients.jedis.params.*;
import redis.clients.jedis.args.UnblockType;
Expand Down Expand Up @@ -2027,6 +2028,27 @@ public List<String> sort(final String key, final SortingParams sortingParameters
return client.getMultiBulkReply();
}

@Override
public String lmove(final String srcKey, final String dstKey, final ListDirection from,
final ListDirection to) {
checkIsInMultiOrPipeline();
client.lmove(srcKey, dstKey, from, to);
return client.getBulkReply();
}

@Override
public String blmove(final String srcKey, final String dstKey, final ListDirection from,
final ListDirection to, final int timeout) {
checkIsInMultiOrPipeline();
client.blmove(srcKey, dstKey, from, to, timeout);
client.setTimeoutInfinite();
try {
return client.getBulkReply();
} finally {
client.rollbackTimeout();
}
}

/**
* BLPOP (and BRPOP) is a blocking list pop primitive. You can see this commands as blocking
* versions of LPOP and RPOP able to block if the specified keys don't exist or contain empty
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/redis/clients/jedis/JedisCluster.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package redis.clients.jedis;

import redis.clients.jedis.args.ListDirection;
import redis.clients.jedis.commands.JedisClusterCommands;
import redis.clients.jedis.commands.JedisClusterScriptingCommands;
import redis.clients.jedis.commands.MultiKeyJedisClusterCommands;
Expand Down Expand Up @@ -1819,6 +1820,27 @@ public Long execute(Jedis connection) {
}.run(keys.length, keys);
}

@Override
public String lmove(String srcKey, String dstKey, ListDirection from, ListDirection to) {
return new JedisClusterCommand<String>(connectionHandler, maxAttempts) {
@Override
public String execute(Jedis connection) {
return connection.lmove(srcKey, dstKey, from, to);
}
}.run(2, srcKey, dstKey);
}

@Override
public String blmove(String srcKey, String dstKey, ListDirection from, ListDirection to,
int timeout) {
return new JedisClusterCommand<String>(connectionHandler, maxAttempts) {
@Override
public String execute(Jedis connection) {
return connection.blmove(srcKey, dstKey, from, to, timeout);
}
}.run(2, srcKey, dstKey);
}

@Override
public List<String> blpop(final int timeout, final String... keys) {
return new JedisClusterCommand<List<String>>(connectionHandler, maxAttempts) {
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/redis/clients/jedis/MultiKeyPipelineBase.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package redis.clients.jedis;

import redis.clients.jedis.args.ListDirection;
import redis.clients.jedis.args.FlushMode;
import redis.clients.jedis.commands.*;
import redis.clients.jedis.params.*;
Expand All @@ -14,6 +15,34 @@ public abstract class MultiKeyPipelineBase extends PipelineBase implements

protected Client client = null;

@Override
public Response<byte[]> lmove(byte[] srcKey, byte[] dstKey, ListDirection from,
ListDirection to) {
client.lmove(srcKey, dstKey, from, to);
return getResponse(BuilderFactory.BYTE_ARRAY);
}

@Override
public Response<byte[]> blmove(byte[] srcKey, byte[] dstKey, ListDirection from, ListDirection to,
int timeout) {
client.blmove(srcKey, dstKey, from, to, timeout);
return getResponse(BuilderFactory.BYTE_ARRAY);
}

@Override
public Response<String> lmove(String srcKey, String dstKey, ListDirection from,
ListDirection to) {
client.lmove(srcKey, dstKey, from, to);
return getResponse(BuilderFactory.STRING);
}

@Override
public Response<String> blmove(String srcKey, String dstKey, ListDirection from, ListDirection to,
int timeout) {
client.blmove(srcKey, dstKey, from, to, timeout);
return getResponse(BuilderFactory.STRING);
}

@Override
public Response<List<String>> brpop(String... args) {
client.brpop(args);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/jedis/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public static enum Command implements ProtocolCommand {
READONLY, GEOADD, GEODIST, GEOHASH, GEOPOS, GEORADIUS, GEORADIUS_RO, GEORADIUSBYMEMBER,
GEORADIUSBYMEMBER_RO, MODULE, BITFIELD, HSTRLEN, TOUCH, SWAPDB, MEMORY, XADD, XLEN, XDEL,
XTRIM, XRANGE, XREVRANGE, XREAD, XACK, XGROUP, XREADGROUP, XPENDING, XCLAIM, ACL, XINFO,
BITFIELD_RO, LPOS, SMISMEMBER, ZMSCORE, BZPOPMIN, BZPOPMAX;
BITFIELD_RO, LPOS, SMISMEMBER, ZMSCORE, BZPOPMIN, BZPOPMAX, BLMOVE, LMOVE;

private final byte[] raw;

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/redis/clients/jedis/args/ListDirection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package redis.clients.jedis.args;

import redis.clients.jedis.util.SafeEncoder;

/**
* Direction for {@code LMOVE} and {@code BLMOVE} command.
*/
public enum ListDirection implements Rawable {
LEFT, RIGHT;

private final byte[] raw;

ListDirection() {
raw = SafeEncoder.encode(this.name());
}

@Override
public byte[] getRaw() {
return raw;
}
}
5 changes: 5 additions & 0 deletions src/main/java/redis/clients/jedis/commands/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import redis.clients.jedis.ListPosition;
import redis.clients.jedis.ScanParams;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.args.ListDirection;
import redis.clients.jedis.args.UnblockType;
import redis.clients.jedis.ZParams;
import redis.clients.jedis.params.GetExParams;
Expand Down Expand Up @@ -274,6 +275,10 @@ default void setex(String key, int seconds, String value) {

void sort(String key, SortingParams sortingParameters);

void lmove(String srcKey, String dstKey, ListDirection from, ListDirection to);

void blmove(String srcKey, String dstKey, ListDirection from, ListDirection to, int timeout);

void blpop(String[] args);

void sort(String key, SortingParams sortingParameters, String dstkey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.ZParams;
import redis.clients.jedis.args.ListDirection;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.XReadGroupParams;
Expand All @@ -24,6 +25,10 @@ public interface MultiKeyBinaryCommands {

Long exists(byte[]... keys);

byte[] lmove(byte[] srcKey, byte[] dstKey, ListDirection from, ListDirection to);

byte[] blmove(byte[] srcKey, byte[] dstKey, ListDirection from, ListDirection to, int timeout);

List<byte[]> blpop(int timeout, byte[]... keys);

List<byte[]> brpop(int timeout, byte[]... keys);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.ZParams;
import redis.clients.jedis.args.ListDirection;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.XReadGroupParams;
Expand All @@ -26,6 +27,10 @@ public interface MultiKeyBinaryJedisClusterCommands {

Long exists(byte[]... keys);

byte[] lmove(byte[] srcKey, byte[] dstKey, ListDirection from, ListDirection to);

byte[] blmove(byte[] srcKey, byte[] dstKey, ListDirection from, ListDirection to, int timeout);

List<byte[]> blpop(int timeout, byte[]... keys);

List<byte[]> brpop(int timeout, byte[]... keys);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.ZParams;
import redis.clients.jedis.args.ListDirection;
import redis.clients.jedis.params.*;

import java.util.List;
Expand All @@ -24,6 +25,10 @@ public interface MultiKeyBinaryRedisPipeline {

Response<Long> exists(byte[]... keys);

Response<byte[]> lmove(byte[] srcKey, byte[] dstKey, ListDirection from, ListDirection to);

Response<byte[]> blmove(byte[] srcKey, byte[] dstKey, ListDirection from, ListDirection to, int timeout);

Response<List<byte[]>> blpop(byte[]... args);

Response<List<byte[]>> brpop(byte[]... args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import redis.clients.jedis.StreamEntry;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.ZParams;
import redis.clients.jedis.args.ListDirection;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GeoRadiusStoreParam;
import redis.clients.jedis.params.XReadGroupParams;
Expand All @@ -27,6 +28,10 @@ public interface MultiKeyCommands {

Long exists(String... keys);

String lmove(String srcKey, String dstKey, ListDirection from, ListDirection to);

String blmove(String srcKey, String dstKey, ListDirection from, ListDirection to, int timeout);

List<String> blpop(int timeout, String... keys);

List<String> brpop(int timeout, String... keys);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import redis.clients.jedis.StreamEntryID;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.ZParams;
import redis.clients.jedis.args.ListDirection;
import redis.clients.jedis.params.*;

import java.util.List;
Expand All @@ -25,6 +26,10 @@ public interface MultiKeyCommandsPipeline {

Response<Long> exists(String... keys);

Response<String> lmove(String srcKey, String dstKey, ListDirection from, ListDirection to);

Response<String> blmove(String srcKey, String dstKey, ListDirection from, ListDirection to, int timeout);

Response<List<String>> blpop(String... args);

Response<List<String>> brpop(String... args);
Expand Down
Loading