Search in sources :

Example 26 with Config

use of org.redisson.config.Config in project redisson by redisson.

the class BaseTest method createConfig.

public static Config createConfig() {
    //        String redisAddress = System.getProperty("redisAddress");
    //        if (redisAddress == null) {
    //            redisAddress = "127.0.0.1:6379";
    //        }
    Config config = new Config();
    //        config.setCodec(new MsgPackJacksonCodec());
    //        config.useSentinelServers().setMasterName("mymaster").addSentinelAddress("127.0.0.1:26379", "127.0.0.1:26389");
    //        config.useClusterServers().addNodeAddress("127.0.0.1:7004", "127.0.0.1:7001", "127.0.0.1:7000");
    config.useSingleServer().setAddress(RedisRunner.getDefaultRedisServerBindAddressAndPort());
    //        .addSlaveAddress("127.0.0.1:6389");
    return config;
}
Also used : Config(org.redisson.config.Config)

Example 27 with Config

use of org.redisson.config.Config in project redisson by redisson.

the class CommandHandlersTest method testDecoder.

@Test(expected = RedisException.class)
public void testDecoder() {
    redisson.getBucket("1234").set("1234");
    Config config = createConfig();
    config.setCodec(new ErrorsCodec());
    RedissonClient redisson = Redisson.create(config);
    redisson.getBucket("1234").get();
}
Also used : RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) Test(org.junit.Test)

Example 28 with Config

use of org.redisson.config.Config in project redisson by redisson.

the class BaseConcurrentTest method testMultiInstanceConcurrency.

protected void testMultiInstanceConcurrency(int iterations, final RedissonRunnable runnable) throws InterruptedException {
    ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
    NioEventLoopGroup group = new NioEventLoopGroup();
    final Map<Integer, RedissonClient> instances = new HashMap<Integer, RedissonClient>();
    for (int i = 0; i < iterations; i++) {
        Config config = createConfig();
        config.setEventLoopGroup(group);
        RedissonClient instance = Redisson.create(config);
        instances.put(i, instance);
    }
    long watch = System.currentTimeMillis();
    for (int i = 0; i < iterations; i++) {
        final int n = i;
        executor.execute(new Runnable() {

            @Override
            public void run() {
                RedissonClient redisson = instances.get(n);
                runnable.run(redisson);
            }
        });
    }
    executor.shutdown();
    Assert.assertTrue(executor.awaitTermination(RedissonRuntimeEnvironment.isTravis ? 10 : 3, TimeUnit.MINUTES));
    System.out.println("multi: " + (System.currentTimeMillis() - watch));
    executor = Executors.newCachedThreadPool();
    for (final RedissonClient redisson : instances.values()) {
        executor.execute(new Runnable() {

            @Override
            public void run() {
                redisson.shutdown();
            }
        });
    }
    group.shutdownGracefully();
    executor.shutdown();
    Assert.assertTrue(executor.awaitTermination(5, TimeUnit.MINUTES));
}
Also used : RedissonClient(org.redisson.api.RedissonClient) HashMap(java.util.HashMap) Config(org.redisson.config.Config) ExecutorService(java.util.concurrent.ExecutorService) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 29 with Config

use of org.redisson.config.Config in project redisson by redisson.

the class Redisson method create.

/**
     * Create sync/async Redisson instance with default config
     *
     * @return Redisson instance
     */
public static RedissonClient create() {
    Config config = new Config();
    config.useSingleServer().setAddress("127.0.0.1:6379");
    //        config.useClusterServers().addNodeAddress("127.0.0.1:7000");
    return create(config);
}
Also used : Config(org.redisson.config.Config)

Example 30 with Config

use of org.redisson.config.Config in project redisson by redisson.

the class RedissonSessionManager method start.

@Override
public void start() throws LifecycleException {
    Config config = null;
    try {
        config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
    } catch (IOException e) {
        // trying next format
        try {
            config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
        } catch (IOException e1) {
            log.error("Can't parse json config " + configPath, e);
            throw new LifecycleException("Can't parse yaml config " + configPath, e1);
        }
    }
    try {
        redisson = Redisson.create(config);
    } catch (Exception e) {
        throw new LifecycleException(e);
    }
    lifecycle.fireLifecycleEvent(START_EVENT, null);
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) Config(org.redisson.config.Config) IOException(java.io.IOException) File(java.io.File) LifecycleException(org.apache.catalina.LifecycleException) IOException(java.io.IOException)

Aggregations

Config (org.redisson.config.Config)68 Test (org.junit.Test)51 RedissonClient (org.redisson.api.RedissonClient)44 RedisProcess (org.redisson.RedisRunner.RedisProcess)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 IOException (java.io.IOException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 RedissonNodeConfig (org.redisson.config.RedissonNodeConfig)4 HashMap (java.util.HashMap)3 ExecutorService (java.util.concurrent.ExecutorService)3 Before (org.junit.Before)3 SerializationCodec (org.redisson.codec.SerializationCodec)3 File (java.io.File)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 LifecycleException (org.apache.catalina.LifecycleException)2 BeforeClass (org.junit.BeforeClass)2 BaseTest.createConfig (org.redisson.BaseTest.createConfig)2 RLock (org.redisson.api.RLock)2 JsonJacksonCodec (org.redisson.codec.JsonJacksonCodec)2