Search in sources :

Example 1 with StatefulRedisConnection

use of com.lambdaworks.redis.api.StatefulRedisConnection in project jetcache by alibaba.

the class LutteceConnectionManager method asyncCommands.

public Object asyncCommands(AbstractRedisClient redisClient) {
    connection(redisClient);
    LutteceObjects lo = getLutteceObjectsFromMap(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;
}
Also used : CacheConfigException(com.alicp.jetcache.CacheConfigException) StatefulRedisClusterConnection(com.lambdaworks.redis.cluster.api.StatefulRedisClusterConnection) StatefulRedisConnection(com.lambdaworks.redis.api.StatefulRedisConnection)

Example 2 with StatefulRedisConnection

use of com.lambdaworks.redis.api.StatefulRedisConnection in project jetcache by alibaba.

the class LutteceConnectionManager method commands.

public Object commands(AbstractRedisClient redisClient) {
    connection(redisClient);
    LutteceObjects lo = getLutteceObjectsFromMap(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;
}
Also used : CacheConfigException(com.alicp.jetcache.CacheConfigException) StatefulRedisClusterConnection(com.lambdaworks.redis.cluster.api.StatefulRedisClusterConnection) StatefulRedisConnection(com.lambdaworks.redis.api.StatefulRedisConnection)

Example 3 with StatefulRedisConnection

use of com.lambdaworks.redis.api.StatefulRedisConnection in project jetcache by alibaba.

the class LutteceConnectionManager method reactiveCommands.

public Object reactiveCommands(AbstractRedisClient redisClient) {
    connection(redisClient);
    LutteceObjects lo = getLutteceObjectsFromMap(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;
}
Also used : CacheConfigException(com.alicp.jetcache.CacheConfigException) StatefulRedisClusterConnection(com.lambdaworks.redis.cluster.api.StatefulRedisClusterConnection) StatefulRedisConnection(com.lambdaworks.redis.api.StatefulRedisConnection)

Example 4 with StatefulRedisConnection

use of com.lambdaworks.redis.api.StatefulRedisConnection in project jetcache by alibaba.

the class RedisLutteceStarterTest method tests.

@Test
public void tests() throws Exception {
    if (RedisLutteceCacheTest.checkOS()) {
        System.setProperty("spring.profiles.active", "redisluttece-cluster");
    } else {
        System.setProperty("spring.profiles.active", "redisluttece");
    }
    context = SpringApplication.run(RedisLutteceStarterTest.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 LutteceFactory(acb, key, StatefulRedisConnection.class).getObject() instanceof StatefulRedisConnection);
    Assert.assertTrue(new LutteceFactory(acb, key, RedisCommands.class).getObject() instanceof RedisCommands);
    Assert.assertTrue(new LutteceFactory(acb, key, RedisAsyncCommands.class).getObject() instanceof RedisAsyncCommands);
    Assert.assertTrue(new LutteceFactory(acb, key, RedisReactiveCommands.class).getObject() instanceof RedisReactiveCommands);
    if (RedisLutteceCacheTest.checkOS()) {
        key = "remote.A2";
        Assert.assertTrue(new LutteceFactory(acb, key, RedisClusterClient.class).getObject() instanceof RedisClusterClient);
        Assert.assertTrue(new LutteceFactory(acb, key, RedisClusterCommands.class).getObject() instanceof RedisClusterCommands);
        Assert.assertTrue(new LutteceFactory(acb, key, RedisClusterAsyncCommands.class).getObject() instanceof RedisClusterAsyncCommands);
        Assert.assertTrue(new LutteceFactory(acb, key, RedisClusterReactiveCommands.class).getObject() instanceof RedisClusterReactiveCommands);
    }
}
Also used : RedisClusterCommands(com.lambdaworks.redis.cluster.api.sync.RedisClusterCommands) StatefulRedisConnection(com.lambdaworks.redis.api.StatefulRedisConnection) RedisClusterAsyncCommands(com.lambdaworks.redis.cluster.api.async.RedisClusterAsyncCommands) RedisClient(com.lambdaworks.redis.RedisClient) RedisCommands(com.lambdaworks.redis.api.sync.RedisCommands) RedisAsyncCommands(com.lambdaworks.redis.api.async.RedisAsyncCommands) RedisClusterReactiveCommands(com.lambdaworks.redis.cluster.api.rx.RedisClusterReactiveCommands) RedisClusterClient(com.lambdaworks.redis.cluster.RedisClusterClient) RedisReactiveCommands(com.lambdaworks.redis.api.rx.RedisReactiveCommands) SpringTest(com.alicp.jetcache.test.spring.SpringTest) Test(org.junit.Test) RedisLutteceCacheTest(com.alicp.jetcache.redis.luttece.RedisLutteceCacheTest)

Aggregations

StatefulRedisConnection (com.lambdaworks.redis.api.StatefulRedisConnection)4 CacheConfigException (com.alicp.jetcache.CacheConfigException)3 StatefulRedisClusterConnection (com.lambdaworks.redis.cluster.api.StatefulRedisClusterConnection)3 RedisLutteceCacheTest (com.alicp.jetcache.redis.luttece.RedisLutteceCacheTest)1 SpringTest (com.alicp.jetcache.test.spring.SpringTest)1 RedisClient (com.lambdaworks.redis.RedisClient)1 RedisAsyncCommands (com.lambdaworks.redis.api.async.RedisAsyncCommands)1 RedisReactiveCommands (com.lambdaworks.redis.api.rx.RedisReactiveCommands)1 RedisCommands (com.lambdaworks.redis.api.sync.RedisCommands)1 RedisClusterClient (com.lambdaworks.redis.cluster.RedisClusterClient)1 RedisClusterAsyncCommands (com.lambdaworks.redis.cluster.api.async.RedisClusterAsyncCommands)1 RedisClusterReactiveCommands (com.lambdaworks.redis.cluster.api.rx.RedisClusterReactiveCommands)1 RedisClusterCommands (com.lambdaworks.redis.cluster.api.sync.RedisClusterCommands)1 Test (org.junit.Test)1