本文整理汇总了Java中com.lambdaworks.redis.api.sync.RedisCommands.set方法的典型用法代码示例。如果您正苦于以下问题:Java RedisCommands.set方法的具体用法?Java RedisCommands.set怎么用?Java RedisCommands.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lambdaworks.redis.api.sync.RedisCommands
的用法示例。
在下文中一共展示了RedisCommands.set方法的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: 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);
}
示例4: 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();
}
示例5: 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();
}
示例6: testByteBufferCodec
import com.lambdaworks.redis.api.sync.RedisCommands; //导入方法依赖的package包/类
@Test
public void testByteBufferCodec() throws Exception {
RedisCommands<ByteBuffer, ByteBuffer> connection = client.connect(new ByteBufferCodec()).sync();
String value = "üöäü+#";
ByteBuffer wrap = ByteBuffer.wrap(value.getBytes());
connection.set(wrap, wrap);
List<ByteBuffer> keys = connection.keys(wrap);
assertThat(keys).hasSize(1);
ByteBuffer byteBuffer = keys.get(0);
byte[] bytes = new byte[byteBuffer.remaining()];
byteBuffer.get(bytes);
assertThat(bytes).isEqualTo(value.getBytes());
connection.close();
}
示例7: testGzipompressedJavaSerializer
import com.lambdaworks.redis.api.sync.RedisCommands; //导入方法依赖的package包/类
@Test
public void testGzipompressedJavaSerializer() throws Exception {
RedisCommands<String, Object> connection = client
.connect(CompressionCodec
.valueCompressor(new SerializedObjectCodec(), CompressionCodec.CompressionType.GZIP))
.sync();
List<String> list = list("one", "two");
connection.set(key, list);
assertThat(connection.get(key)).isEqualTo(list);
connection.close();
}
示例8: testMasterSlaveReadWrite
import com.lambdaworks.redis.api.sync.RedisCommands; //导入方法依赖的package包/类
@Test
public void testMasterSlaveReadWrite() throws Exception {
RedisCommands<String, String> redisCommands = connection.sync();
redisCommands.set(key, value);
redisCommands.waitForReplication(1, 100);
assertThat(redisCommands.get(key)).isEqualTo(value);
}
示例9: testConnectToSlave
import com.lambdaworks.redis.api.sync.RedisCommands; //导入方法依赖的package包/类
@Test
public void testConnectToSlave() throws Exception {
connection.close();
RedisURI slaveUri = RedisURI.Builder.redis(host, TestSettings.port(4)).withPassword(passwd).build();
connection = (StatefulRedisMasterSlaveConnectionImpl) MasterSlave.connect(client, new Utf8StringCodec(), slaveUri);
RedisCommands<String, String> sync = connection.sync();
sync.set(key, value);
}
示例10: commandNotExecutedFailsOnEncode
import com.lambdaworks.redis.api.sync.RedisCommands; //导入方法依赖的package包/类
@Test
public void commandNotExecutedFailsOnEncode() {
RedisCommands<String, String> connection = client.connect().sync();
RedisChannelWriter<String, String> channelWriter = getRedisChannelHandler(connection).getChannelWriter();
connection.set(key, "1");
AsyncCommand<String, String, String> working = new AsyncCommand<>(new Command<>(CommandType.INCR, new IntegerOutput(
CODEC), new CommandArgs<>(CODEC).addKey(key)));
channelWriter.write(working);
assertThat(working.await(2, TimeUnit.SECONDS)).isTrue();
assertThat(connection.get(key)).isEqualTo("2");
AsyncCommand<String, String, Object> command = new AsyncCommand<String, String, Object>(new Command<>(CommandType.INCR,
new IntegerOutput(CODEC), new CommandArgs<>(CODEC).addKey(key))) {
@Override
public void encode(ByteBuf buf) {
throw new IllegalStateException("I want to break free");
}
};
channelWriter.write(command);
assertThat(command.await(2, TimeUnit.SECONDS)).isTrue();
assertThat(command.isCancelled()).isFalse();
assertThat(getException(command)).isInstanceOf(EncoderException.class);
Wait.untilTrue(() -> !getStack(getRedisChannelHandler(connection)).isEmpty()).waitOrTimeout();
assertThat(getStack(getRedisChannelHandler(connection))).isNotEmpty();
getStack(getRedisChannelHandler(connection)).clear();
assertThat(connection.get(key)).isEqualTo("2");
assertThat(getDisconnectedBuffer(getRedisChannelHandler(connection))).isEmpty();
assertThat(getCommandBuffer(getRedisChannelHandler(connection))).isEmpty();
connection.close();
}
示例11: masterSlaveWithSsl
import com.lambdaworks.redis.api.sync.RedisCommands; //导入方法依赖的package包/类
@Test
public void masterSlaveWithSsl() {
RedisCommands<String, String> connection = MasterSlave.connect(redisClient, StringCodec.UTF8,
MASTER_SLAVE_URIS_NO_VERIFY).sync();
connection.set("key", "value");
assertThat(connection.get("key")).isEqualTo("value");
connection.getStatefulConnection().close();
}
示例12: testByteCodec
import com.lambdaworks.redis.api.sync.RedisCommands; //导入方法依赖的package包/类
@Test
public void testByteCodec() throws Exception {
RedisCommands<byte[], byte[]> connection = client.connect(new ByteArrayCodec()).sync();
String value = "üöäü+#";
connection.set(key.getBytes(), value.getBytes());
assertThat(connection.get(key.getBytes())).isEqualTo(value.getBytes());
connection.set(key.getBytes(), null);
assertThat(connection.get(key.getBytes())).isEqualTo(new byte[0]);
List<byte[]> keys = connection.keys(key.getBytes());
assertThat(keys).contains(key.getBytes());
connection.close();
}
示例13: commandCancelledOverSyncAPIAfterConnectionIsDisconnected
import com.lambdaworks.redis.api.sync.RedisCommands; //导入方法依赖的package包/类
@Test
public void commandCancelledOverSyncAPIAfterConnectionIsDisconnected() throws Exception {
RedisCommands<String, String> connection = client.connect().sync();
RedisCommands<String, String> verificationConnection = client.connect().sync();
connection.set(key, "1");
ConnectionWatchdog connectionWatchdog = Connections.getConnectionWatchdog(connection.getStatefulConnection());
connectionWatchdog.setListenOnChannelInactive(false);
connection.quit();
Wait.untilTrue(() -> !connection.isOpen()).waitOrTimeout();
try {
connection.incr(key);
} catch (RedisException e) {
assertThat(e).isExactlyInstanceOf(RedisCommandTimeoutException.class);
}
assertThat(verificationConnection.get("key")).isEqualTo("1");
assertThat(getStack(getRedisChannelHandler(connection))).isEmpty();
assertThat(getDisconnectedBuffer(getRedisChannelHandler(connection)).size()).isGreaterThan(0);
connectionWatchdog.setListenOnChannelInactive(true);
connectionWatchdog.scheduleReconnect();
while (!getCommandBuffer(getRedisChannelHandler(connection)).isEmpty()
|| !getDisconnectedBuffer(getRedisChannelHandler(connection)).isEmpty()) {
Thread.sleep(10);
}
assertThat(connection.get(key)).isEqualTo("1");
connection.close();
verificationConnection.close();
}
示例14: testJavaSerializer
import com.lambdaworks.redis.api.sync.RedisCommands; //导入方法依赖的package包/类
@Test
public void testJavaSerializer() throws Exception {
StatefulRedisConnection<String, Object> redisConnection = client.connect(new SerializedObjectCodec());
RedisCommands<String, Object> sync = redisConnection.sync();
List<String> list = list("one", "two");
sync.set(key, list);
assertThat(sync.get(key)).isEqualTo(list);
assertThat(sync.set(key, list)).isEqualTo("OK");
assertThat(sync.set(key, list, SetArgs.Builder.ex(1))).isEqualTo("OK");
redisConnection.close();
}
示例15: testDeflateCompressedJavaSerializer
import com.lambdaworks.redis.api.sync.RedisCommands; //导入方法依赖的package包/类
@Test
public void testDeflateCompressedJavaSerializer() throws Exception {
RedisCommands<String, Object> connection = client
.connect(
CompressionCodec
.valueCompressor(new SerializedObjectCodec(), CompressionCodec.CompressionType.DEFLATE))
.sync();
List<String> list = list("one", "two");
connection.set(key, list);
assertThat(connection.get(key)).isEqualTo(list);
connection.close();
}