• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java StatefulRedisConnection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.lambdaworks.redis.api.StatefulRedisConnection的典型用法代码示例。如果您正苦于以下问题:Java StatefulRedisConnection类的具体用法?Java StatefulRedisConnection怎么用?Java StatefulRedisConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



StatefulRedisConnection类属于com.lambdaworks.redis.api包,在下文中一共展示了StatefulRedisConnection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: connect

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
/**
 * Connects to the Redis server.
 * @param configuration The configuration object.
 * @throws Exception If an error occurs.
 */
public void connect(Configuration configuration) throws Exception {
    if(sync != null) {
        return;
    }
    RedisURI.Builder uri = RedisURI.Builder.redis(configuration.getRedisHost(), configuration.getRedisPort())
            .withDatabase(configuration.getRedisIndex());
    if(!configuration.getRedisAuth().isEmpty()) {
        uri.withPassword(configuration.getRedisAuth());
    }
    RedisClient client = RedisClient.create(uri.build());
    StatefulRedisConnection<String, String> connection = client.connect();
    sync = connection.sync();
    for(Category category : Category.values()) {
        logger.info("Registered the category {} with the type {}.", category, category.getEntry().getType());
        category.getEntry().setCategory(category);
    }
}
 
开发者ID:Arraying,项目名称:Arraybot,代码行数:23,代码来源:Redis.java


示例2: insertionRemoval

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
@Test
public void insertionRemoval() throws NumberFormatException, InterruptedException, ExecutionException {
	RedisClient redis = RedisClient.create("redis://127.0.0.1:6379");
	StatefulRedisConnection<String, String> redisConn = redis.connect();
	RedisAsyncCommands<String, String> redisCmd = redisConn.async();
	
	long iterations = 1000;
	
	for (long i = 0; i < iterations; i++) {
		redisCmd.set(String.valueOf(i), String.valueOf(i + 1));
	}
	
	for (long i = 0; i < iterations; i++) {
		long v = Long.valueOf(redisCmd.get(String.valueOf(i)).get());
		assertEquals(i + 1, v);
	}
	
	for (long i = 0; i < iterations; i++) {
		redisCmd.del(String.valueOf(i));
	}
	
	redisConn.close();
	redis.shutdown();
}
 
开发者ID:3Cores,项目名称:sostream,代码行数:25,代码来源:TestRedisLettuce.java


示例3: ping

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
public void ping(final PingCallback callback) {
    Consumer<StatefulRedisConnection> connectionConsumer = new Consumer<StatefulRedisConnection>() {
        @Override
        public void accept(StatefulRedisConnection statefulRedisConnection) {
            final CompletableFuture<String> future = statefulRedisConnection.async().ping().toCompletableFuture();

            future.whenCompleteAsync((pong, th) -> {
                if(th != null){
                    callback.fail(th);
                }else{
                    callback.pong(pong);
                }
            }, executors);
        }
    };
    Consumer<Throwable> throwableConsumer = new Consumer<Throwable>() {
        @Override
        public void accept(Throwable e) {
            callback.fail(e);
            log.error("[ping]" + hostPort, e);
        }
    };
    asyncExecute(connectionConsumer, throwableConsumer);
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:25,代码来源:RedisSession.java


示例4: role

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
public void role(RollCallback callback) {
    Consumer<StatefulRedisConnection> connectionConsumer = new Consumer<StatefulRedisConnection>() {
        @Override
        public void accept(StatefulRedisConnection statefulRedisConnection) {
            final CompletableFuture<List<Object>> future = statefulRedisConnection.async().role().toCompletableFuture();

            future.whenCompleteAsync((role, th) -> {
                if (th != null) {
                    callback.fail(th);
                } else {
                    callback.role((String) role.get(0));
                }
            }, executors);
        }
    };
    asyncExecute(connectionConsumer, null);
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:18,代码来源:RedisSession.java


示例5: serverInfo

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
public void serverInfo(Callbackable<String> callback) {
    String serverInfoSection = "server";
    Consumer<StatefulRedisConnection> connectionConsumer = (connection) -> {
        CompletableFuture<String> future = connection.async().info(serverInfoSection).toCompletableFuture();
        future.whenCompleteAsync((info, th) -> {
            if(th != null){
                log.error("[info]{}", hostPort, th);
                callback.fail(th);
            }else{
                callback.success(info);
            }
        }, executors);
    };

    Consumer<Throwable> throwableConsumer = (throwable) -> {
        callback.fail(throwable);
        log.error("[info]{}", hostPort, throwable);
    };

    asyncExecute(connectionConsumer, throwableConsumer);
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:22,代码来源:RedisSession.java


示例6: conf

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
public void conf(String confSection, Callbackable<List<String>> callback) {
    Consumer<StatefulRedisConnection> connectionConsumer = (connection) -> {
        CompletableFuture<List<String>> future = connection.async().configGet(confSection).toCompletableFuture();
        future.whenCompleteAsync((conf, throwable) -> {
            if(throwable != null) {
                log.error("[conf]Executing conf command error", throwable);
                callback.fail(throwable);
            } else {
                callback.success(conf);
            }
        });
    };

    Consumer<Throwable> throwableConsumer = (throwable) -> {
        callback.fail(throwable);
        log.error("[conf]{}", hostPort, throwable);
    };

    asyncExecute(connectionConsumer, throwableConsumer);
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:21,代码来源:RedisSession.java


示例7: publish

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
@SuppressWarnings("unused")
private void publish() {

	scheduled.scheduleAtFixedRate(new AbstractExceptionLogTask() {

		StatefulRedisConnection<String, String> redisConnection;
		private RedisClient redisClient;
		{
			redisClient = RedisClient.create(clientResources, redisURI);
		}

		@Override
		public void doRun() {

			if (redisConnection == null) {
				redisConnection = redisClient.connect();
			}

			logger.info("[run][publish]{}", channel);
			redisConnection.async().publish(channel, randomString(10));

		}
	}, 0, 5, TimeUnit.SECONDS);
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:25,代码来源:LettuceTest.java


示例8: getConnection

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
protected StatefulRedisConnection<String, String> getConnection()
{
    if (connection == null) {
        synchronized (syncObject)
        {
            if (connection == null)
            {
                Logging.write("$");
                RedisClient client = getRedisClient();
                connection = client.connect();
                TrySetClientName();
            }
        }
    }

    return connection;
}
 
开发者ID:JonCole,项目名称:SampleCode,代码行数:18,代码来源:LettuceRedisClient.java


示例9: handleInvocation

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {

    try {

        Method targetMethod = methodCache.get(method);
        Object result = targetMethod.invoke(asyncApi, args);

        if (result instanceof RedisFuture) {
            RedisFuture<?> command = (RedisFuture<?>) result;
            if (!method.getName().equals("exec") && !method.getName().equals("multi")) {
                if (connection instanceof StatefulRedisConnection && ((StatefulRedisConnection) connection).isMulti()) {
                    return null;
                }
            }

            LettuceFutures.awaitOrCancel(command, connection.getTimeout(), connection.getTimeoutUnit());
            return command.get();
        }
        return result;
    } catch (InvocationTargetException e) {
        throw e.getTargetException();
    }

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


示例10: regularClientFailsOnFirstCommandWithDelay

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
@Test
public void regularClientFailsOnFirstCommandWithDelay() {

    try (StatefulRedisConnection<String, String> connect = client.connect()) {

        Wait.untilEquals(false, connect::isOpen).waitOrTimeout();

        connect.sync().ping();
    } catch (RedisException e) {
        if (e.getCause() instanceof IOException) {
            assertThat(e).hasCauseInstanceOf(IOException.class);
        } else {
            assertThat(e.getCause()).hasMessageContaining("DENIED");
        }
    }
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:17,代码来源:ProtectedModeTests.java


示例11: connectStandaloneAsync

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
private <K, V> ConnectionFuture<StatefulRedisConnection<K, V>> connectStandaloneAsync(RedisCodec<K, V> codec,
        RedisURI redisURI, Timeout timeout) {

    assertNotNull(codec);
    checkValidRedisURI(redisURI);

    logger.debug("Trying to get a Redis connection for: " + redisURI);

    CommandHandler<K, V> handler = new CommandHandler<>(clientOptions, clientResources);

    StatefulRedisConnectionImpl<K, V> connection = newStatefulRedisConnection(handler, codec, timeout.timeout,
            timeout.timeUnit);
    ConnectionFuture<StatefulRedisConnection<K, V>> future = connectStatefulAsync(handler, connection, redisURI);

    future.whenComplete((channelHandler, throwable) -> {

        if (throwable != null) {
            connection.close();
        }
    });

    return future;
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:24,代码来源:RedisClient.java


示例12: closeStaleConnections

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
/**
 * Close stale connections.
 */
public void closeStaleConnections() {
    logger.debug("closeStaleConnections() count before expiring: {}", getConnectionCount());

    Set<ConnectionKey> stale = getStaleConnectionKeys();

    for (ConnectionKey connectionKey : stale) {
        StatefulRedisConnection<K, V> connection = connections.get(connectionKey);
        if (connection != null) {
            connections.remove(connectionKey);
            connection.close();
        }
    }

    logger.debug("closeStaleConnections() count after expiring: {}", getConnectionCount());
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:19,代码来源:MasterSlaveConnectionProvider.java


示例13: tryWithResourcesReturnsSoftRefConnectionToPool

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
@Test
public void tryWithResourcesReturnsSoftRefConnectionToPool() throws Exception {

    SoftReferenceObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport
            .createSoftReferenceObjectPool(() -> client.connect());

    StatefulRedisConnection<String, String> usedConnection = null;
    try (StatefulRedisConnection<String, String> connection = pool.borrowObject()) {

        RedisCommands<String, String> sync = connection.sync();
        sync.ping();

        usedConnection = connection;
    }

    try {
        usedConnection.isMulti();
        fail("Missing RedisException");
    } catch (RedisException e) {
        assertThat(e).hasMessageContaining("deallocated");
    }

    pool.close();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:25,代码来源:ConnectionPoolSupportTest.java


示例14: call

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
@Override
public void call(Subscriber<? super T> subscriber) {

    // Reuse the first command but then discard it.
    RedisCommand<K, V, T> command = this.command;
    if (command == null) {
        command = commandSupplier.get();
    }

    if (command.getOutput() instanceof StreamingOutput<?>) {
        StreamingOutput<T> streamingOutput = (StreamingOutput<T>) command.getOutput();

        if (connection instanceof StatefulRedisConnection<?, ?> && ((StatefulRedisConnection) connection).isMulti()) {
            streamingOutput.setSubscriber(new DelegatingWrapper<>(new ObservableSubscriberWrapper<>(subscriber),
                    streamingOutput.getSubscriber()));
        } else {
            streamingOutput.setSubscriber(new ObservableSubscriberWrapper<>(subscriber));
        }
    }

    connection.dispatch(new ObservableCommand<>(command, subscriber, dissolve));

    this.command = null;

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


示例15: shouldRetrieveTopology

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
@Test
public void shouldRetrieveTopology() {

    MasterSlaveTopologyRefresh refresh = new MasterSlaveTopologyRefresh(connectionFactory, provider);

    CompletableFuture<StatefulRedisConnection<String, String>> master = CompletableFuture.completedFuture(connection);
    CompletableFuture<StatefulRedisConnection<String, String>> slave = CompletableFuture.completedFuture(connection);
    when(connectionFactory.connectToNodeAsync(any(), any())).thenReturn((CompletableFuture) master,
            (CompletableFuture) slave);

    RedisURI redisURI = new RedisURI();
    redisURI.setTimeout(1);
    redisURI.setUnit(TimeUnit.MILLISECONDS);

    List<RedisNodeDescription> nodes = refresh.getNodes(redisURI);

    assertThat(nodes).hasSize(2);
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:19,代码来源:MasterSlaveTopologyRefreshTest.java


示例16: wrappedMasterSlaveConnectionShouldUseWrappers

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
@Test
public void wrappedMasterSlaveConnectionShouldUseWrappers() throws Exception {

    GenericObjectPool<StatefulRedisMasterSlaveConnection<String, String>> pool = ConnectionPoolSupport
            .createGenericObjectPool(() -> MasterSlave.connect(client, new StringCodec(), RedisURI.create(host, port)),
                    new GenericObjectPoolConfig());

    StatefulRedisMasterSlaveConnection<String, String> connection = pool.borrowObject();
    RedisCommands<String, String> sync = connection.sync();

    assertThat(connection).isInstanceOf(StatefulRedisMasterSlaveConnection.class);
    assertThat(Proxy.isProxyClass(connection.getClass())).isTrue();

    assertThat(sync).isInstanceOf(RedisCommands.class);
    assertThat(connection.async()).isInstanceOf(RedisAsyncCommands.class).isNotInstanceOf(RedisAsyncCommandsImpl.class);
    assertThat(connection.reactive()).isInstanceOf(RedisReactiveCommands.class).isNotInstanceOf(
            RedisReactiveCommandsImpl.class);
    assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisConnection.class)
            .isNotInstanceOf(StatefulRedisConnectionImpl.class).isSameAs(connection);

    sync.close();
    pool.close();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:24,代码来源:ConnectionPoolSupportTest.java


示例17: operateOnNodeConnection

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
@Test
public void operateOnNodeConnection() {

    sync.set(KEY_A, value);
    sync.set(KEY_B, "d");

    StatefulRedisConnection<String, String> statefulRedisConnection = sync.getStatefulConnection().getConnection(
            TestSettings.hostAddr(), port2);

    RedisClusterCommands<String, String> connection = statefulRedisConnection.sync();

    assertThat(connection.get(KEY_A)).isEqualTo(value);
    try {
        connection.get(KEY_B);
        fail("missing RedisCommandExecutionException: MOVED");
    } catch (RedisException e) {
        assertThat(e).hasMessageContaining("MOVED");
    }
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:20,代码来源:RedisClusterClientTest.java


示例18: authInvalidPassword

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void authInvalidPassword() throws Exception {
    RedisAsyncConnection<String, String> async = client.connectAsync();
    try {
        async.auth("invalid");
        fail("Authenticated with invalid password");
    } catch (RedisException e) {
        assertThat(e.getMessage()).isEqualTo("ERR Client sent AUTH, but no password is set");
        StatefulRedisConnection<String, String> statefulRedisConnection = (StatefulRedisConnection<String, String>) ReflectionTestUtils
                .getField(async, "connection");
        assertThat(ReflectionTestUtils.getField(statefulRedisConnection, "password")).isNull();
    } finally {
        async.close();
    }
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:17,代码来源:ConnectionCommandTest.java


示例19: wrappedObjectClosedAfterReturn

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
@Test
public void wrappedObjectClosedAfterReturn() throws Exception {

    GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
            () -> client.connect(), new GenericObjectPoolConfig(), true);

    StatefulRedisConnection<String, String> connection = pool.borrowObject();
    RedisCommands<String, String> sync = connection.sync();
    sync.ping();
    sync.close();

    try {
        connection.isMulti();
        fail("Missing RedisException");
    } catch (RedisException e) {
        assertThat(e).hasMessageContaining("deallocated");
    }

    pool.close();
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:21,代码来源:ConnectionPoolSupportTest.java


示例20: getConnections

import com.lambdaworks.redis.api.StatefulRedisConnection; //导入依赖的package包/类
private StatefulRedisConnection<K, V>[] getConnections(
        CompletableFuture<StatefulRedisConnection<K, V>>[] selectedReaderCandidates) {

    List<StatefulRedisConnection<K, V>> connections = new ArrayList<>(selectedReaderCandidates.length);

    for (CompletableFuture<StatefulRedisConnection<K, V>> candidate : selectedReaderCandidates) {

        try {
            connections.add(candidate.join());
        } catch (Exception o_O) {
        }
    }

    StatefulRedisConnection<K, V>[] result = new StatefulRedisConnection[connections.size()];
    connections.toArray(result);
    return result;
}
 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:18,代码来源:PooledClusterConnectionProvider.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ProgressListener类代码示例发布时间:2022-05-21
下一篇:
Java Base64Decoder类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap