Search in sources :

Example 1 with CacheConfigModel

use of com.lcache.core.model.CacheConfigModel in project lcache by long172066912.

the class assertTest method getExecutor.

@Test
public void getExecutor() {
    assertEquals(jedis, CacheClientFactory.getCacheExecutor(new CacheConfigModel().setClientType(RedisClientConstants.JEDIS).setConnectTypeEnum(ConnectTypeEnum.POOL).setCacheType("test"), new JedisConnectSourceConfig()));
    assertEquals(lettuce, CacheClientFactory.getCacheExecutor(new CacheConfigModel().setClientType(RedisClientConstants.LETTUCE).setConnectTypeEnum(ConnectTypeEnum.SIMPLE).setCacheType("test1"), new LettuceConnectSourceConfig()));
    assertEquals(jedis, CacheClientFactory.builder().cacheType("test").clientType(RedisClientConstants.JEDIS).connectType(ConnectTypeEnum.POOL).cacheConfig(new JedisConnectSourceConfig()).build());
    assertEquals(lettuce, CacheClientFactory.builder().cacheType("test1").clientType(RedisClientConstants.LETTUCE).connectType(ConnectTypeEnum.SIMPLE).cacheConfig(new LettuceConnectSourceConfig()).build());
}
Also used : JedisConnectSourceConfig(com.lcache.extend.handle.redis.jedis.config.JedisConnectSourceConfig) LettuceConnectSourceConfig(com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig) CacheConfigModel(com.lcache.core.model.CacheConfigModel) Test(org.junit.Test)

Example 2 with CacheConfigModel

use of com.lcache.core.model.CacheConfigModel in project lcache by long172066912.

the class CacheConfigUtils method checkIsEquals.

/**
 * 检测2个key是否相等,cacheType+clientType+connectType
 *
 * @param hashKey1
 * @param hashKey2
 * @return
 */
public static boolean checkIsEquals(String hashKey1, String hashKey2) {
    CacheConfigModel cacheConfigModel1 = hashKeyToModel(hashKey1);
    CacheConfigModel cacheConfigModel2 = hashKeyToModel(hashKey2);
    return cacheConfigModel1.getCacheType().equals(cacheConfigModel2.getCacheType()) && cacheConfigModel1.getClientType() == cacheConfigModel2.getClientType() && cacheConfigModel1.getConnectTypeEnum().equals(cacheConfigModel2.getConnectTypeEnum()) && cacheConfigModel1.getConfigSourceType().equals(cacheConfigModel2.getConfigSourceType());
}
Also used : CacheConfigModel(com.lcache.core.model.CacheConfigModel)

Example 3 with CacheConfigModel

use of com.lcache.core.model.CacheConfigModel in project lcache by long172066912.

the class CacheClientFactory method getCacheExecutor.

/**
 * 自定义配置获取缓存执行器
 *
 * @param cacheType
 * @param config
 * @return
 */
public static BaseCacheExecutor getCacheExecutor(String cacheType, BaseCacheConfig config) {
    CacheConfigModel cacheConfigModel = new CacheConfigModel();
    cacheConfigModel.setConfigSourceType(CacheConfigSourceTypeEnum.CUSTOM);
    cacheConfigModel.setCacheType(cacheType);
    return CacheExecutorFactory.getCacheExecutor(config, cacheConfigModel);
}
Also used : CacheConfigModel(com.lcache.core.model.CacheConfigModel)

Example 4 with CacheConfigModel

use of com.lcache.core.model.CacheConfigModel in project lcache by long172066912.

the class AbstractLettuceHandleExecutor method pSync.

/**
 * Lettuce管道需要使用新的连接
 *
 * @param commands
 * @return
 */
@Override
public List<Object> pSync(List<PipelineCmd> commands) {
    // 设置使用方式为管道
    CacheConfigModel pipelineCacheConfigModel = new CacheConfigModel(this.getCacheConfigModel(), UseTypeEnum.PIPELINE);
    // 获取管道专用链接
    StatefulConnection statefulConnection = this.getStatefulConnection(new ConnectResource().setConnectResource(this.getPipelineConnectResource(pipelineCacheConfigModel)));
    try {
        List<Object> res = new ArrayList<>();
        List<RedisFuture<?>> redisFutures = new LettucePipelineExecutor(this.async(statefulConnection)).pSync(commands);
        for (int i = 0; i < redisFutures.size(); i++) {
            try {
                res.add(redisFutures.get(i).get());
            } catch (Exception e) {
                CacheExceptionFactory.addErrorLog("AbstractLettuceHandleExecutor->pSync get error ! size:" + i, e);
            }
        }
        return res;
    } finally {
    // 关闭连接
    // connectionResource.close();
    }
}
Also used : RedisFuture(io.lettuce.core.RedisFuture) StatefulConnection(io.lettuce.core.api.StatefulConnection) ArrayList(java.util.ArrayList) LettuceConnectResource(com.lcache.extend.handle.redis.lettuce.connect.LettuceConnectResource) ConnectResource(com.lcache.connect.ConnectResource) LettucePipelineExecutor(com.lcache.extend.handle.redis.lettuce.pipeline.LettucePipelineExecutor) CacheConfigModel(com.lcache.core.model.CacheConfigModel)

Aggregations

CacheConfigModel (com.lcache.core.model.CacheConfigModel)4 ConnectResource (com.lcache.connect.ConnectResource)1 JedisConnectSourceConfig (com.lcache.extend.handle.redis.jedis.config.JedisConnectSourceConfig)1 LettuceConnectSourceConfig (com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig)1 LettuceConnectResource (com.lcache.extend.handle.redis.lettuce.connect.LettuceConnectResource)1 LettucePipelineExecutor (com.lcache.extend.handle.redis.lettuce.pipeline.LettucePipelineExecutor)1 RedisFuture (io.lettuce.core.RedisFuture)1 StatefulConnection (io.lettuce.core.api.StatefulConnection)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1