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
4 changes: 4 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ public void set(final byte[] key, final byte[] value, final SetParams params) {
public void get(final byte[] key) {
sendCommand(GET, key);
}

public void getDel(final byte[] key) {
sendCommand(GETDEL, key);
}

public void quit() {
db = 0;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,22 @@ public byte[] get(final byte[] key) {
client.get(key);
return client.getBinaryBulkReply();
}

/**
* Get the value of key and delete the key. This command is similar to GET, except for the fact
* that it also deletes the key on success (if and only if the key's value type is a string).
* <p>
* Time complexity: O(1)
* @param key
* @return the value of key
* @since Redis 6.2
*/
@Override
public byte[] getDel(final byte[] key) {
checkIsInMultiOrPipeline();
client.getDel(key);
return client.getBinaryBulkReply();
}

/**
* Ask the server to silently close the connection.
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedisCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ public byte[] execute(Jedis connection) {
}
}.runBinary(key);
}

@Override
public byte[] getDel(final byte[] key) {
return new JedisClusterCommand<byte[]>(connectionHandler, maxAttempts) {
@Override
public byte[] execute(Jedis connection) {
return connection.getDel(key);
}
}.runBinary(key);
}

@Override
public Long exists(final byte[]... keys) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryShardedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public byte[] get(final byte[] key) {
return j.get(key);
}

@Override
public byte[] getDel(final byte[] key) {
Jedis j = getShard(key);
return j.getDel(key);
}

@Override
public Boolean exists(final byte[] key) {
Jedis j = getShard(key);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/redis/clients/jedis/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public void set(final String key, final String value, final SetParams params) {
public void get(final String key) {
get(SafeEncoder.encode(key));
}

@Override
public void getDel(final String key) {
getDel(SafeEncoder.encode(key));
}

@Override
public void exists(final String... keys) {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,22 @@ public String get(final String key) {
return client.getBulkReply();
}

/**
* Get the value of key and delete the key. This command is similar to GET, except for the fact
* that it also deletes the key on success (if and only if the key's value type is a string).
* <p>
* Time complexity: O(1)
* @param key
* @return the value of key
* @since Redis 6.2
*/
@Override
public String getDel(final String key) {
checkIsInMultiOrPipeline();
client.getDel(key);
return client.getBulkReply();
}

/**
* Test if the specified keys exist. The command returns the number of keys exist.
* Time complexity: O(N)
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/redis/clients/jedis/JedisCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ public String execute(Jedis connection) {
}
}.run(key);
}

@Override
public String getDel(final String key) {
return new JedisClusterCommand<String>(connectionHandler, maxAttempts) {
@Override
public String execute(Jedis connection) {
return connection.getDel(key);
}
}.run(key);
}

@Override
public Boolean exists(final String key) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/redis/clients/jedis/PipelineBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,18 @@ public Response<byte[]> get(final byte[] key) {
return getResponse(BuilderFactory.BYTE_ARRAY);
}

@Override
public Response<String> getDel(final String key) {
getClient(key).getDel(key);
return getResponse(BuilderFactory.STRING);
}

@Override
public Response<byte[]> getDel(final byte[] key) {
getClient(key).getDel(key);
return getResponse(BuilderFactory.BYTE_ARRAY);
}

@Override
public Response<Boolean> getbit(final String key, final long offset) {
getClient(key).getbit(key, offset);
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 @@ -243,7 +243,7 @@ public static final byte[] toByteArray(final double value) {
}

public static enum Command implements ProtocolCommand {
PING, SET, GET, QUIT, EXISTS, DEL, UNLINK, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX,
PING, SET, GET, GETDEL, QUIT, EXISTS, DEL, UNLINK, 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,
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/redis/clients/jedis/ShardedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public String get(final String key) {
Jedis j = getShard(key);
return j.get(key);
}

@Override
public String getDel(final String key) {
Jedis j = getShard(key);
return j.getDel(key);
}

@Override
public String echo(final String string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public interface BinaryJedisClusterCommands {

byte[] get(byte[] key);

byte[] getDel(byte[] key);

Boolean exists(byte[] key);

Long persist(byte[] key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public interface BinaryJedisCommands {
String set(byte[] key, byte[] value, SetParams params);

byte[] get(byte[] key);

byte[] getDel(byte[] key);

Boolean exists(byte[] key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public interface BinaryRedisPipeline {
Response<Long> pexpireAt(byte[] key, long millisecondsTimestamp);

Response<byte[]> get(byte[] key);

Response<byte[]> getDel(byte[] key);

Response<Boolean> getbit(byte[] key, long offset);

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/redis/clients/jedis/commands/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public interface Commands {
void set(String key, String value, SetParams params);

void get(String key);

void getDel(String key);

void exists(String... keys);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public interface JedisClusterCommands {
String set(String key, String value, SetParams params);

String get(String key);

String getDel(String key);

Boolean exists(String key);

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/redis/clients/jedis/commands/JedisCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public interface JedisCommands {
String set(String key, String value, SetParams params);

String get(String key);

String getDel(String key);

Boolean exists(String key);

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/redis/clients/jedis/commands/RedisPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public interface RedisPipeline {
Response<Long> pexpireAt(String key, long millisecondsTimestamp);

Response<String> get(String key);

Response<String> getDel(String key);

Response<Boolean> getbit(String key, long offset);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,15 @@ public void psetex() {
long ttl = jedis.ttl("foo");
assertTrue(ttl > 0 && ttl <= 20000);
}

@Test
public void getDel() {
String status = jedis.set("foo", "bar");
assertEquals("OK", status);

String value = jedis.getDel("foo");
assertEquals("bar", value);

assertNull(jedis.get("foo"));
}
}