-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Support rename-command (#1817) #1822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c2e7276
7a1527c
d1f41c2
f54fa0b
2374c44
7c76999
dd00cee
cc100f6
af0bd44
942304d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| } | ||
|
|
||
| public static enum Keyword { | ||
|
|
||
| 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()); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| } | ||||||||||||
| String value = jedis.get("mykey"); | ||||||||||||
| assertEquals("hello world2", value); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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."