beiwei30 closed pull request #1987: [Dubbo-1986]optimize redis connection
release
URL: https://github.com/apache/incubator-dubbo/pull/1987
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/dubbo-rpc/dubbo-rpc-redis/src/main/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocol.java
b/dubbo-rpc/dubbo-rpc-redis/src/main/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocol.java
index 7a5f7d7a74..5c12a1037f 100644
---
a/dubbo-rpc/dubbo-rpc-redis/src/main/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocol.java
+++
b/dubbo-rpc/dubbo-rpc-redis/src/main/java/org/apache/dubbo/rpc/protocol/redis/RedisProtocol.java
@@ -98,15 +98,15 @@ private Serialization getSerialization(URL url) {
return new AbstractInvoker<T>(type, url) {
@Override
protected Result doInvoke(Invocation invocation) throws
Throwable {
- Jedis resource = null;
+ Jedis jedis = null;
try {
- resource = jedisPool.getResource();
+ jedis = jedisPool.getResource();
if (get.equals(invocation.getMethodName())) {
if (invocation.getArguments().length != 1) {
throw new IllegalArgumentException("The redis
get method arguments mismatch, must only one arguments. interface: " +
type.getName() + ", method: " + invocation.getMethodName() + ", url: " + url);
}
- byte[] value =
resource.get(String.valueOf(invocation.getArguments()[0]).getBytes());
+ byte[] value =
jedis.get(String.valueOf(invocation.getArguments()[0]).getBytes());
if (value == null) {
return new RpcResult();
}
@@ -120,16 +120,16 @@ protected Result doInvoke(Invocation invocation) throws
Throwable {
ByteArrayOutputStream output = new
ByteArrayOutputStream();
ObjectOutput value =
getSerialization(url).serialize(url, output);
value.writeObject(invocation.getArguments()[1]);
- resource.set(key, output.toByteArray());
+ jedis.set(key, output.toByteArray());
if (expiry > 1000) {
- resource.expire(key, expiry / 1000);
+ jedis.expire(key, expiry / 1000);
}
return new RpcResult();
} else if (delete.equals(invocation.getMethodName())) {
if (invocation.getArguments().length != 1) {
throw new IllegalArgumentException("The redis
delete method arguments mismatch, must only one arguments. interface: " +
type.getName() + ", method: " + invocation.getMethodName() + ", url: " + url);
}
-
resource.del(String.valueOf(invocation.getArguments()[0]).getBytes());
+
jedis.del(String.valueOf(invocation.getArguments()[0]).getBytes());
return new RpcResult();
} else {
throw new
UnsupportedOperationException("Unsupported method " +
invocation.getMethodName() + " in redis service.");
@@ -145,9 +145,9 @@ protected Result doInvoke(Invocation invocation) throws
Throwable {
}
throw re;
} finally {
- if (resource != null) {
+ if (jedis != null) {
try {
- jedisPool.returnResource(resource);
+ jedis.close();
} catch (Throwable t) {
logger.warn("returnResource error: " +
t.getMessage(), t);
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]