Search in sources :

Example 1 with JedisConnectSourceConfig

use of com.lcache.extend.handle.redis.jedis.config.JedisConnectSourceConfig in project lcache by long172066912.

the class RedissonClientManager method getJedisRedissonConfig.

/**
 * Jedis配置转Redisson配置
 *
 * @param cacheConfigModel
 * @param cacheConfig
 * @return
 */
private static Config getJedisRedissonConfig(CacheConfigModel cacheConfigModel, BaseCacheConfig cacheConfig) {
    Config config = new Config();
    switch(cacheConfigModel.getConnectTypeEnum()) {
        case SIMPLE:
            JedisConnectSourceConfig simpleConfig = (JedisConnectSourceConfig) cacheConfig;
            config.useSingleServer().setAddress("redis://" + simpleConfig.getHost() + ":" + simpleConfig.getPort()).setPassword(StringUtils.isNotBlank(simpleConfig.getPwd()) ? simpleConfig.getPwd() : null);
            break;
        case POOL:
            JedisConnectSourceConfig poolConfig = (JedisConnectSourceConfig) cacheConfig;
            config.useSingleServer().setAddress("redis://" + poolConfig.getHost() + ":" + poolConfig.getPort()).setPassword(StringUtils.isNotBlank(poolConfig.getPwd()) ? poolConfig.getPwd() : null);
            break;
        case SHARDED:
            return null;
        case CLUSTER:
            JedisClusterConnectSourceConfig clusterConfig = (JedisClusterConnectSourceConfig) cacheConfig;
            for (HostAndPort hostAndPort : clusterConfig.getNodes()) {
                config.useClusterServers().addNodeAddress("redis://" + hostAndPort.getHost() + ":" + hostAndPort.getPort());
            }
            config.useClusterServers().setScanInterval(2000).setPassword(StringUtils.isNotBlank(clusterConfig.getPwd()) ? clusterConfig.getPwd() : null);
            break;
        case CLUSTER_POOL:
            JedisClusterConnectSourceConfig clusterPoolConfig = (JedisClusterConnectSourceConfig) cacheConfig;
            for (HostAndPort hostAndPort : clusterPoolConfig.getNodes()) {
                config.useClusterServers().addNodeAddress("redis://" + hostAndPort.getHost() + ":" + hostAndPort.getPort());
            }
            config.useClusterServers().setScanInterval(2000).setPassword(StringUtils.isNotBlank(clusterPoolConfig.getPwd()) ? clusterPoolConfig.getPwd() : null);
            break;
        default:
            return null;
    }
    return config;
}
Also used : JedisConnectSourceConfig(com.lcache.extend.handle.redis.jedis.config.JedisConnectSourceConfig) HostAndPort(redis.clients.jedis.HostAndPort) BaseCacheConfig(com.lcache.config.BaseCacheConfig) JedisClusterConnectSourceConfig(com.lcache.extend.handle.redis.jedis.config.JedisClusterConnectSourceConfig) LettuceConnectSourceConfig(com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig) Config(org.redisson.config.Config) JedisConnectSourceConfig(com.lcache.extend.handle.redis.jedis.config.JedisConnectSourceConfig) LettuceClusterConnectSourceConfig(com.lcache.extend.handle.redis.lettuce.config.LettuceClusterConnectSourceConfig) JedisClusterConnectSourceConfig(com.lcache.extend.handle.redis.jedis.config.JedisClusterConnectSourceConfig)

Example 2 with JedisConnectSourceConfig

use of com.lcache.extend.handle.redis.jedis.config.JedisConnectSourceConfig 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 3 with JedisConnectSourceConfig

use of com.lcache.extend.handle.redis.jedis.config.JedisConnectSourceConfig in project lcache by long172066912.

the class TestRedisCache2 method evalZadd.

@Test
public void evalZadd() {
    new Thread(() -> {
        BaseCacheExecutor jedis = CacheClientFactory.getCacheExecutor(CacheConfigModel.jedisPool("test"), new JedisConnectSourceConfig());
        // zset批量判断是否存
        String jzsetKey = "jzset:test:1";
        jedis.del(jzsetKey);
        while (true) {
            try {
                jedis.zadd(jzsetKey, ImmutableMap.of("a", (double) 1, "b", (double) 2, "c", (double) 3), 3600);
                jedis.zaddIfKeyExists(jzsetKey, 4, "e", 3600);
                Map<String, Double> score = jedis.zscoreBatch(jzsetKey, Arrays.asList("a", "b", "c", "e"));
                System.out.println("jedis : " + JSON.toJSONString(score));
                Thread.sleep(500L);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
    BaseCacheExecutor baseCacheExecutor = CacheClientFactory.getCacheExecutor("test", new LettuceConnectSourceConfig());
    // zset批量判断是否存
    String zsetKey = "lzset:test:1";
    baseCacheExecutor.del(zsetKey);
    while (true) {
        try {
            baseCacheExecutor.zadd(zsetKey, ImmutableMap.of("a", (double) 1, "b", (double) 2, "c", (double) 3), 3600);
            baseCacheExecutor.zaddIfKeyExists(zsetKey, 4, "e", 3600);
            Map<String, Double> score = baseCacheExecutor.zscoreBatch(zsetKey, Arrays.asList("a", "b", "c", "e"));
            System.out.println("lettuce : " + JSON.toJSONString(score));
            Thread.sleep(500L);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : JedisConnectSourceConfig(com.lcache.extend.handle.redis.jedis.config.JedisConnectSourceConfig) BaseCacheExecutor(com.lcache.core.BaseCacheExecutor) LettuceConnectSourceConfig(com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

JedisConnectSourceConfig (com.lcache.extend.handle.redis.jedis.config.JedisConnectSourceConfig)3 LettuceConnectSourceConfig (com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig)3 Test (org.junit.Test)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 BaseCacheConfig (com.lcache.config.BaseCacheConfig)1 BaseCacheExecutor (com.lcache.core.BaseCacheExecutor)1 CacheConfigModel (com.lcache.core.model.CacheConfigModel)1 JedisClusterConnectSourceConfig (com.lcache.extend.handle.redis.jedis.config.JedisClusterConnectSourceConfig)1 LettuceClusterConnectSourceConfig (com.lcache.extend.handle.redis.lettuce.config.LettuceClusterConnectSourceConfig)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 Config (org.redisson.config.Config)1 HostAndPort (redis.clients.jedis.HostAndPort)1