本文整理汇总了Java中io.lettuce.core.api.StatefulRedisConnection类的典型用法代码示例。如果您正苦于以下问题:Java StatefulRedisConnection类的具体用法?Java StatefulRedisConnection怎么用?Java StatefulRedisConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StatefulRedisConnection类属于io.lettuce.core.api包,在下文中一共展示了StatefulRedisConnection类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sync
import io.lettuce.core.api.StatefulRedisConnection; //导入依赖的package包/类
@Test
public void sync() {
RedisClient client = RedisClient.create("redis://localhost");
StatefulRedisConnection<String, String> connection =
new TracingStatefulRedisConnection<>(client.connect(), mockTracer, false);
RedisCommands<String, String> commands = connection.sync();
assertEquals("OK", commands.set("key", "value"));
assertEquals("value", commands.get("key"));
connection.close();
client.shutdown();
List<MockSpan> spans = mockTracer.finishedSpans();
assertEquals(2, spans.size());
}
示例2: commands
import io.lettuce.core.api.StatefulRedisConnection; //导入依赖的package包/类
public Object commands(AbstractRedisClient redisClient) {
connection(redisClient);
LettuceObjects lo = getLettuceObjectsFromMap(redisClient);
if (lo.commands == null) {
if (lo.connection instanceof StatefulRedisConnection) {
lo.commands = ((StatefulRedisConnection) lo.connection).sync();
} else if (lo.connection instanceof StatefulRedisClusterConnection) {
lo.commands = ((StatefulRedisClusterConnection) lo.connection).sync();
} else {
throw new CacheConfigException("type " + lo.connection.getClass() + " is not supported");
}
}
return lo.commands;
}
示例3: asyncCommands
import io.lettuce.core.api.StatefulRedisConnection; //导入依赖的package包/类
public Object asyncCommands(AbstractRedisClient redisClient) {
connection(redisClient);
LettuceObjects lo = getLettuceObjectsFromMap(redisClient);
if (lo.asyncCommands == null) {
if (lo.connection instanceof StatefulRedisConnection) {
lo.asyncCommands = ((StatefulRedisConnection) lo.connection).async();
} else if (lo.connection instanceof StatefulRedisClusterConnection) {
lo.asyncCommands = ((StatefulRedisClusterConnection) lo.connection).async();
} else {
throw new CacheConfigException("type " + lo.connection.getClass() + " is not supported");
}
}
return lo.asyncCommands;
}
示例4: reactiveCommands
import io.lettuce.core.api.StatefulRedisConnection; //导入依赖的package包/类
public Object reactiveCommands(AbstractRedisClient redisClient) {
connection(redisClient);
LettuceObjects lo = getLettuceObjectsFromMap(redisClient);
if (lo.reactiveCommands == null) {
if (lo.connection instanceof StatefulRedisConnection) {
lo.reactiveCommands = ((StatefulRedisConnection) lo.connection).reactive();
} else if (lo.connection instanceof StatefulRedisClusterConnection) {
lo.reactiveCommands = ((StatefulRedisClusterConnection) lo.connection).reactive();
} else {
throw new CacheConfigException("type " + lo.connection.getClass() + " is not supported");
}
}
return lo.reactiveCommands;
}
示例5: tests
import io.lettuce.core.api.StatefulRedisConnection; //导入依赖的package包/类
@Test
public void tests() throws Exception {
if (RedisLettuceCacheTest.checkOS()) {
System.setProperty("spring.profiles.active", "redislettuce-cluster");
} else {
System.setProperty("spring.profiles.active", "redislettuce");
}
context = SpringApplication.run(RedisLettuceStarterTest.class);
doTest();
A bean = context.getBean(A.class);
bean.test();
RedisClient t1 = (RedisClient) context.getBean("defaultClient");
RedisClient t2 = (RedisClient) context.getBean("a1Client");
Assert.assertNotNull(t1);
Assert.assertNotNull(t2);
Assert.assertNotSame(t1, t2);
AutoConfigureBeans acb = context.getBean(AutoConfigureBeans.class);
String key = "remote.A1";
Assert.assertTrue(new LettuceFactory(acb, key, StatefulRedisConnection.class).getObject() instanceof StatefulRedisConnection);
Assert.assertTrue(new LettuceFactory(acb, key, RedisCommands.class).getObject() instanceof RedisCommands);
Assert.assertTrue(new LettuceFactory(acb, key, RedisAsyncCommands.class).getObject() instanceof RedisAsyncCommands);
Assert.assertTrue(new LettuceFactory(acb, key, RedisReactiveCommands.class).getObject() instanceof RedisReactiveCommands);
if (RedisLettuceCacheTest.checkOS()) {
key = "remote.A2";
Assert.assertTrue(new LettuceFactory(acb, key , RedisClusterClient.class).getObject() instanceof RedisClusterClient);
Assert.assertTrue(new LettuceFactory(acb, key , RedisClusterCommands.class).getObject() instanceof RedisClusterCommands);
Assert.assertTrue(new LettuceFactory(acb, key , RedisClusterAsyncCommands.class).getObject() instanceof RedisClusterAsyncCommands);
Assert.assertTrue(new LettuceFactory(acb, key , RedisClusterReactiveCommands.class).getObject() instanceof RedisClusterReactiveCommands);
}
}
示例6: TracingStatefulRedisConnection
import io.lettuce.core.api.StatefulRedisConnection; //导入依赖的package包/类
/**
* @param connection redis connection
* @param tracer tracer
* @param traceWithActiveSpanOnly if <code>true</code> then create new spans only if there is
* active span
*/
public TracingStatefulRedisConnection(StatefulRedisConnection<K, V> connection, Tracer tracer,
boolean traceWithActiveSpanOnly) {
this.connection = connection;
this.tracer = tracer;
this.traceWithActiveSpanOnly = traceWithActiveSpanOnly;
}
示例7: run
import io.lettuce.core.api.StatefulRedisConnection; //导入依赖的package包/类
@Override
public void run(Configuration configuration, Environment environment) {
environment.jersey().register(new LoginResource());
environment.jersey().register(new UserResource());
environment.jersey().register(new AuthDynamicFeature(
new OAuthCredentialAuthFilter.Builder<PrincipalImpl>()
.setAuthenticator(new TestOAuthAuthenticator()).setPrefix("Bearer")
.buildAuthFilter()));
environment.jersey().register(RolesAllowedDynamicFeature.class);
environment.jersey().register(new AuthValueFactoryProvider.Binder<>(PrincipalImpl.class));
//TODO move this cleanup into the tests
environment.lifecycle().manage(new Managed() {
@Override
public void start() {
}
@Override
public void stop() {
flushRedis();
}
private void flushRedis() {
try (StatefulRedisConnection<String, String> connection = redisClient.connect()) {
connection.sync().flushdb();
}
redisClient.shutdownAsync();
}
});
}
示例8: RedisSlidingWindowRequestRateLimiter
import io.lettuce.core.api.StatefulRedisConnection; //导入依赖的package包/类
public RedisSlidingWindowRequestRateLimiter(StatefulRedisConnection<String, String> connection, Set<RequestLimitRule> rules, TimeSupplier timeSupplier) {
requireNonNull(rules, "rules can not be null");
requireNonNull(timeSupplier, "time supplier can not be null");
requireNonNull(connection, "connection can not be null");
this.connection = connection;
scriptLoader = new RedisScriptLoader(connection, "sliding-window-ratelimit.lua");
rulesJson = serialiserLimitRules(rules);
this.timeSupplier = timeSupplier;
}
示例9: RedisScriptLoader
import io.lettuce.core.api.StatefulRedisConnection; //导入依赖的package包/类
public RedisScriptLoader(StatefulRedisConnection<String, String> connection, String scriptUri, boolean eagerLoad) {
requireNonNull(connection);
this.connection = connection;
this.scriptUri = requireNonNull(scriptUri);
if (eagerLoad) {
scriptSha();
}
}
示例10: getConnection
import io.lettuce.core.api.StatefulRedisConnection; //导入依赖的package包/类
private StatefulRedisConnection<String, String> getConnection() {
// going to ignore race conditions at the cost of having multiple connections
if (connection == null) {
connection = client.connect();
}
return connection;
}
示例11: getStatefulConnection
import io.lettuce.core.api.StatefulRedisConnection; //导入依赖的package包/类
@Override
public StatefulRedisConnection<K, V> getStatefulConnection() {
return new TracingStatefulRedisConnection<>(commands.getStatefulConnection(), tracer,
traceWithActiveSpanOnly);
}
示例12: async
import io.lettuce.core.api.StatefulRedisConnection; //导入依赖的package包/类
@Test
public void async() throws Exception {
RedisClient client = RedisClient.create("redis://localhost");
StatefulRedisConnection<String, String> connection =
new TracingStatefulRedisConnection<>(client.connect(), mockTracer, false);
RedisAsyncCommands<String, String> commands = connection.async();
assertEquals("OK", commands.set("key2", "value2").get(15, TimeUnit.SECONDS));
assertEquals("value2", commands.get("key2").get(15, TimeUnit.SECONDS));
connection.close();
client.shutdown();
List<MockSpan> spans = mockTracer.finishedSpans();
assertEquals(2, spans.size());
}
示例13: RedisTimeSupplier
import io.lettuce.core.api.StatefulRedisConnection; //导入依赖的package包/类
public RedisTimeSupplier(StatefulRedisConnection<String, String> connection) {
this.connection = requireNonNull(connection);
}
示例14: afterEach
import io.lettuce.core.api.StatefulRedisConnection; //导入依赖的package包/类
@AfterEach
void afterEach() {
try (StatefulRedisConnection<String, String> connection = client.connect()) {
connection.sync().flushdb();
}
}