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

* partial implementation of netty 4 client + refactoring on Reply inheritance tree #36

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 3 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
*.iml
*~
*.ipr
.idea
.project
.settings
target
*.iws
cache
*.releaseBackup
release.properties
*/.classpath
17 changes: 17 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@

*** Maintenance discoutinued *** - I personnally switched to scredis https://github.com/Livestream/scredis

Fork of https://github.com/spullara/redis-protocol

Maven repository available (see pom.xml in orange-groupid branch)

----

A very fast Redis client for the JVM.

Description of each module:
Expand Down Expand Up @@ -91,6 +100,7 @@ Various redis client benchmarks


Copyright 2012 Sam Pullara
Copyright 2014 Orange by Gaël Bréard

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -104,3 +114,10 @@ Copyright 2012 Sam Pullara
See the License for the specific language governing permissions and
limitations under the License.

Contributions:
Gaël Bréard: Update netty4 client
* partial implementation of netty 4 client (some verbs are missing, need just some more copy-paste)
* refactoring on Reply inheritance tree
* fix some issues on message order over intense usage of message pipelining
* some other minor modifications

7 changes: 6 additions & 1 deletion benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
<dependency>
<groupId>com.github.spullara.redis</groupId>
<artifactId>client</artifactId>
<version>0.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.orange.redis-embedded</groupId>
<artifactId>embedded-redis</artifactId>
<version>0.5</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand Down
34 changes: 27 additions & 7 deletions benchmark/src/test/java/redis/client/BenchmarkTest.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
package redis.client;

import org.junit.Test;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

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

import redis.embedded.RedisServer;

/**
* Run the benchmark with defaults
* <p/>
* User: sam
* Date: 3/18/12
* Time: 3:53 PM
* User: sam Date: 3/18/12 Time: 3:53 PM
*/
public class BenchmarkTest {

private RedisServer redisServer;

@Before
public void setup() throws Exception {
redisServer = new RedisServer();
redisServer.start();
// redisServer.getPort()
}

@After
public void tearDown() throws Exception {
redisServer.stop();
}

@Test
public void runBenchmark() throws IOException, ExecutionException, InterruptedException {
if (System.getenv().containsKey("CI") || System.getProperty("CI") != null) return;
Benchmark.main(new String[0]);
if (System.getenv().containsKey("CI") || System.getProperty("CI") != null)
return;
String[] args = { "-p", Integer.toString(redisServer.getPort()) };
// Benchmark.main(new String[0]);
Benchmark.main(args);
}
}
9 changes: 8 additions & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@
<dependency>
<groupId>com.github.spullara.redis</groupId>
<artifactId>protocol</artifactId>
<version>0.8-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.orange.redis-embedded</groupId>
<artifactId>embedded-redis</artifactId>
<version>0.5</version>
<scope>test</scope>
</dependency>

<!--
<dependency>
<groupId>redis.clients</groupId>
Expand Down
55 changes: 33 additions & 22 deletions client/src/test/java/redis/client/AllCommandsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

import com.google.common.base.Charsets;
import com.google.common.util.concurrent.ListenableFuture;

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

import redis.embedded.RedisServer;
import redis.reply.BulkReply;
import redis.reply.IntegerReply;
import redis.reply.MultiBulkReply;
import redis.reply.StatusReply;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;

Expand All @@ -31,45 +37,50 @@ public class AllCommandsTest {
private static RedisClient.Pipeline p;
private static RedisClient rc2;

private static RedisServer redisServer;

@BeforeClass
public static void setup() throws IOException {
rc = new RedisClient("localhost", 6379);
public static void setup() throws IOException, URISyntaxException {
redisServer = new RedisServer();
redisServer.start();
rc = new RedisClient("localhost", redisServer.getPort());
p = rc.pipeline();
rc2 = new RedisClient("localhost", 6379);
rc2 = new RedisClient("localhost", redisServer.getPort());
}

@AfterClass
public static void shutdown() throws IOException {
public static void shutdown() throws IOException, InterruptedException {
rc.close();
rc2.close();
redisServer.stop();
}


@Test
public void testDefaultAuthDB() throws IOException {
rc.config_set("requirepass", "test");
RedisClient test = new RedisClient("localhost", 6379, 1, "test");
try {
test.set("foo", "bar");
} catch (RedisException e) {
fail("default passwd failed");
}
test.config_set("requirepass", "");
rc.select(1);
if (!new String(rc.get("foo").data()).equals("bar"))
fail("default db failed");
rc.del("foo");
rc.config_set("requirepass", "test");
RedisClient test = new RedisClient("localhost", redisServer.getPort(), 1, "test");
try {
test.set("foo", "bar");
} catch (RedisException e) {
fail("default passwd failed");
}
test.config_set("requirepass", "");
rc.select(1);
if (!new String(rc.get("foo").data()).equals("bar"))
fail("default db failed");
rc.del("foo");
}

@Test
public void testauth() throws IOException {
rc.config_set("requirepass", "test");
RedisClient authtest = new RedisClient("localhost", 6379);
RedisClient authtest = new RedisClient("localhost", redisServer.getPort());
try {
authtest.info(null);
fail("should have thrown");
} catch (RedisException re) {
assertEquals("ERR operation not permitted", re.getMessage());
// assertEquals("ERR operation not permitted", re.getMessage());
assertEquals("NOAUTH Authentication required.", re.getMessage());
}
rc.auth("test");
rc.config_set("requirepass", "");
Expand Down Expand Up @@ -142,9 +153,9 @@ public void del() {
@Test
public void eval() {
// Commenting out for now until I upgrade my Redis
// eq(a("key1", "key2", "first", "second"),
// (MultiBulkReply) rc.eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2,
// a("key1", "key2", "first", "second")));
// eq(a("key1", "key2", "first", "second"),
// (MultiBulkReply) rc.eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", 2,
// a("key1", "key2", "first", "second")));
}

@Test
Expand Down
23 changes: 21 additions & 2 deletions client/src/test/java/redis/client/Issue19Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

import com.google.common.base.Charsets;
import com.google.common.util.concurrent.ListenableFuture;

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

import redis.Command;
import redis.embedded.RedisServer;
import redis.reply.Reply;

import java.io.IOException;
Expand All @@ -17,13 +22,27 @@
* https://github.com/spullara/redis-protocol/issues/19
*/
public class Issue19Test {

private RedisServer redisServer;

@Before
public void setup() throws Exception {
redisServer = new RedisServer();
redisServer.start();
}

@After
public void tearDown() throws Exception {
redisServer.stop();
}

@Test
public void testExecuteSyntaxError() throws IOException, InterruptedException, ExecutionException {
RedisClient client = new RedisClient("localhost", 6379);
RedisClient client = new RedisClient("localhost", redisServer.getPort());
client.multi();
String name = "ZADD";
// Wrong number of arguments for zadd command
Command cmd = new Command(name.getBytes(Charsets.UTF_8),"foo");
Command cmd = new Command(name.getBytes(Charsets.UTF_8), "foo");
ListenableFuture<? extends Reply> f = client.pipeline(name, cmd);
try {
// Fixed in 2.6.5
Expand Down
17 changes: 15 additions & 2 deletions client/src/test/java/redis/client/Issue20Test.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package redis.client;

import com.google.common.util.concurrent.ListenableFuture;

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

import redis.embedded.RedisServer;
import redis.reply.StatusReply;

import java.util.concurrent.Future;
Expand All @@ -15,9 +19,18 @@
public class Issue20Test {
private RedisClient client;

private RedisServer redisServer;

@Before
public void setUp() throws Exception {
client = new RedisClient("localhost", 6379);
public void setup() throws Exception {
redisServer = new RedisServer();
redisServer.start();
client = new RedisClient("localhost", redisServer.getPort());
}

@After
public void tearDown() throws Exception {
redisServer.stop();
}

@Test
Expand Down
21 changes: 19 additions & 2 deletions client/src/test/java/redis/client/Issue21Test.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package redis.client;

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

import redis.embedded.RedisServer;
import redis.reply.MultiBulkReply;
import redis.reply.Reply;

Expand All @@ -9,14 +13,27 @@
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;


/**
* https://github.com/spullara/redis-protocol/issues/21
*/
public class Issue21Test {
private RedisServer redisServer;

@Before
public void setup() throws Exception {
redisServer = new RedisServer();
redisServer.start();
// redisServer.getPort()
}

@After
public void tearDown() throws Exception {
redisServer.stop();
}

@Test
public void testBRPOPLPUSH() throws IOException {
RedisClient client = new RedisClient("localhost", 6379);
RedisClient client = new RedisClient("localhost", redisServer.getPort());
Reply brpoplpush = client.brpoplpush("alskdjflksadf", "alksdjflaksdfj", 1);
assertTrue(brpoplpush instanceof MultiBulkReply);
assertEquals(null, ((MultiBulkReply) brpoplpush).data());
Expand Down
22 changes: 21 additions & 1 deletion client/src/test/java/redis/client/Issue24Test.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package redis.client;

import com.google.common.util.concurrent.ListenableFuture;

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

import redis.embedded.RedisServer;
import redis.reply.ErrorReply;

import java.util.concurrent.ExecutionException;
Expand All @@ -15,9 +20,24 @@
* Issue 24: https://github.com/spullara/redis-protocol/issues/24
*/
public class Issue24Test {

private RedisServer redisServer;

@Before
public void setup() throws Exception {
redisServer = new RedisServer();
redisServer.start();
// redisServer.getPort()
}

@After
public void tearDown() throws Exception {
redisServer.stop();
}

@Test
public void testRestoreBadData() throws Exception {
RedisClient client = new RedisClient("localhost", 6379);
RedisClient client = new RedisClient("localhost", redisServer.getPort());
RedisClient.Pipeline pipeline = client.pipeline();
client.multi();

Expand Down
Loading