Skip to content
Closed
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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ define REDIS8_CONF
daemonize yes
protected-mode no
port 6386
requirepass foobared
Copy link
Contributor

@sazzad16 sazzad16 Jul 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test requires instance at 6386 port to be password-less. Either create a new instance or create a new one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"a new instance or create a new one"? what is the different between "new instance" and "new one"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops!

"Either use password-less instance or create a new one."

pidfile /tmp/redis8.pid
logfile /tmp/redis8.log
save ""
appendonly no
rename-command SET NEWSET
rename-command GET NEWGET
rename-command DEL ""
endef

# SENTINELS
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</scm>

<properties>
<redis-hosts>localhost:6379,localhost:6380,localhost:6381,localhost:6382,localhost:6383,localhost:6384,localhost:6385</redis-hosts>
<redis-hosts>localhost:6379,localhost:6380,localhost:6381,localhost:6382,localhost:6383,localhost:6384,localhost:6385,localhost:6386</redis-hosts>
<sentinel-hosts>localhost:26379,localhost:26380,localhost:26381</sentinel-hosts>
<cluster-hosts>localhost:7379,localhost:7380,localhost:7381,localhost:7382,localhost:7383,localhost:7384,localhost:7385</cluster-hosts>
<github.global.server>github</github.global.server>
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/redis/clients/jedis/Protocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,20 @@ public static enum Command implements ProtocolCommand {
GEORADIUSBYMEMBER, GEORADIUSBYMEMBER_RO, MODULE, BITFIELD, HSTRLEN, TOUCH, SWAPDB, MEMORY,
XADD, XLEN, XDEL, XTRIM, XRANGE, XREVRANGE, XREAD, XACK, XGROUP, XREADGROUP, XPENDING, XCLAIM;

private final byte[] raw;
private byte[] raw;

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

@Override
public byte[] getRaw() {
return raw;
}

public void rename(final String newName) {
raw = SafeEncoder.encode(newName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this be an issue in multithreading? Synchronized/Lock may be required here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, but volatile should do, I'm trying to find a way to avoid the performance penalty on each getRaw() call

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • +1 to volatile (or AtomicReference), at the moment it's not though, so we need to update that to either volatile or AtomicReference.
  • We should make this fail (and have tests for) if newName is:
    • null
    • empty
    • an existing command name

}
}

public static enum Keyword {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package redis.clients.jedis.tests.commands;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Protocol.Command;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.tests.HostAndPortUtil;

public class RenameProtocolCommandsTest {

private Jedis jedis;

@Before
public void setUp() throws Exception {
HostAndPort hnp = HostAndPortUtil.getRedisServers().get(7);
jedis = new Jedis(hnp.getHost(), hnp.getPort(), 500);
jedis.connect();
jedis.auth("foobared");
jedis.flushAll();

Command.SET.rename("NEWSET");
Command.GET.rename("NEWGET");
}

@After
public void tearDown() {
Command.SET.rename("SET");
Command.GET.rename("GET");

jedis.disconnect();
}

@Test
public void renameCommand() {
jedis.set("mykey", "hello world");
String value = jedis.get("mykey");
assertEquals("hello world", value);
}

@Test
public void disabledCommand() {
jedis.set("mykey", "hello world2");
try {
jedis.del("mykey");
fail("'DEL' command should be unknown");
} catch (JedisDataException expected) {
assertEquals("ERR unknown command 'DEL'", expected.getMessage());
Copy link
Contributor

@yangbodong22011 yangbodong22011 Jan 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assertEquals("ERR unknown command 'DEL'", expected.getMessage());
// We need use a regex for the error message, because it may has different format
// 1, ERR unknown command 'DEL'
// 2, ERR unknown command `del`, with args beginning with: `abc` (Redis 6.2)
Assert.assertTrue(expected.getMessage().matches("ERR unknown command .DEL.*"));

}
String value = jedis.get("mykey");
assertEquals("hello world2", value);
}
}