本文整理汇总了Java中com.lambdaworks.redis.api.StatefulRedisConnection.sync方法的典型用法代码示例。如果您正苦于以下问题:Java StatefulRedisConnection.sync方法的具体用法?Java StatefulRedisConnection.sync怎么用?Java StatefulRedisConnection.sync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.lambdaworks.redis.api.StatefulRedisConnection
的用法示例。
在下文中一共展示了StatefulRedisConnection.sync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例2: genericPoolUsingWrappingShouldPropagateExceptionsCorrectly
import com.lambdaworks.redis.api.StatefulRedisConnection; //导入方法依赖的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();
}
示例3: wrappedConnectionShouldUseWrappers
import com.lambdaworks.redis.api.StatefulRedisConnection; //导入方法依赖的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();
}
示例4: plainConnectionShouldNotUseWrappers
import com.lambdaworks.redis.api.StatefulRedisConnection; //导入方法依赖的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();
}
示例5: 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();
}
示例6: 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");
}
}
示例7: ping
import com.lambdaworks.redis.api.StatefulRedisConnection; //导入方法依赖的package包/类
public String ping() {
StatefulRedisConnection<String, String> connection = redisClient.connect();
RedisCommands<String, String> sync = connection.sync();
String result = sync.ping();
connection.close();
return result;
}
示例8: sync
import com.lambdaworks.redis.api.StatefulRedisConnection; //导入方法依赖的package包/类
/**
* Create a transactional wrapper proxy for {@link RedisCommands}.
*
* @param connection the connection
* @return the wrapper proxy.
*/
@SuppressWarnings("unchecked")
public static <K, V> RedisCommands<K, V> sync(StatefulRedisConnection<K, V> connection) {
try {
TxSyncInvocationHandler<K, V> handler = new TxSyncInvocationHandler<>(connection.sync());
return (RedisCommands<K, V>) Proxy.newProxyInstance(handler.getClass().getClassLoader(),
new Class<?>[] { RedisCommands.class }, handler);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
示例9: testJavaSerializer
import com.lambdaworks.redis.api.StatefulRedisConnection; //导入方法依赖的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();
}
示例10: borrowAndReturn
import com.lambdaworks.redis.api.StatefulRedisConnection; //导入方法依赖的package包/类
private void borrowAndReturn(ObjectPool<StatefulRedisConnection<String, String>> pool) throws Exception {
for (int i = 0; i < 10; i++) {
StatefulRedisConnection<String, String> connection = pool.borrowObject();
RedisCommands<String, String> sync = connection.sync();
sync.ping();
pool.returnObject(connection);
}
}
示例11: borrowAndClose
import com.lambdaworks.redis.api.StatefulRedisConnection; //导入方法依赖的package包/类
private void borrowAndClose(ObjectPool<StatefulRedisConnection<String, String>> pool) throws Exception {
for (int i = 0; i < 10; i++) {
StatefulRedisConnection<String, String> connection = pool.borrowObject();
RedisCommands<String, String> sync = connection.sync();
sync.ping();
sync.close();
}
}
示例12: main
import com.lambdaworks.redis.api.StatefulRedisConnection; //导入方法依赖的package包/类
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"com/lambdaworks/examples/SpringTest-context.xml");
RedisClient client = context.getBean(RedisClient.class);
StatefulRedisConnection<String, String> connection = client.connect();
RedisCommands<String, String> sync = connection.sync();
System.out.println("PING: " + sync.ping());
connection.close();
MySpringBean mySpringBean = context.getBean(MySpringBean.class);
System.out.println("PING: " + mySpringBean.ping());
context.close();
}
示例13: main
import com.lambdaworks.redis.api.StatefulRedisConnection; //导入方法依赖的package包/类
public static void main(String[] args) {
// Syntax: redis://[[email protected]]host[:port][/databaseNumber]
RedisClient redisClient = RedisClient.create(RedisURI.create("redis://[email protected]:6379/0"));
StatefulRedisConnection<String, String> connection = redisClient.connect();
System.out.println("Connected to Redis");
RedisCommands<String, String> sync = connection.sync();
sync.set("foo", "bar");
String value = sync.get("foo");
System.out.println(value);
connection.close();
redisClient.shutdown();
}
示例14: softRefPoolShouldWorkWithWrappedConnections
import com.lambdaworks.redis.api.StatefulRedisConnection; //导入方法依赖的package包/类
@Test
public void softRefPoolShouldWorkWithWrappedConnections() throws Exception {
SoftReferenceObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport
.createSoftReferenceObjectPool(() -> client.connect());
StatefulRedisConnection<String, String> connection = pool.borrowObject();
assertThat(channels).hasSize(1);
RedisCommands<String, String> sync = connection.sync();
sync.ping();
sync.close();
pool.close();
Wait.untilTrue(channels::isEmpty).waitOrTimeout();
assertThat(channels).isEmpty();
}
示例15: of
import com.lambdaworks.redis.api.StatefulRedisConnection; //导入方法依赖的package包/类
/**
* Create {@link RedisCommands} given {@link StatefulRedisConnection}.
*
* @param connection must not be {@literal null}.
* @return
*/
public static RedisConditions of(StatefulRedisConnection<String, String> connection) {
return new RedisConditions(connection.sync());
}