io.lettuce.core.AbstractRedisClient Java Examples
The following examples show how to use
io.lettuce.core.AbstractRedisClient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisLettuceCache.java From jetcache with Apache License 2.0 | 6 votes |
@Override public <T> T unwrap(Class<T> clazz) { Objects.requireNonNull(clazz); if (AbstractRedisClient.class.isAssignableFrom(clazz)) { return (T) client; } else if (RedisClusterCommands.class.isAssignableFrom(clazz)) { // RedisCommands extends RedisClusterCommands return (T) stringCommands; } else if (RedisClusterAsyncCommands.class.isAssignableFrom(clazz)) { // RedisAsyncCommands extends RedisClusterAsyncCommands return (T) stringAsyncCommands; } else if (RedisClusterReactiveCommands.class.isAssignableFrom(clazz)) { // RedisReactiveCommands extends RedisClusterReactiveCommands return (T) lettuceConnectionManager.reactiveCommands(client); } throw new IllegalArgumentException(clazz.getName()); }
Example #2
Source File: LettuceFactory.java From jetcache with Apache License 2.0 | 6 votes |
public LettuceFactory(String key, Class<?> clazz) { this.clazz = clazz; if (AbstractRedisClient.class.isAssignableFrom(clazz)) { key += ".client"; } else if (StatefulConnection.class.isAssignableFrom(clazz)) { key += ".connection"; } else if (RedisClusterCommands.class.isAssignableFrom(clazz)) { // RedisCommands extends RedisClusterCommands key += ".commands"; } else if (RedisClusterAsyncCommands.class.isAssignableFrom(clazz)) { // RedisAsyncCommands extends RedisClusterAsyncCommands key += ".asyncCommands"; } else if (RedisClusterReactiveCommands.class.isAssignableFrom(clazz)) { // RedisReactiveCommands extends RedisClusterReactiveCommands key += ".reactiveCommands"; } else { throw new IllegalArgumentException(clazz.getName()); } this.key = key; }
Example #3
Source File: LettuceConnectionManager.java From jetcache with Apache License 2.0 | 6 votes |
public void removeAndClose(AbstractRedisClient redisClient) { LettuceObjects lo = (LettuceObjects) map.remove(redisClient); if (lo == null) { return; } /* if (lo.commands != null && lo.commands instanceof RedisClusterCommands) { ((RedisClusterCommands) lo.commands).close(); } if (lo.asyncCommands != null && lo.asyncCommands instanceof RedisClusterAsyncCommands) { ((RedisClusterAsyncCommands) lo.asyncCommands).close(); } if (lo.reactiveCommands != null && lo.reactiveCommands instanceof RedisClusterReactiveCommands) { ((RedisClusterReactiveCommands) lo.reactiveCommands).close(); } */ if (lo.connection != null) { lo.connection.close(); } redisClient.shutdown(); }
Example #4
Source File: LettuceConnectionManager.java From jetcache with Apache License 2.0 | 6 votes |
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 if (lo.connection instanceof StatefulRedisSentinelConnection) { lo.reactiveCommands = ((StatefulRedisSentinelConnection) lo.connection).reactive(); } else { throw new CacheConfigException("type " + lo.connection.getClass() + " is not supported"); } } return lo.reactiveCommands; }
Example #5
Source File: LettuceConnectionManager.java From jetcache with Apache License 2.0 | 6 votes |
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 if (lo.connection instanceof StatefulRedisSentinelConnection) { lo.asyncCommands = ((StatefulRedisSentinelConnection) lo.connection).async(); } else { throw new CacheConfigException("type " + lo.connection.getClass() + " is not supported"); } } return lo.asyncCommands; }
Example #6
Source File: LettuceConnectionManager.java From jetcache with Apache License 2.0 | 6 votes |
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 if (lo.connection instanceof StatefulRedisSentinelConnection) { lo.commands = ((StatefulRedisSentinelConnection) lo.connection).sync(); }else { throw new CacheConfigException("type " + lo.connection.getClass() + " is not supported"); } } return lo.commands; }
Example #7
Source File: AbstractRedisClientInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { EnhancedInstance clientOptions = (EnhancedInstance) allArguments[0]; if (clientOptions == null) { return; } AbstractRedisClient client = (AbstractRedisClient) objInst; if (client.getOptions() == null || ((EnhancedInstance) client.getOptions()).getSkyWalkingDynamicField() == null) { return; } clientOptions.setSkyWalkingDynamicField(((EnhancedInstance) client.getOptions()).getSkyWalkingDynamicField()); }
Example #8
Source File: RedisLettuceCacheTest.java From jetcache with Apache License 2.0 | 5 votes |
private void testUnwrap(AbstractRedisClient client) { Assert.assertTrue(cache.unwrap(AbstractRedisClient.class) instanceof AbstractRedisClient); if (client instanceof RedisClient) { Assert.assertTrue(cache.unwrap(RedisClient.class) instanceof RedisClient); Assert.assertTrue(cache.unwrap(RedisCommands.class) instanceof RedisCommands); Assert.assertTrue(cache.unwrap(RedisAsyncCommands.class) instanceof RedisAsyncCommands); Assert.assertTrue(cache.unwrap(RedisReactiveCommands.class) instanceof RedisReactiveCommands); } else { Assert.assertTrue(cache.unwrap(RedisClusterClient.class) instanceof RedisClusterClient); Assert.assertTrue(cache.unwrap(RedisClusterCommands.class) instanceof RedisClusterCommands); Assert.assertTrue(cache.unwrap(RedisClusterAsyncCommands.class) instanceof RedisClusterAsyncCommands); Assert.assertTrue(cache.unwrap(RedisClusterReactiveCommands.class) instanceof RedisClusterReactiveCommands); } }
Example #9
Source File: LettuceConnectionManager.java From jetcache with Apache License 2.0 | 5 votes |
public StatefulConnection connection(AbstractRedisClient redisClient) { LettuceObjects lo = getLettuceObjectsFromMap(redisClient); if (lo.connection == null) { if (redisClient instanceof RedisClient) { lo.connection = ((RedisClient) redisClient).connect(new JetCacheCodec()); } else if (redisClient instanceof RedisClusterClient) { lo.connection = ((RedisClusterClient) redisClient).connect(new JetCacheCodec()); } else { throw new CacheConfigException("type " + redisClient.getClass() + " is not supported"); } } return lo.connection; }
Example #10
Source File: LettuceConnectionManager.java From jetcache with Apache License 2.0 | 5 votes |
public void init(AbstractRedisClient redisClient, StatefulConnection connection) { map.computeIfAbsent(redisClient, key -> { LettuceObjects lo = new LettuceObjects(); lo.connection = connection; return lo; }); }
Example #11
Source File: LettuceConnectionManager.java From jetcache with Apache License 2.0 | 5 votes |
private LettuceObjects getLettuceObjectsFromMap(AbstractRedisClient redisClient) { LettuceObjects lo = map.get(redisClient); if (lo == null) { throw new CacheException("LettuceObjects is not initialized"); } return lo; }
Example #12
Source File: RedisLettuceCacheTest.java From jetcache with Apache License 2.0 | 4 votes |
private void test(AbstractRedisClient client, StatefulConnection connection) throws Exception { cache = RedisLettuceCacheBuilder.createRedisLettuceCacheBuilder() .redisClient(client) .connection(connection) .keyConvertor(FastjsonKeyConvertor.INSTANCE) .valueEncoder(JavaValueEncoder.INSTANCE) .valueDecoder(JavaValueDecoder.INSTANCE) .keyPrefix(new Random().nextInt() + "") .expireAfterWrite(500, TimeUnit.MILLISECONDS) .buildCache(); baseTest(); expireAfterWriteTest(cache.config().getExpireAfterWriteInMillis()); fastjsonKeyCoverterTest(); testUnwrap(client); LoadingCacheTest.loadingCacheTest(RedisLettuceCacheBuilder.createRedisLettuceCacheBuilder() .redisClient(client) .keyConvertor(FastjsonKeyConvertor.INSTANCE) .valueEncoder(JavaValueEncoder.INSTANCE) .valueDecoder(JavaValueDecoder.INSTANCE) .keyPrefix(new Random().nextInt() + ""), 50); cache = RedisLettuceCacheBuilder.createRedisLettuceCacheBuilder() .redisClient(client) .keyConvertor(null) .valueEncoder(KryoValueEncoder.INSTANCE) .valueDecoder(KryoValueDecoder.INSTANCE) .keyPrefix(new Random().nextInt() + "") .buildCache(); nullKeyConvertorTest(); int thread = 10; int time = 3000; cache = RedisLettuceCacheBuilder.createRedisLettuceCacheBuilder() .redisClient(client) .keyConvertor(FastjsonKeyConvertor.INSTANCE) .valueEncoder(KryoValueEncoder.INSTANCE) .valueDecoder(KryoValueDecoder.INSTANCE) .keyPrefix(new Random().nextInt() + "") .buildCache(); ((RedisLettuceCacheConfig) cache.config()).setAsyncResultTimeoutInMillis(1100); concurrentTest(thread, 500, time); LettuceConnectionManager.defaultManager().removeAndClose(client); }
Example #13
Source File: RedisLettuceCacheBuilder.java From jetcache with Apache License 2.0 | 4 votes |
public void setRedisClient(AbstractRedisClient redisClient) { getConfig().setRedisClient(redisClient); }
Example #14
Source File: RedisLettuceCacheConfig.java From jetcache with Apache License 2.0 | 4 votes |
public void setRedisClient(AbstractRedisClient redisClient) { this.redisClient = redisClient; }
Example #15
Source File: RedisSessionFactoryImpl.java From kafka-connect-redis with Apache License 2.0 | 4 votes |
RedisSessionImpl(AbstractRedisClient client, StatefulConnection connection, RedisClusterAsyncCommands<byte[], byte[]> asyncCommands, RedisConnectorConfig config) { this.client = client; this.connection = connection; this.asyncCommands = asyncCommands; this.config = config; }
Example #16
Source File: RedisSessionFactoryImpl.java From kafka-connect-redis with Apache License 2.0 | 4 votes |
public AbstractRedisClient client() { return this.client; }
Example #17
Source File: RedisSession.java From pulsar with Apache License 2.0 | 4 votes |
public RedisSession(AbstractRedisClient client, StatefulConnection connection, RedisClusterAsyncCommands<byte[], byte[]> asyncCommands) { this.client = client; this.connection = connection; this.asyncCommands = asyncCommands; }
Example #18
Source File: RedisSession.java From pulsar with Apache License 2.0 | 4 votes |
public AbstractRedisClient client() { return this.client; }
Example #19
Source File: RedisLettuceCacheConfig.java From jetcache with Apache License 2.0 | 4 votes |
public AbstractRedisClient getRedisClient() { return redisClient; }
Example #20
Source File: RedisSession.java From kafka-connect-redis with Apache License 2.0 | votes |
AbstractRedisClient client();