本文整理汇总了Java中com.lambdaworks.redis.RedisException类的典型用法代码示例。如果您正苦于以下问题:Java RedisException类的具体用法?Java RedisException怎么用?Java RedisException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RedisException类属于com.lambdaworks.redis包,在下文中一共展示了RedisException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newScriptOutput
import com.lambdaworks.redis.RedisException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected <T> CommandOutput<K, V, T> newScriptOutput(RedisCodec<K, V> codec, ScriptOutputType type) {
switch (type) {
case BOOLEAN:
return (CommandOutput<K, V, T>) new BooleanOutput<>(codec);
case INTEGER:
return (CommandOutput<K, V, T>) new IntegerOutput<>(codec);
case STATUS:
return (CommandOutput<K, V, T>) new StatusOutput<>(codec);
case MULTI:
return (CommandOutput<K, V, T>) new NestedMultiOutput<>(codec);
case VALUE:
return (CommandOutput<K, V, T>) new ValueOutput<>(codec);
default:
throw new RedisException("Unsupported script output type");
}
}
示例2: handleInvocation
import com.lambdaworks.redis.RedisException; //导入依赖的package包/类
@Override
protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
if (pool == null) {
throw new RedisException("Connection pool is closed");
}
if (method.getName().equals("close")) {
pool.close();
pool = null;
return null;
}
T connection = pool.allocateConnection();
try {
return method.invoke(connection, args);
} finally {
pool.freeConnection(connection);
}
}
示例3: testCreate
import com.lambdaworks.redis.RedisException; //导入依赖的package包/类
@Test
public void testCreate() throws Exception {
RedisConnection<String, String> connection = PoolingProxyFactory.create(client.pool());
connection.set("a", "b");
connection.close();
try {
connection.set("x", "y");
fail("missing exception");
} catch (RedisException e) {
assertThat(e.getMessage()).isEqualTo("Connection pool is closed");
}
}
示例4: closeWithQueuedCommandsFails
import com.lambdaworks.redis.RedisException; //导入依赖的package包/类
@Test
public void closeWithQueuedCommandsFails() throws Exception {
when(clientOptions.isAutoReconnect()).thenReturn(true);
queue.add(command);
when(clusterChannelWriter.write(any())).thenThrow(new RedisException("meh"));
sut.close();
assertThat(command.isDone()).isTrue();
try {
command.get();
fail("Expected ExecutionException");
} catch (ExecutionException e) {
assertThat(e).hasCauseExactlyInstanceOf(RedisException.class);
}
}
示例5: closeWithBufferedCommandsFails
import com.lambdaworks.redis.RedisException; //导入依赖的package包/类
@Test
public void closeWithBufferedCommandsFails() throws Exception {
when(clientOptions.isAutoReconnect()).thenReturn(true);
when(clientOptions.getRequestQueueSize()).thenReturn(1000);
when(clientOptions.getDisconnectedBehavior()).thenReturn(ClientOptions.DisconnectedBehavior.ACCEPT_COMMANDS);
sut = new ClusterNodeCommandHandler(clientOptions, clientResources, clusterChannelWriter);
sut.write(command);
when(clusterChannelWriter.write(any())).thenThrow(new RedisException(""));
sut.close();
try {
command.get();
fail("Expected ExecutionException");
} catch (ExecutionException e) {
assertThat(e).hasCauseExactlyInstanceOf(RedisException.class);
}
}
示例6: shouldFailIfNoNodeConnects
import com.lambdaworks.redis.RedisException; //导入依赖的package包/类
@Test
public void shouldFailIfNoNodeConnects() throws Exception {
List<RedisURI> seed = Arrays.asList(RedisURI.create("127.0.0.1", 7380), RedisURI.create("127.0.0.1", 7381));
when(nodeConnectionFactory.connectToNodeAsync(any(RedisCodec.class), eq(new InetSocketAddress("127.0.0.1", 7380))))
.thenReturn(completedWithException(new RedisException("connection failed")));
when(nodeConnectionFactory.connectToNodeAsync(any(RedisCodec.class), eq(new InetSocketAddress("127.0.0.1", 7381))))
.thenReturn(completedWithException(new RedisException("connection failed")));
try {
sut.loadViews(seed, true);
fail("Missing RedisConnectionException");
} catch (Exception e) {
assertThat(e).hasNoCause().hasMessage("Unable to establish a connection to Redis Cluster");
assertThat(e.getSuppressed()).hasSize(2);
}
verify(nodeConnectionFactory).connectToNodeAsync(any(RedisCodec.class), eq(new InetSocketAddress("127.0.0.1", 7380)));
verify(nodeConnectionFactory).connectToNodeAsync(any(RedisCodec.class), eq(new InetSocketAddress("127.0.0.1", 7381)));
}
示例7: parse
import com.lambdaworks.redis.RedisException; //导入依赖的package包/类
/**
* Parse partition lines into Partitions object.
*
* @param nodes output of CLUSTER NODES
* @return the partitions object.
*/
public static Collection<DisqueNode> parse(String nodes) {
List<DisqueNode> result = new ArrayList<>();
Iterator<String> iterator = TOKEN_PATTERN.splitAsStream(nodes).iterator();
try {
while (iterator.hasNext()) {
String node = iterator.next();
DisqueNode partition = parseNode(node);
result.add(partition);
}
} catch (Exception e) {
throw new RedisException("Cannot parse " + nodes, e);
}
return result;
}
示例8: auth
import com.lambdaworks.redis.RedisException; //导入依赖的package包/类
@Test
public void auth() throws Exception {
new WithPasswordRequired() {
@Override
protected void run(DisqueClient client) throws Exception {
DisqueCommands<String, String> connection = client.connect().sync();
try {
connection.ping();
fail("Server doesn't require authentication");
} catch (RedisException e) {
assertThat(e.getMessage()).isEqualTo("NOAUTH Authentication required.");
assertThat(connection.auth(passwd)).isEqualTo("OK");
assertThat(connection.ping()).isEqualTo("PONG");
}
DisqueURI disqueURI = DisqueURI.create("disque://" + passwd + "@" + TestSettings.host() + ":"
+ TestSettings.port());
DisqueClient disqueClient = DisqueClient.create(disqueURI);
DisqueCommands<String, String> authConnection = disqueClient.connect().sync();
authConnection.ping();
authConnection.close();
disqueClient.shutdown(100, 100, TimeUnit.MILLISECONDS);
}
};
}
示例9: readReplyType
import com.lambdaworks.redis.RedisException; //导入依赖的package包/类
private State.Type readReplyType(ByteBuf buffer) {
byte b = buffer.readByte();
switch (b) {
case '+':
return SINGLE;
case '-':
return ERROR;
case ':':
return INTEGER;
case '$':
return BULK;
case '*':
return MULTI;
default:
throw new RedisException("Invalid first byte: " + Byte.toString(b));
}
}
示例10: clusterLeaving
import com.lambdaworks.redis.RedisException; //导入依赖的package包/类
@Test
public void clusterLeaving() throws Exception {
assertThat(disque.clusterLeaving()).isEqualTo("no");
assertThat(disque.clusterLeaving(true)).isEqualTo("OK");
assertThat(disque.clusterLeaving()).isEqualTo("yes");
try {
disque.getjob(queue);
fail("Missing exception");
}catch (RedisException e) {
assertThat(e).hasMessageStartingWith("LEAVING");
}
assertThat(disque.clusterLeaving(false)).isEqualTo("OK");
}
示例11: getMaster
import com.lambdaworks.redis.RedisException; //导入依赖的package包/类
public RedisNodeDescription getMaster() {
for (RedisNodeDescription knownNode : knownNodes) {
if (knownNode.getRole() == RedisInstance.Role.MASTER) {
return knownNode;
}
}
throw new RedisException(String.format("Master is currently unknown: %s", knownNodes));
}
示例12: write
import com.lambdaworks.redis.RedisException; //导入依赖的package包/类
@Override
public <T, C extends RedisCommand<K, V, T>> C write(C command) {
LettuceAssert.notNull(command, "Command must not be null");
if (closed) {
throw new RedisException("Connection is closed");
}
MasterSlaveConnectionProvider.Intent intent = getIntent(command.getType());
StatefulRedisConnection<K, V> connection = masterSlaveConnectionProvider.getConnection(intent);
return connection.dispatch(command);
}
示例13: getNodes
import com.lambdaworks.redis.RedisException; //导入依赖的package包/类
@Override
public List<RedisNodeDescription> getNodes() {
logger.debug("Performing topology lookup");
String info = connection.sync().info("replication");
try {
return getNodesFromInfo(info);
} catch (RuntimeException e) {
throw new RedisException(e);
}
}
示例14: handleInvocation
import com.lambdaworks.redis.RedisException; //导入依赖的package包/类
@Override
protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getName().equals("getStatefulConnection")) {
return proxiedConnection;
}
if (method.getName().equals("getTargetConnection")) {
return connection;
}
if (connection == null) {
throw new RedisException("Connection is deallocated and cannot be used anymore.");
}
if (method.getName().equals("close")) {
pool.returnObject(proxiedConnection);
connection = null;
proxiedConnection = null;
connectionProxies.clear();
return null;
}
try {
if (method.getName().equals("sync") || method.getName().equals("async") || method.getName().equals("reactive")) {
return connectionProxies.computeIfAbsent(method, m -> getInnerProxy(method, args));
}
return method.invoke(connection, args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
示例15: parse
import com.lambdaworks.redis.RedisException; //导入依赖的package包/类
/**
* Parse partition lines into Partitions object.
*
* @param nodes output of CLUSTER NODES
* @return the partitions object.
*/
public static Partitions parse(String nodes) {
Partitions result = new Partitions();
try {
List<RedisClusterNode> mappedNodes = TOKEN_PATTERN.splitAsStream(nodes).filter(s -> !s.isEmpty())
.map(ClusterPartitionParser::parseNode)
.collect(Collectors.toList());
result.addAll(mappedNodes);
} catch (Exception e) {
throw new RedisException("Cannot parse " + nodes, e);
}
return result;
}