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 14 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
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ save ""
appendonly no
endef

define REDIS9_CONF
daemonize yes
protected-mode no
port 6387
pidfile /tmp/redis9.pid
logfile /tmp/redis9.log
save ""
appendonly no
maxmemory-policy allkeys-lfu
endef

sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
# SENTINELS
define REDIS_SENTINEL1
port 26379
Expand Down Expand Up @@ -253,6 +264,7 @@ export REDIS5_CONF
export REDIS6_CONF
export REDIS7_CONF
export REDIS8_CONF
export REDIS9_CONF
export REDIS_SENTINEL1
export REDIS_SENTINEL2
export REDIS_SENTINEL3
Expand Down Expand Up @@ -280,6 +292,7 @@ start: stunnel cleanup
echo "$$REDIS6_CONF" | redis-server -
echo "$$REDIS7_CONF" | redis-server -
echo "$$REDIS8_CONF" | redis-server -
echo "$$REDIS9_CONF" | redis-server -
echo "$$REDIS_SENTINEL1" > /tmp/sentinel1.conf && redis-server /tmp/sentinel1.conf --sentinel
@sleep 0.5
echo "$$REDIS_SENTINEL2" > /tmp/sentinel2.conf && redis-server /tmp/sentinel2.conf --sentinel
Expand Down Expand Up @@ -310,6 +323,7 @@ stop:
kill `cat /tmp/redis6.pid`
kill `cat /tmp/redis7.pid`
kill `cat /tmp/redis8.pid`
kill `cat /tmp/redis9.pid`
kill `cat /tmp/sentinel1.pid`
kill `cat /tmp/sentinel2.pid`
kill `cat /tmp/sentinel3.pid`
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,localhost:6387</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
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<byte[]> objectHelpBinary() {
client.objectHelp();
return client.getBinaryMultiBulkReply();
}

@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<byte[]> objectHelpBinary();

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,8 @@ Response<List<byte[]>> xclaim(byte[] key, byte[] group, byte[] consumername, lon

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

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
Expand Up @@ -24,6 +24,7 @@ private HostAndPortUtil(){
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT + 5));
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT + 6));
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT + 7));
redisHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_PORT + 8));

sentinelHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT));
sentinelHostAndPortList.add(new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT + 1));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package redis.clients.jedis.tests.commands;

import java.util.LinkedHashMap;
import java.util.Map;

sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
import org.junit.After;
import org.junit.Before;

sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.tests.HostAndPortUtil;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
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.After;
import org.junit.Before;
import org.junit.Test;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.tests.HostAndPortUtil;
import redis.clients.jedis.util.SafeEncoder;

import java.util.List;

public class ObjectCommandsTest extends JedisCommandTestBase {

private String key = "mylist";
private byte[] binaryKey = SafeEncoder.encode(key);
private static final HostAndPort lfuHnp = HostAndPortUtil.getRedisServers().get(8);
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
private Jedis lfuJedis;

@Before
public void setUp() throws Exception {
super.setUp();

lfuJedis = new Jedis(lfuHnp.getHost(), lfuHnp.getPort(), 500);
lfuJedis.connect();
lfuJedis.flushAll();
}

@After
public void tearDown() throws Exception {
super.tearDown();
lfuJedis.disconnect();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reverse order.

}

@Test
public void objectRefcount() {
Expand Down Expand Up @@ -45,4 +71,28 @@ public void objectIdletime() throws InterruptedException {
time = jedis.objectIdletime(binaryKey);
assertEquals(new Long(0), time);
}

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

// Binary
List<byte[]> helpBinaryTexts = jedis.objectHelpBinary();
assertNotNull(helpBinaryTexts);
}

@Test
public void objectFreq() {
lfuJedis.set(key, "test1");
lfuJedis.get(key);
// String
Long count = lfuJedis.objectFreq(key);
assertTrue(count > 0);

// Binary
count = lfuJedis.objectFreq(binaryKey);
assertTrue(count > 0);
}
}