Skip to content
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

Implements objecthelp and objectFREQ method. #2141

Merged
merged 19 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import static redis.clients.jedis.Protocol.Keyword.RESET;
import static redis.clients.jedis.Protocol.Keyword.STORE;
import static redis.clients.jedis.Protocol.Keyword.WITHSCORES;
import static redis.clients.jedis.Protocol.Keyword.FREQ;
import static redis.clients.jedis.Protocol.Keyword.HELP;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -991,6 +993,14 @@ public void objectEncoding(final byte[] key) {
sendCommand(OBJECT, ENCODING.raw, key);
}

public void objectHelp() {
sendCommand(OBJECT, HELP.raw);
}

public void objectFreq(final byte[] key) {
sendCommand(OBJECT, FREQ.raw, key);
}

public void bitcount(final byte[] key) {
sendCommand(BITCOUNT, key);
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -3461,6 +3461,18 @@ public Long objectIdletime(final byte[] key) {
return client.getIntegerReply();
}

@Override
public List<String> objectHelp() {
client.objectHelp();
return client.getMultiBulkReply();
}

@Override
public Long objectFreq(final byte[] key) {
client.objectFreq(key);
return client.getIntegerReply();
}

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

public List<String> objectHelp() {
Jedis j = getShard("null");
return j.objectHelp();
}

public Long objectFreq(final byte[] key) {
Jedis j = getShard(key);
return j.objectIdletime(key);
}

@Override
public Boolean setbit(final byte[] key, final long offset, boolean value) {
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 @@ -846,6 +846,11 @@ public void objectEncoding(final String key) {
objectEncoding(SafeEncoder.encode(key));
}

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

@Override
public void bitcount(final String key) {
bitcount(SafeEncoder.encode(key));
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -2962,6 +2962,18 @@ public Long objectIdletime(final String key) {
return client.getIntegerReply();
}

@Override
public List<String> objectHelp() {
client.objectHelp();
return client.getMultiBulkReply();
}

@Override
public Long objectFreq(final String key) {
client.objectFreq(key);
return client.getIntegerReply();
}

@Override
public Long bitcount(final String key) {
checkIsInMultiOrPipeline();
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/redis/clients/jedis/PipelineBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,24 @@ public Response<Long> objectIdletime(final byte[] key) {
return getResponse(BuilderFactory.LONG);
}

@Override
public Response<String> objectHelp() {
getClient("null").objectHelp();
return getResponse(BuilderFactory.STRING);
}

@Override
public Response<Long> objectFreq(byte[] key) {
getClient(key).objectFreq(key);
return getResponse(BuilderFactory.LONG);
}

@Override
public Response<Long> objectFreq(String key) {
getClient(key).objectFreq(key);
return getResponse(BuilderFactory.LONG);
}

@Override
public Response<Long> pexpire(final String key, final long milliseconds) {
getClient(key).pexpire(key, milliseconds);
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 @@ -280,7 +280,7 @@ public static enum Keyword {
RESETSTAT, REWRITE, RESET, FLUSH, EXISTS, LOAD, KILL, LEN, REFCOUNT, ENCODING, IDLETIME,
GETNAME, SETNAME, LIST, MATCH, COUNT, PING, PONG, UNLOAD, REPLACE, KEYS, PAUSE, DOCTOR,
BLOCK, NOACK, STREAMS, KEY, CREATE, MKSTREAM, SETID, DESTROY, DELCONSUMER, MAXLEN, GROUP,
IDLE, TIME, RETRYCOUNT, FORCE, STREAM, GROUPS, CONSUMERS;
IDLE, TIME, RETRYCOUNT, FORCE, STREAM, GROUPS, CONSUMERS, HELP, FREQ;

public final byte[] raw;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public interface AdvancedBinaryJedisCommands {

Long objectIdletime(byte[] key);

List<String> objectHelp();
dengliming marked this conversation as resolved.
Show resolved Hide resolved

Long objectFreq(byte[] key);

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

String migrate(String host, int port, int destinationDB, int timeout, MigrateParams params, byte[]... keys);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public interface AdvancedJedisCommands {

Long objectIdletime(String key);

List<String> objectHelp();

Long objectFreq(String key);

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

String migrate(String host, int port, int destinationDB, int timeout, MigrateParams params, String... keys);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ Response<List<byte[]>> xclaim(byte[] key, byte[] group, byte[] consumername, lon

Response<Long> objectIdletime(byte[] key);

Response<String> objectHelp();
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved

Response<Long> objectFreq(byte[] key);

Response<Double> incrByFloat(byte[] key, double increment);

Response<String> psetex(byte[] key, long milliseconds, byte[] value);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/redis/clients/jedis/commands/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ void zrevrangeByScoreWithScores(String key, String max, String min,

void objectEncoding(String key);

void objectHelp();

void objectFreq(String key);

void bitcount(String key);

void bitcount(String key, long start, long end);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/redis/clients/jedis/commands/RedisPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ Response<Set<Tuple>> zrangeByScoreWithScores(String key, String min, String max,

Response<Long> objectIdletime(String key);

Response<String> objectHelp();
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved

Response<Long> objectFreq(String key);

Response<Double> incrByFloat(String key, double increment);

Response<String> psetex(String key, long milliseconds, String value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package redis.clients.jedis.tests.commands;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import redis.clients.jedis.util.SafeEncoder;

import java.util.List;

public class ObjectCommandsTest extends JedisCommandTestBase {

private String key = "mylist";
Expand Down Expand Up @@ -45,4 +49,27 @@ public void objectIdletime() throws InterruptedException {
time = jedis.objectIdletime(binaryKey);
assertEquals(new Long(0), time);
}

@Test
public void objectHelp() {
List<String> helpTexts = jedis.objectHelp();
assertNotNull(helpTexts);
}

@Test
public void objectFreq() {
jedis.set(key, "test1");
// Before we test objectFreq command, we must config maxmemory-policy or will throw "An LFU maxmemory policy is not selected, access frequency not tracked. Please note that when switching between policies at runtime LRU and LFU data will take some time to adjust."
jedis.configSet("maxmemory-policy", "allkeys-lfu");
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
jedis.get(key);
// String
Long count = jedis.objectFreq(key);
assertTrue(count > 0);

// Binary
count = jedis.objectFreq(binaryKey);
assertTrue(count > 0);
// Reset default config for other test case.
jedis.configSet("maxmemory-policy", "noeviction");
}
}