当前位置: 首页>>代码示例>>Java>>正文


Java RedisException类代码示例

本文整理汇总了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");
    }
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:18,代码来源:BaseRedisCommandBuilder.java

示例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);
    }
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:21,代码来源:TransparentPoolingInvocationHandler.java

示例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");

    }
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:17,代码来源:PoolingProxyFactoryTest.java

示例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);
    }
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:20,代码来源:ClusterNodeCommandHandlerTest.java

示例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);
    }
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:21,代码来源:ClusterNodeCommandHandlerTest.java

示例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)));
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:22,代码来源:ClusterTopologyRefreshTest.java

示例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;
}
 
开发者ID:mp911de,项目名称:spinach,代码行数:25,代码来源:ClusterNodesParser.java

示例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);
        }

    };
}
 
开发者ID:mp911de,项目名称:spinach,代码行数:27,代码来源:BasicCommandTest.java

示例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));
    }
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:18,代码来源:RedisStateMachine.java

示例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");
}
 
开发者ID:mp911de,项目名称:spinach,代码行数:16,代码来源:ClusterCommandTest.java

示例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));
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:10,代码来源:MasterSlaveConnectionProvider.java

示例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);
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:15,代码来源:MasterSlaveChannelWriter.java

示例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);
    }
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:13,代码来源:MasterSlaveTopologyProvider.java

示例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();
    }
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:36,代码来源:ConnectionPoolSupport.java

示例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;
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:21,代码来源:ClusterPartitionParser.java


注:本文中的com.lambdaworks.redis.RedisException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。