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
13 changes: 13 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.FlushMode;
import redis.clients.jedis.args.UnblockType;
import redis.clients.jedis.params.*;
import redis.clients.jedis.util.SafeEncoder;
Expand Down Expand Up @@ -217,6 +218,10 @@ public void flushDB() {
sendCommand(FLUSHDB);
}

public void flushDB(FlushMode flushMode) {
sendCommand(FLUSHDB, flushMode.getRaw());
}

public void keys(final byte[] pattern) {
sendCommand(KEYS, pattern);
}
Expand Down Expand Up @@ -277,6 +282,10 @@ public void flushAll() {
sendCommand(FLUSHALL);
}

public void flushAll(FlushMode flushMode) {
sendCommand(FLUSHALL, flushMode.getRaw());
}

public void getSet(final byte[] key, final byte[] value) {
sendCommand(GETSET, key, value);
}
Expand Down Expand Up @@ -1098,6 +1107,10 @@ public void scriptFlush() {
sendCommand(SCRIPT, Keyword.FLUSH.getRaw());
}

public void scriptFlush(FlushMode flushMode) {
sendCommand(SCRIPT, Keyword.FLUSH.getRaw(), flushMode.getRaw());
}

public void scriptExists(final byte[]... sha1) {
sendCommand(SCRIPT, joinParameters(Keyword.EXISTS.getRaw(), sha1));
}
Expand Down
32 changes: 32 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.FlushMode;
import redis.clients.jedis.args.UnblockType;
import redis.clients.jedis.commands.AdvancedBinaryJedisCommands;
import redis.clients.jedis.commands.BasicCommands;
Expand Down Expand Up @@ -529,6 +530,18 @@ public String flushDB() {
return client.getStatusCodeReply();
}

/**
* Delete all the keys of the currently selected DB. This command never fails.
* @param flushMode
* @return Status code reply
*/
@Override
public String flushDB(FlushMode flushMode) {
checkIsInMultiOrPipeline();
client.flushDB(flushMode);
return client.getStatusCodeReply();
}

/**
* Returns all the keys matching the glob-style pattern as space separated strings. For example if
* you have in the database the keys "foo" and "foobar" the command "KEYS foo*" will return
Expand Down Expand Up @@ -766,6 +779,19 @@ public String flushAll() {
return client.getStatusCodeReply();
}

/**
* Delete all the keys of all the existing databases, not just the currently selected one. This
* command never fails.
* @param flushMode
* @return Status code reply
*/
@Override
public String flushAll(FlushMode flushMode) {
checkIsInMultiOrPipeline();
client.flushAll(flushMode);
return client.getStatusCodeReply();
}

/**
* GETSET is an atomic set this value and return the old value command. Set key to the string
* value and return the old value stored at key. The string can't be longer than 1073741824 bytes
Expand Down Expand Up @@ -3747,6 +3773,12 @@ public String scriptFlush() {
return client.getStatusCodeReply();
}

@Override
public String scriptFlush(final FlushMode flushMode) {
client.scriptFlush(flushMode);
return client.getStatusCodeReply();
}

public Long scriptExists(final byte[] sha1) {
byte[][] a = new byte[1][];
a[0] = sha1;
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
@@ -1,5 +1,6 @@
package redis.clients.jedis;

import redis.clients.jedis.args.FlushMode;
import redis.clients.jedis.commands.BinaryJedisClusterCommands;
import redis.clients.jedis.commands.JedisClusterBinaryScriptingCommands;
import redis.clients.jedis.commands.MultiKeyBinaryJedisClusterCommands;
Expand Down Expand Up @@ -1710,6 +1711,16 @@ public String execute(Jedis connection) {
}.runBinary(sampleKey);
}

@Override
public String scriptFlush(final byte[] sampleKey, final FlushMode flushMode) {
return new JedisClusterCommand<String>(connectionHandler, maxAttempts) {
@Override
public String execute(Jedis connection) {
return connection.scriptFlush(flushMode);
}
}.runBinary(sampleKey);
}

@Override
public String scriptKill(final byte[] sampleKey) {
return new JedisClusterCommand<String>(connectionHandler, maxAttempts) {
Expand Down
13 changes: 13 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.FlushMode;
import redis.clients.jedis.commands.*;
import redis.clients.jedis.params.*;

Expand Down Expand Up @@ -499,6 +500,18 @@ public Response<String> flushAll() {
return getResponse(BuilderFactory.STRING);
}

@Override
public Response<String> flushDB(FlushMode flushMode) {
client.flushDB(flushMode);
return getResponse(BuilderFactory.STRING);
}

@Override
public Response<String> flushAll(FlushMode flushMode) {
client.flushAll(flushMode);
return getResponse(BuilderFactory.STRING);
}

@Override
public Response<String> info() {
client.info();
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/redis/clients/jedis/args/FlushMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package redis.clients.jedis.args;

import redis.clients.jedis.util.SafeEncoder;

/**
* Enum object describing flushing mode.
*/
public enum FlushMode implements Rawable {

/**
* flushes synchronously
*/
SYNC,

/**
* flushes asynchronously
*/
ASYNC;

private final byte[] raw;

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

@Override
public byte[] getRaw() {
return raw;
}
}
16 changes: 16 additions & 0 deletions src/main/java/redis/clients/jedis/commands/BasicCommands.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package redis.clients.jedis.commands;

import redis.clients.jedis.DebugParams;
import redis.clients.jedis.args.FlushMode;

public interface BasicCommands {

Expand All @@ -24,6 +25,14 @@ public interface BasicCommands {
*/
String flushDB();

/**
* Delete all the keys of the currently selected DB. This command never fails. The time-complexity
* for this operation is O(N), N being the number of keys in the database.
* @param flushMode
* @return OK
*/
String flushDB(FlushMode flushMode);

/**
* Return the number of keys in the currently-selected database.
* @return the number of key in the currently-selected database.
Expand Down Expand Up @@ -52,6 +61,13 @@ public interface BasicCommands {
*/
String flushAll();

/**
* Delete all the keys of all the existing databases, not just the currently selected one.
* @param flushMode
* @return a simple string reply (OK)
*/
String flushAll(FlushMode flushMode);

/**
* Request for authentication in a password-protected Redis server. Redis can be instructed to
* require a password before allowing clients to execute commands. This is done using the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import redis.clients.jedis.Module;
import redis.clients.jedis.Response;
import redis.clients.jedis.args.FlushMode;

import java.util.List;

Expand All @@ -26,8 +27,12 @@ public interface BasicRedisPipeline {

Response<String> flushDB();

Response<String> flushDB(FlushMode flushMode);

Response<String> flushAll();

Response<String> flushAll(FlushMode flushMode);

Response<String> info();

Response<List<String>> time();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package redis.clients.jedis.commands;

import redis.clients.jedis.args.FlushMode;

import java.util.List;

public interface BinaryScriptingCommands {
Expand All @@ -25,5 +27,7 @@ public interface BinaryScriptingCommands {

String scriptFlush();

String scriptFlush(FlushMode flushMode);

String scriptKill();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package redis.clients.jedis.commands;

import redis.clients.jedis.args.FlushMode;

import java.util.List;

public interface JedisClusterBinaryScriptingCommands {
Expand Down Expand Up @@ -52,6 +54,14 @@ public interface JedisClusterBinaryScriptingCommands {
*/
String scriptFlush(byte[] sampleKey);

/**
* @param sampleKey Command will be executed in the node where the hash slot of this key is
* assigned to
* @param flushMode
* @return
*/
String scriptFlush(byte[] sampleKey, FlushMode flushMode);

/**
* @param sampleKey Command will be executed in the node where the hash slot of this key is
* assigned to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import redis.clients.jedis.ScanParams;
import redis.clients.jedis.ScanResult;
import redis.clients.jedis.StreamEntryID;
import redis.clients.jedis.args.FlushMode;
import redis.clients.jedis.util.SafeEncoder;
import redis.clients.jedis.exceptions.JedisDataException;

Expand Down Expand Up @@ -555,7 +556,8 @@ public void flushDB() {
assertEquals(0, jedis.dbSize().intValue());
jedis.select(1);
assertEquals(1, jedis.dbSize().intValue());
jedis.del("bar");
assertEquals("OK", jedis.flushDB(FlushMode.SYNC));
assertEquals(0, jedis.dbSize().intValue());

// Binary
jedis.select(0);
Expand All @@ -568,7 +570,8 @@ public void flushDB() {
assertEquals(0, jedis.dbSize().intValue());
jedis.select(1);
assertEquals(1, jedis.dbSize().intValue());

assertEquals("OK", jedis.flushDB(FlushMode.ASYNC));
assertEquals(0, jedis.dbSize().intValue());
}

@Test
Expand All @@ -582,6 +585,10 @@ public void flushAll() {
assertEquals(0, jedis.dbSize().intValue());
jedis.select(1);
assertEquals(0, jedis.dbSize().intValue());
jedis.set("foo", "bar");
assertEquals(1, jedis.dbSize().intValue());
assertEquals("OK", jedis.flushAll(FlushMode.SYNC));
assertEquals(0, jedis.dbSize().intValue());

// Binary
jedis.select(0);
Expand All @@ -594,7 +601,10 @@ public void flushAll() {
assertEquals(0, jedis.dbSize().intValue());
jedis.select(1);
assertEquals(0, jedis.dbSize().intValue());

jedis.set(bfoo, bbar);
assertEquals(1, jedis.dbSize().intValue());
assertEquals("OK", jedis.flushAll(FlushMode.ASYNC));
assertEquals(0, jedis.dbSize().intValue());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.List;
import org.junit.Test;

import redis.clients.jedis.args.FlushMode;
import redis.clients.jedis.exceptions.JedisClusterOperationException;
import redis.clients.jedis.exceptions.JedisDataException;

Expand Down Expand Up @@ -73,6 +74,7 @@ public void testBinaryScriptFlush() {
byte[] byteKey = "key1".getBytes();
jedisCluster.scriptLoad("return redis.call('get','foo')".getBytes(), byteKey);
assertEquals("OK", jedisCluster.scriptFlush(byteKey));
assertEquals("OK", jedisCluster.scriptFlush(byteKey, FlushMode.SYNC));
}

@Test(expected = JedisDataException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import redis.clients.jedis.BinaryJedis;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.args.FlushMode;
import redis.clients.jedis.exceptions.JedisConnectionException;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.exceptions.JedisNoScriptException;
Expand Down Expand Up @@ -152,6 +153,16 @@ public void scriptFlush() {
assertFalse(jedis.scriptExists("6b1bf486c81ceb7edf3c093f4c48582e38c0e791"));
}

@Test
public void scriptFlushMode() {
jedis.set("foo", "bar");
jedis.eval("return redis.call('get','foo')");
String sha1 = "6b1bf486c81ceb7edf3c093f4c48582e38c0e791";
assertTrue(jedis.scriptExists(sha1));
jedis.scriptFlush(FlushMode.SYNC);
assertFalse(jedis.scriptExists(sha1));
}

@Test
public void scriptExists() {
jedis.scriptLoad("return redis.call('get','foo')");
Expand Down