Merge branch 'master' into 3.0.0

pull/1821/head
Nikita 7 years ago
commit 663d479201

@ -13,6 +13,19 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/**
* Copyright (C) 2011 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package org.redisson; package org.redisson;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -43,8 +56,6 @@ import io.netty.buffer.ByteBuf;
/** /**
* Bloom filter based on Highway 128-bit hash. * Bloom filter based on Highway 128-bit hash.
* *
* Code parts from Guava BloomFilter
*
* @author Nikita Koksharov * @author Nikita Koksharov
* *
* @param <T> type of object * @param <T> type of object

@ -198,17 +198,10 @@ public interface RKeys extends RKeysAsync {
*/ */
String randomKey(); String randomKey();
/** /*
* Find keys by key search pattern at once using KEYS command. * Use getKeysByPattern method instead
*
* Supported glob-style patterns:
* h?llo subscribes to hello, hallo and hxllo
* h*llo subscribes to hllo and heeeello
* h[ae]llo subscribes to hello and hallo, but not hillo
*
* @param pattern - match pattern
* @return collection of keys
*/ */
@Deprecated
Collection<String> findKeysByPattern(String pattern); Collection<String> findKeysByPattern(String pattern);
/** /**

@ -158,17 +158,10 @@ public interface RKeysAsync {
*/ */
RFuture<String> randomKeyAsync(); RFuture<String> randomKeyAsync();
/** /*
* Find keys by key search pattern in async mode * Use getKeysByPattern method instead
*
* Supported glob-style patterns:
* h?llo subscribes to hello, hallo and hxllo
* h*llo subscribes to hllo and heeeello
* h[ae]llo subscribes to hello and hallo, but not hillo
*
* @param pattern - match pattern
* @return collections of keys
*/ */
@Deprecated
RFuture<Collection<String>> findKeysByPatternAsync(String pattern); RFuture<Collection<String>> findKeysByPatternAsync(String pattern);
/** /**

@ -13,6 +13,22 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/**
* Copyright 2012 Sam Pullara
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.redisson.client.handler; package org.redisson.client.handler;
import java.io.IOException; import java.io.IOException;
@ -52,8 +68,6 @@ import io.netty.util.CharsetUtil;
/** /**
* Redis protocol command decoder * Redis protocol command decoder
* *
* Code parts from Sam Pullara
*
* @author Nikita Koksharov * @author Nikita Koksharov
* *
*/ */

@ -13,11 +13,24 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/**
* Copyright 2012 Sam Pullara
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.redisson.client.handler; package org.redisson.client.handler;
import java.util.HashMap;
import java.util.Map;
import org.redisson.client.protocol.CommandData; import org.redisson.client.protocol.CommandData;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -34,8 +47,6 @@ import io.netty.util.CharsetUtil;
/** /**
* Redis protocol command encoder * Redis protocol command encoder
* *
* Code parts from Sam Pullara
*
* @author Nikita Koksharov * @author Nikita Koksharov
* *
*/ */
@ -50,8 +61,6 @@ public class CommandEncoder extends MessageToByteEncoder<CommandData<?, ?>> {
private static final char BYTES_PREFIX = '$'; private static final char BYTES_PREFIX = '$';
private static final byte[] CRLF = "\r\n".getBytes(); private static final byte[] CRLF = "\r\n".getBytes();
private static final Map<Long, byte[]> longCache = new HashMap<Long, byte[]>();
@Override @Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (acceptOutboundMessage(msg)) { if (acceptOutboundMessage(msg)) {
@ -76,7 +85,7 @@ public class CommandEncoder extends MessageToByteEncoder<CommandData<?, ?>> {
if (msg.getCommand().getSubName() != null) { if (msg.getCommand().getSubName() != null) {
len++; len++;
} }
out.writeBytes(convert(len)); out.writeCharSequence(Long.toString(len), CharsetUtil.US_ASCII);
out.writeBytes(CRLF); out.writeBytes(CRLF);
writeArgument(out, msg.getCommand().getName().getBytes(CharsetUtil.UTF_8)); writeArgument(out, msg.getCommand().getName().getBytes(CharsetUtil.UTF_8));
@ -120,7 +129,7 @@ public class CommandEncoder extends MessageToByteEncoder<CommandData<?, ?>> {
private void writeArgument(ByteBuf out, byte[] arg) { private void writeArgument(ByteBuf out, byte[] arg) {
out.writeByte(BYTES_PREFIX); out.writeByte(BYTES_PREFIX);
out.writeBytes(convert(arg.length)); out.writeCharSequence(Long.toString(arg.length), CharsetUtil.US_ASCII);
out.writeBytes(CRLF); out.writeBytes(CRLF);
out.writeBytes(arg); out.writeBytes(arg);
out.writeBytes(CRLF); out.writeBytes(CRLF);
@ -128,92 +137,10 @@ public class CommandEncoder extends MessageToByteEncoder<CommandData<?, ?>> {
private void writeArgument(ByteBuf out, ByteBuf arg) { private void writeArgument(ByteBuf out, ByteBuf arg) {
out.writeByte(BYTES_PREFIX); out.writeByte(BYTES_PREFIX);
out.writeBytes(convert(arg.readableBytes())); out.writeCharSequence(Long.toString(arg.readableBytes()), CharsetUtil.US_ASCII);
out.writeBytes(CRLF); out.writeBytes(CRLF);
out.writeBytes(arg, arg.readerIndex(), arg.readableBytes()); out.writeBytes(arg, arg.readerIndex(), arg.readableBytes());
out.writeBytes(CRLF); out.writeBytes(CRLF);
} }
static final char[] DIGITTENS = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1', '1', '1', '1',
'1', '1', '1', '1', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '3', '3', '3', '3', '3', '3', '3',
'3', '3', '3', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '5', '5', '5', '5', '5', '5', '5', '5',
'5', '5', '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '7', '7', '7', '7', '7', '7', '7', '7', '7',
'7', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '9', '9', '9', '9', '9', '9', '9', '9', '9', '9', };
static final char[] DIGITONES = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6',
'7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', };
static final char[] DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
static final int[] SIZETABLE = { 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, Integer.MAX_VALUE };
// Requires positive x
static int stringSize(long x) {
for (int i = 0;; i++)
if (x <= SIZETABLE[i])
return i + 1;
}
static void getChars(long i, int index, byte[] buf) {
long q, r;
int charPos = index;
byte sign = 0;
if (i < 0) {
sign = '-';
i = -i;
}
// Generate two digits per iteration
while (i >= 65536) {
q = i / 100;
// really: r = i - (q * 100);
r = i - ((q << 6) + (q << 5) + (q << 2));
i = q;
buf[--charPos] = (byte) DIGITONES[(int) r];
buf[--charPos] = (byte) DIGITTENS[(int) r];
}
// Fall thru to fast mode for smaller numbers
// assert(i <= 65536, i);
for (;;) {
q = (i * 52429) >>> (16 + 3);
r = i - ((q << 3) + (q << 1)); // r = i-(q*10) ...
buf[--charPos] = (byte) DIGITS[(int) r];
i = q;
if (i == 0)
break;
}
if (sign != 0) {
buf[--charPos] = sign;
}
}
public static byte[] convert(long i) {
if (i >= 0 && i <= 255) {
return longCache.get(i);
}
return toChars(i);
}
public static byte[] toChars(long i) {
int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
byte[] buf = new byte[size];
getChars(i, size, buf);
return buf;
}
static {
for (long i = 0; i < 256; i++) {
byte[] value = toChars(i);
longCache.put(i, value);
}
}
} }

@ -61,6 +61,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import io.netty.resolver.AddressResolver; import io.netty.resolver.AddressResolver;
import io.netty.util.NetUtil;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener; import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.ScheduledFuture; import io.netty.util.concurrent.ScheduledFuture;
@ -100,15 +101,9 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
try { try {
RedisConnection connection = connectionFuture.syncUninterruptibly().getNow(); RedisConnection connection = connectionFuture.syncUninterruptibly().getNow();
if (cfg.getNodeAddresses().size() == 1) { if (cfg.getNodeAddresses().size() == 1 && NetUtil.createByteArrayFromIpAddressString(addr.getHost()) == null) {
AddressResolver<InetSocketAddress> resolver = createResolverGroup().getResolver(getGroup().next()); configEndpointHostName = addr.getHost();
Future<List<InetSocketAddress>> addrsFuture = resolver.resolveAll(InetSocketAddress.createUnresolved(addr.getHost(), addr.getPort())); isConfigEndpoint = true;
List<InetSocketAddress> allAddrs = addrsFuture.syncUninterruptibly().getNow();
if (allAddrs.size() > 1) {
configEndpointHostName = addr.getHost();
isConfigEndpoint = true;
}
resolver.close();
} }
clusterNodesCommand = RedisCommands.CLUSTER_NODES; clusterNodesCommand = RedisCommands.CLUSTER_NODES;
@ -300,7 +295,6 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
public void operationComplete(Future<List<InetSocketAddress>> future) throws Exception { public void operationComplete(Future<List<InetSocketAddress>> future) throws Exception {
AtomicReference<Throwable> lastException = new AtomicReference<Throwable>(future.cause()); AtomicReference<Throwable> lastException = new AtomicReference<Throwable>(future.cause());
if (!future.isSuccess()) { if (!future.isSuccess()) {
resolver.close();
checkClusterState(cfg, Collections.<URI>emptyList().iterator(), lastException); checkClusterState(cfg, Collections.<URI>emptyList().iterator(), lastException);
return; return;
} }
@ -311,7 +305,6 @@ public class ClusterConnectionManager extends MasterSlaveConnectionManager {
nodes.add(node); nodes.add(node);
} }
resolver.close();
Iterator<URI> nodesIterator = nodes.iterator(); Iterator<URI> nodesIterator = nodes.iterator();
checkClusterState(cfg, nodesIterator, lastException); checkClusterState(cfg, nodesIterator, lastException);
} }

Loading…
Cancel
Save