本文整理汇总了Java中com.lambdaworks.redis.api.sync.RedisCommands类的典型用法代码示例。如果您正苦于以下问题:Java RedisCommands类的具体用法?Java RedisCommands怎么用?Java RedisCommands使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RedisCommands类属于com.lambdaworks.redis.api.sync包,在下文中一共展示了RedisCommands类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: commandIsExecutedOnce
import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void commandIsExecutedOnce() {
RedisCommands<String, String> connection = client.connect().sync();
connection.set(key, "1");
connection.incr(key);
assertThat(connection.get(key)).isEqualTo("2");
connection.incr(key);
assertThat(connection.get(key)).isEqualTo("3");
connection.incr(key);
assertThat(connection.get(key)).isEqualTo("4");
connection.close();
}
示例2: commandFailsDuringDecode
import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void commandFailsDuringDecode() {
RedisCommands<String, String> connection = client.connect().sync();
RedisChannelWriter<String, String> channelWriter = getRedisChannelHandler(connection).getChannelWriter();
RedisCommands<String, String> verificationConnection = client.connect().sync();
connection.set(key, "1");
AsyncCommand<String, String, String> command = new AsyncCommand<>(new Command<>(CommandType.INCR, new StatusOutput<>(
CODEC), new CommandArgs<>(CODEC).addKey(key)));
channelWriter.write(command);
assertThat(command.await(2, TimeUnit.SECONDS)).isTrue();
assertThat(command.isCancelled()).isFalse();
assertThat(getException(command)).isInstanceOf(IllegalStateException.class);
assertThat(verificationConnection.get(key)).isEqualTo("2");
assertThat(connection.get(key)).isEqualTo("2");
connection.close();
}
示例3: commandIsExecutedOnce
import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void commandIsExecutedOnce() throws Exception {
RedisCommands<String, String> connection = client.connect().sync();
connection.set(key, "1");
connection.incr(key);
assertThat(connection.get(key)).isEqualTo("2");
connection.incr(key);
assertThat(connection.get(key)).isEqualTo("3");
connection.incr(key);
assertThat(connection.get(key)).isEqualTo("4");
connection.close();
}
示例4: commandFailsDuringDecode
import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void commandFailsDuringDecode() throws Exception {
RedisCommands<String, String> connection = client.connect().sync();
RedisChannelWriter<String, String> channelWriter = getRedisChannelHandler(connection).getChannelWriter();
RedisCommands<String, String> verificationConnection = client.connect().sync();
connection.set(key, "1");
AsyncCommand<String, String, String> command = new AsyncCommand(new Command<>(CommandType.INCR, new StatusOutput<>(
CODEC), new CommandArgs<>(CODEC).addKey(key)));
channelWriter.write(command);
assertThat(command.await(2, TimeUnit.SECONDS)).isTrue();
assertThat(command.isCancelled()).isFalse();
assertThat(command.isDone()).isTrue();
assertThat(getException(command)).isInstanceOf(IllegalStateException.class);
assertThat(verificationConnection.get(key)).isEqualTo("2");
assertThat(connection.get(key)).isEqualTo("2");
connection.close();
verificationConnection.close();
}
示例5: hasMaster
import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
/**
* Check if a master runs on any of the given ports.
*
* @param redisPorts
* @return
*/
public boolean hasMaster(int... redisPorts) {
Map<Integer, RedisCommands<String, String>> connections = new HashMap<>();
for (int redisPort : redisPorts) {
connections.put(redisPort,
redisClient.connect(RedisURI.Builder.redis(TestSettings.hostAddr(), redisPort).build()).sync());
}
try {
Integer masterPort = getMasterPort(connections);
if (masterPort != null) {
return true;
}
} finally {
for (RedisCommands<String, String> commands : connections.values()) {
commands.close();
}
}
return false;
}
示例6: genericPoolUsingWrappingShouldPropagateExceptionsCorrectly
import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void genericPoolUsingWrappingShouldPropagateExceptionsCorrectly() throws Exception {
GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
() -> client.connect(), new GenericObjectPoolConfig());
StatefulRedisConnection<String, String> connection = pool.borrowObject();
RedisCommands<String, String> sync = connection.sync();
sync.set(key, value);
try {
sync.hgetall(key);
fail("Missing RedisCommandExecutionException");
} catch (RedisCommandExecutionException e) {
assertThat(e).hasMessageContaining("WRONGTYPE");
}
sync.close();
pool.close();
}
示例7: wrappedConnectionShouldUseWrappers
import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void wrappedConnectionShouldUseWrappers() throws Exception {
GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
() -> client.connect(), new GenericObjectPoolConfig());
StatefulRedisConnection<String, String> connection = pool.borrowObject();
RedisCommands<String, String> sync = connection.sync();
assertThat(connection).isInstanceOf(StatefulRedisConnection.class).isNotInstanceOf(
StatefulRedisClusterConnectionImpl.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();
}
示例8: wrappedMasterSlaveConnectionShouldUseWrappers
import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的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();
}
示例9: plainConnectionShouldNotUseWrappers
import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void plainConnectionShouldNotUseWrappers() throws Exception {
GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
() -> client.connect(), new GenericObjectPoolConfig(), false);
StatefulRedisConnection<String, String> connection = pool.borrowObject();
RedisCommands<String, String> sync = connection.sync();
assertThat(connection).isInstanceOf(StatefulRedisConnection.class).isNotInstanceOf(
StatefulRedisClusterConnectionImpl.class);
assertThat(Proxy.isProxyClass(connection.getClass())).isFalse();
assertThat(sync).isInstanceOf(RedisCommands.class);
assertThat(connection.async()).isInstanceOf(RedisAsyncCommands.class).isInstanceOf(RedisAsyncCommandsImpl.class);
assertThat(connection.reactive()).isInstanceOf(RedisReactiveCommands.class).isInstanceOf(
RedisReactiveCommandsImpl.class);
assertThat(sync.getStatefulConnection()).isInstanceOf(StatefulRedisConnection.class).isInstanceOf(
StatefulRedisConnectionImpl.class);
pool.returnObject(connection);
pool.close();
}
示例10: wrappedObjectClosedAfterReturn
import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的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();
}
示例11: tryWithResourcesReturnsConnectionToPool
import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void tryWithResourcesReturnsConnectionToPool() throws Exception {
GenericObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport.createGenericObjectPool(
() -> client.connect(), new GenericObjectPoolConfig());
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();
}
示例12: tryWithResourcesReturnsSoftRefConnectionToPool
import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的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();
}
示例13: testPooling
import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void testPooling() throws Exception {
final RedisConnectionPool<RedisCommands<String, String>> pool = client.pool();
assertThat(pool.getNumActive()).isEqualTo(0);
assertThat(pool.getNumIdle()).isEqualTo(0);
new WithConnection<RedisCommands<String, String>>(pool) {
@Override
protected void run(RedisCommands<String, String> connection) {
connection.set("key", "value");
String result = connection.get("key");
assertThat(result).isEqualTo("value");
assertThat(pool.getNumActive()).isEqualTo(1);
assertThat(pool.getNumIdle()).isEqualTo(0);
}
};
assertThat(pool.getNumActive()).isEqualTo(0);
assertThat(pool.getNumIdle()).isEqualTo(1);
}
示例14: testPoolingWithException
import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void testPoolingWithException() throws Exception {
final RedisConnectionPool<RedisCommands<String, String>> pool = client.pool();
assertThat(pool.getNumActive()).isEqualTo(0);
assertThat(pool.getNumIdle()).isEqualTo(0);
try {
new WithConnection<RedisCommands<String, String>>(pool) {
@Override
protected void run(RedisCommands<String, String> connection) {
connection.set("key", "value");
throw new IllegalStateException("test");
}
};
fail("Missing Exception");
} catch (Exception e) {
}
assertThat(pool.getNumActive()).isEqualTo(0);
assertThat(pool.getNumIdle()).isEqualTo(1);
}
示例15: pingBeforeConnectWithAuthentication
import com.lambdaworks.redis.api.sync.RedisCommands; //导入依赖的package包/类
@Test
public void pingBeforeConnectWithAuthentication() {
new WithPasswordRequired() {
@Override
protected void run(RedisClient client) {
client.setOptions(ClientOptions.builder().pingBeforeActivateConnection(true).build());
RedisURI redisURI = RedisURI.Builder.redis(host, port).withPassword(passwd).build();
RedisCommands<String, String> connection = client.connect(redisURI).sync();
try {
String result = connection.info();
assertThat(result).contains("memory");
} finally {
connection.close();
}
}
};
}