response of time() method extended. #1443

pull/1461/head
Nikita 7 years ago
parent 6e9f8d667e
commit 510f0e1ffc

@ -18,6 +18,8 @@ package org.redisson.api;
import java.net.InetSocketAddress;
import java.util.Map;
import org.redisson.client.protocol.Time;
/**
* Redis node interface
*
@ -35,7 +37,7 @@ public interface Node extends NodeAsync {
*
* @return time in seconds
*/
long time();
Time time();
/**
* Returns node type

@ -18,6 +18,7 @@ package org.redisson.api;
import java.util.Map;
import org.redisson.api.Node.InfoSection;
import org.redisson.client.protocol.Time;
/**
* Redis node interface
@ -29,7 +30,7 @@ public interface NodeAsync {
RFuture<Map<String, String>> infoAsync(InfoSection section);
RFuture<Long> timeAsync();
RFuture<Time> timeAsync();
RFuture<Boolean> pingAsync();

@ -19,9 +19,14 @@ import java.util.concurrent.atomic.AtomicBoolean;
import io.netty.channel.ChannelPromise;
/**
*
* @author Nikita Koksharov
*
*/
public class QueueCommandHolder {
final AtomicBoolean sended = new AtomicBoolean();
final AtomicBoolean sent = new AtomicBoolean();
final ChannelPromise channelPromise;
final QueueCommand command;
@ -40,7 +45,7 @@ public class QueueCommandHolder {
}
public boolean trySend() {
return sended.compareAndSet(false, true);
return sent.compareAndSet(false, true);
}
@Override

@ -36,7 +36,7 @@ import org.redisson.client.protocol.convertor.DoubleNullSafeReplayConvertor;
import org.redisson.client.protocol.convertor.DoubleReplayConvertor;
import org.redisson.client.protocol.convertor.IntegerReplayConvertor;
import org.redisson.client.protocol.convertor.KeyValueConvertor;
import org.redisson.client.protocol.convertor.LongListObjectDecoder;
import org.redisson.client.protocol.convertor.TimeObjectDecoder;
import org.redisson.client.protocol.convertor.LongReplayConvertor;
import org.redisson.client.protocol.convertor.TrueReplayConvertor;
import org.redisson.client.protocol.convertor.TypeConvertor;
@ -319,7 +319,7 @@ public interface RedisCommands {
RedisStrictCommand<List<ClusterNodeInfo>> CLUSTER_NODES = new RedisStrictCommand<List<ClusterNodeInfo>>("CLUSTER", "NODES", new ClusterNodesDecoder(false));
RedisStrictCommand<List<ClusterNodeInfo>> CLUSTER_NODES_SSL = new RedisStrictCommand<List<ClusterNodeInfo>>("CLUSTER", "NODES", new ClusterNodesDecoder(true));
RedisCommand<Object> TIME = new RedisCommand<Object>("TIME", new LongListObjectDecoder());
RedisStrictCommand<Time> TIME = new RedisStrictCommand<Time>("TIME", new TimeObjectDecoder());
RedisStrictCommand<Map<String, String>> CLUSTER_INFO = new RedisStrictCommand<Map<String, String>>("CLUSTER", "INFO", new StringMapDataDecoder());
RedisStrictCommand<List<String>> SENTINEL_GET_MASTER_ADDR_BY_NAME = new RedisStrictCommand<List<String>>("SENTINEL", "GET-MASTER-ADDR-BY-NAME", new StringListReplayDecoder());

@ -15,6 +15,12 @@
*/
package org.redisson.client.protocol;
/**
*
* @author Nikita Koksharov
*
* @param <V> value type
*/
public class ScoredEntry<V> {
private final Double score;

@ -0,0 +1,67 @@
/**
* Copyright 2018 Nikita Koksharov
*
* 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.protocol;
/**
*
* @author Nikita Koksharov
*
*/
public class Time {
private final int seconds;
private final int microseconds;
public Time(int seconds, int microseconds) {
super();
this.seconds = seconds;
this.microseconds = microseconds;
}
public int getMicroseconds() {
return microseconds;
}
public int getSeconds() {
return seconds;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + microseconds;
result = prime * result + seconds;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Time other = (Time) obj;
if (microseconds != other.microseconds)
return false;
if (seconds != other.seconds)
return false;
return true;
}
}

@ -18,7 +18,9 @@ package org.redisson.client.protocol.convertor;
import java.util.List;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.decoder.ListFirstObjectDecoder;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.Time;
import org.redisson.client.protocol.decoder.MultiDecoder;
/**
*
@ -26,15 +28,17 @@ import org.redisson.client.protocol.decoder.ListFirstObjectDecoder;
*
*/
public class LongListObjectDecoder extends ListFirstObjectDecoder {
public class TimeObjectDecoder implements MultiDecoder<Time> {
@Override
public Object decode(List<Object> parts, State state) {
Object result = super.decode(parts, state);
if (result != null) {
return Long.valueOf(result.toString());
public Decoder<Object> getDecoder(int paramNum, State state) {
// TODO Auto-generated method stub
return null;
}
return result;
@Override
public Time decode(List<Object> parts, State state) {
return new Time(((Long)parts.get(0)).intValue(), ((Long)parts.get(1)).intValue());
}
}

@ -22,8 +22,10 @@ import org.redisson.api.ClusterNode;
import org.redisson.api.NodeType;
import org.redisson.api.RFuture;
import org.redisson.client.RedisClient;
import org.redisson.client.codec.LongCodec;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.Time;
import org.redisson.command.CommandSyncService;
/**
@ -93,12 +95,12 @@ public class RedisClientEntry implements ClusterNode {
}
@Override
public RFuture<Long> timeAsync() {
return commandExecutor.readAsync(client, StringCodec.INSTANCE, RedisCommands.TIME);
public RFuture<Time> timeAsync() {
return commandExecutor.readAsync(client, LongCodec.INSTANCE, RedisCommands.TIME);
}
@Override
public long time() {
public Time time() {
return commandExecutor.get(timeAsync());
}

@ -44,6 +44,7 @@ import org.redisson.client.RedisConnectionException;
import org.redisson.client.RedisOutOfMemoryException;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.Time;
import org.redisson.client.protocol.decoder.ListScanResult;
import org.redisson.client.protocol.decoder.ScanObjectEntry;
import org.redisson.cluster.ClusterNodeInfo;
@ -555,7 +556,10 @@ public class RedissonTest {
Iterator<Node> iter = nodes.getNodes().iterator();
Node node1 = iter.next();
assertThat(node1.time()).isGreaterThan(100000L);
Time time = node1.time();
assertThat(time.getSeconds()).isGreaterThan(time.getMicroseconds());
assertThat(time.getSeconds()).isGreaterThan(1000000000);
assertThat(time.getMicroseconds()).isGreaterThan(10000);
}
@Test

Loading…
Cancel
Save