Skip to content

Commit

Permalink
Add support ABSTTL, IDLETIME and FREQ args to RESTORE command (#2482)
Browse files Browse the repository at this point in the history
* Add support ABSTTL、IDLETIME and FREQ args to RESTORE command

* review

* Deprecated restoreReplace

Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com>
  • Loading branch information
dengliming and sazzad16 authored Mar 23, 2021
1 parent 650a970 commit 2ed7f3b
Show file tree
Hide file tree
Showing 19 changed files with 236 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1248,10 +1248,22 @@ public void restoreReplace(final byte[] key, final int ttl, final byte[] seriali
sendCommand(RESTORE, key, toByteArray(ttl), serializedValue, Keyword.REPLACE.getRaw());
}

/**
* @deprecated Use {@link #restore(byte[], long, byte[], redis.clients.jedis.params.RestoreParams)}.
*/
@Deprecated
public void restoreReplace(final byte[] key, final long ttl, final byte[] serializedValue) {
sendCommand(RESTORE, key, toByteArray(ttl), serializedValue, Keyword.REPLACE.getRaw());
}

public void restore(final byte[] key, final long ttl, final byte[] serializedValue, final RestoreParams params) {
if (params == null) {
sendCommand(RESTORE, key, toByteArray(ttl), serializedValue);
} else {
sendCommand(RESTORE, params.getByteParams(key, toByteArray(ttl), serializedValue));
}
}

public void pexpire(final byte[] key, final long milliseconds) {
sendCommand(PEXPIRE, key, toByteArray(milliseconds));
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -4040,6 +4040,14 @@ public String restoreReplace(final byte[] key, final long ttl, final byte[] seri
return client.getStatusCodeReply();
}

@Override
public String restore(final byte[] key, final long ttl, final byte[] serializedValue,
final RestoreParams params) {
checkIsInMultiOrPipeline();
client.restore(key, ttl, serializedValue, params);
return client.getStatusCodeReply();
}

/**
* Set a timeout on the specified key. After the timeout the key will be automatically deleted by
* the server. A key with an associated timeout is said to be volatile in Redis terminology.
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedisCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,17 @@ public String execute(Jedis connection) {
}.runBinary(key);
}

@Override
public String restore(final byte[] key, final long ttl, final byte[] serializedValue,
final RestoreParams params) {
return new JedisClusterCommand<String>(connectionHandler, maxAttempts) {
@Override
public String execute(Jedis connection) {
return connection.restore(key, ttl, serializedValue, params);
}
}.runBinary(key);
}

@Override
public Long expire(final byte[] key, final int seconds) {
return new JedisClusterCommand<Long>(connectionHandler, maxAttempts) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryShardedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.RestoreParams;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.params.XAddParams;
import redis.clients.jedis.params.XClaimParams;
Expand Down Expand Up @@ -133,6 +134,13 @@ public String restoreReplace(final byte[] key, final long ttl, final byte[] seri
return j.restoreReplace(key, ttl, serializedValue);
}

@Override
public String restore(final byte[] key, final long ttl, final byte[] serializedValue,
final RestoreParams params) {
Jedis j = getShard(key);
return j.restore(key, ttl, serializedValue, params);
}

@Override
public Long expire(final byte[] key, final long seconds) {
Jedis j = getShard(key);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/redis/clients/jedis/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,12 @@ public void restoreReplace(final String key, final long ttl, final byte[] serial
restoreReplace(SafeEncoder.encode(key), ttl, serializedValue);
}

@Override
public void restore(final String key, final long ttl, final byte[] serializedValue,
final RestoreParams params) {
restore(SafeEncoder.encode(key), ttl, serializedValue, params);
}

public void pexpire(final String key, final long milliseconds) {
pexpire(SafeEncoder.encode(key), milliseconds);
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -3502,6 +3502,14 @@ public String restoreReplace(final String key, final long ttl, final byte[] seri
return client.getStatusCodeReply();
}

@Override
public String restore(final String key, final long ttl, final byte[] serializedValue,
final RestoreParams params) {
checkIsInMultiOrPipeline();
client.restore(key, ttl, serializedValue, params);
return client.getStatusCodeReply();
}

@Override
public Long pexpire(final String key, final long milliseconds) {
checkIsInMultiOrPipeline();
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/redis/clients/jedis/JedisCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,17 @@ public String execute(Jedis connection) {
}.run(key);
}

@Override
public String restore(final String key, final long ttl, final byte[] serializedValue,
final RestoreParams params) {
return new JedisClusterCommand<String>(connectionHandler, maxAttempts) {
@Override
public String execute(Jedis connection) {
return connection.restore(key, ttl, serializedValue, params);
}
}.run(key);
}

@Override
public Long expire(final String key, final long seconds) {
return new JedisClusterCommand<Long>(connectionHandler, maxAttempts) {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/redis/clients/jedis/PipelineBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.RestoreParams;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.params.XAddParams;
import redis.clients.jedis.params.XClaimParams;
Expand Down Expand Up @@ -1803,6 +1804,20 @@ public Response<String> restoreReplace(final byte[] key, final long ttl,
return getResponse(BuilderFactory.STRING);
}

@Override
public Response<String> restore(final byte[] key, final long ttl, final byte[] serializedValue,
final RestoreParams params) {
getClient(key).restore(key, ttl, serializedValue, params);
return getResponse(BuilderFactory.STRING);
}

@Override
public Response<String> restore(final String key, final long ttl, final byte[] serializedValue,
final RestoreParams params) {
getClient(key).restore(key, ttl, serializedValue, params);
return getResponse(BuilderFactory.STRING);
}

@Override
public Response<Double> incrByFloat(final String key, final double increment) {
getClient(key).incrByFloat(key, increment);
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 @@ -286,7 +286,7 @@ public static enum Keyword implements Rawable {
NOACK, STREAMS, KEY, CREATE, MKSTREAM, SETID, DESTROY, DELCONSUMER, MAXLEN, GROUP, ID, IDLE,
TIME, RETRYCOUNT, FORCE, USAGE, SAMPLES, STREAM, GROUPS, CONSUMERS, HELP, FREQ, SETUSER,
GETUSER, DELUSER, WHOAMI, CAT, GENPASS, USERS, LOG, INCR, SAVE, JUSTID, WITHVALUES, UNBLOCK,
NOMKSTREAM, MINID, DB;
NOMKSTREAM, MINID, DB, ABSTTL;

/**
* @deprecated This will be private in future. Use {@link #getRaw()}.
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/redis/clients/jedis/ShardedJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.RestoreParams;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.params.XAddParams;
import redis.clients.jedis.params.XClaimParams;
Expand Down Expand Up @@ -108,6 +109,13 @@ public String restoreReplace(final String key, final long ttl, final byte[] seri
return j.restoreReplace(key, ttl, serializedValue);
}

@Override
public String restore(final String key, final long ttl, final byte[] serializedValue,
final RestoreParams params) {
Jedis j = getShard(key);
return j.restore(key, ttl, serializedValue, params);
}

@Override
public Long expire(final String key, final long seconds) {
Jedis j = getShard(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.RestoreParams;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.params.XAddParams;
import redis.clients.jedis.params.XClaimParams;
Expand Down Expand Up @@ -53,6 +54,8 @@ default String restore(byte[] key, int ttl, byte[] serializedValue) {

String restore(byte[] key, long ttl, byte[] serializedValue);

String restore(byte[] key, long ttl, byte[] serializedValue, RestoreParams params);

Long expire(byte[] key, int seconds);

Long pexpire(byte[] key, long milliseconds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import redis.clients.jedis.ScanResult;
import redis.clients.jedis.SortingParams;
import redis.clients.jedis.StreamConsumersInfo;
import redis.clients.jedis.StreamEntryID;
import redis.clients.jedis.StreamGroupInfo;
import redis.clients.jedis.StreamInfo;
import redis.clients.jedis.Tuple;
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.RestoreParams;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.params.XAddParams;
import redis.clients.jedis.params.XClaimParams;
Expand Down Expand Up @@ -68,8 +68,14 @@ default String restoreReplace(byte[] key, int ttl, byte[] serializedValue) {
return restoreReplace(key, (long) ttl, serializedValue);
}

/**
* @deprecated Use {@link #restore(byte[], long, byte[], redis.clients.jedis.params.RestoreParams)}.
*/
@Deprecated
String restoreReplace(byte[] key, long ttl, byte[] serializedValue);

String restore(byte[] key, long ttl, byte[] serializedValue, RestoreParams params);

/**
* @deprecated Use {@link #expire(byte[], long)}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.RestoreParams;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.params.XAddParams;
import redis.clients.jedis.params.XClaimParams;
Expand Down Expand Up @@ -332,8 +333,14 @@ default Response<String> restoreReplace(byte[] key, int ttl, byte[] serializedVa
return restoreReplace(key, (long) ttl, serializedValue);
}

/**
* @deprecated Use {@link #restore(byte[], long, byte[], redis.clients.jedis.params.RestoreParams)}.
*/
@Deprecated
Response<String> restoreReplace(byte[] key, long ttl, byte[] serializedValue);

Response<String> restore(byte[] key, long ttl, byte[] serializedValue, RestoreParams params);

Response<String> migrate(String host, int port, byte[] key, int destinationDB, int timeout);

// Geo Commands
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/redis/clients/jedis/commands/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.MigrateParams;
import redis.clients.jedis.params.ClientKillParams;
import redis.clients.jedis.params.RestoreParams;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.params.XAddParams;
import redis.clients.jedis.params.XClaimParams;
Expand Down Expand Up @@ -427,8 +428,14 @@ default void restoreReplace(String key, int ttl, byte[] serializedValue) {
restoreReplace(key, (long) ttl, serializedValue);
}

/**
* @deprecated Use {@link #restore(java.lang.String, long, byte[], redis.clients.jedis.params.RestoreParams)}.
*/
@Deprecated
void restoreReplace(String key, long ttl, byte[] serializedValue);

void restore(String key, long ttl, byte[] serializedValue, RestoreParams params);

void scan(String cursor, ScanParams params);

void hscan(String key, String cursor, ScanParams params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.RestoreParams;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.params.XAddParams;
import redis.clients.jedis.params.XClaimParams;
Expand Down Expand Up @@ -56,6 +57,8 @@ default String restore(String key, int ttl, byte[] serializedValue) {

String restore(String key, long ttl, byte[] serializedValue);

String restore(String key, long ttl, byte[] serializedValue, RestoreParams params);

/**
* @deprecated Use {@link #expire(java.lang.String, long)}.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/redis/clients/jedis/commands/JedisCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.RestoreParams;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.params.XAddParams;
import redis.clients.jedis.params.XClaimParams;
Expand Down Expand Up @@ -72,8 +73,13 @@ default String restoreReplace(String key, int ttl, byte[] serializedValue) {
return restoreReplace(key, (long) ttl, serializedValue);
}

/**
* @deprecated Use {@link #restore(java.lang.String, long, byte[], redis.clients.jedis.params.RestoreParams)}.
*/
@Deprecated
String restoreReplace(String key, long ttl, byte[] serializedValue);

String restore(String key, long ttl, byte[] serializedValue, RestoreParams params);

/**
* @deprecated Use {@link #expire(java.lang.String, long)}.
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/redis/clients/jedis/commands/RedisPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import redis.clients.jedis.params.GeoAddParams;
import redis.clients.jedis.params.GeoRadiusParam;
import redis.clients.jedis.params.GetExParams;
import redis.clients.jedis.params.RestoreParams;
import redis.clients.jedis.params.SetParams;
import redis.clients.jedis.params.XAddParams;
import redis.clients.jedis.params.XClaimParams;
Expand Down Expand Up @@ -337,6 +338,8 @@ default Response<String> restoreReplace(String key, int ttl, byte[] serializedVa

Response<String> restoreReplace(String key, long ttl, byte[] serializedValue);

Response<String> restore(String key, long ttl, byte[] serializedValue, RestoreParams params);

Response<String> migrate(String host, int port, String key, int destinationDB, int timeout);

// Geo Commands
Expand Down
Loading

0 comments on commit 2ed7f3b

Please sign in to comment.