Search in sources :

Example 91 with Config

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

the class RedissonCache method setRedissonConfig.

public void setRedissonConfig(String config) {
    Config cfg;
    try {
        InputStream is = getClass().getClassLoader().getResourceAsStream(config);
        cfg = Config.fromYAML(is);
    } catch (IOException e) {
        throw new IllegalArgumentException("Can't parse config", e);
    }
    RedissonClient redisson = Redisson.create(cfg);
    mapCache = getMapCache(id, redisson);
    if (maxSize > 0) {
        mapCache.setMaxSize(maxSize);
    }
}
Also used : RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 92 with Config

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

the class RedissonClusterConnectionTest method before.

@BeforeClass
public static void before() throws FailedToStartRedisException, IOException, InterruptedException {
    RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave();
    ClusterRunner clusterRunner = new ClusterRunner().addNode(master1, slave1).addNode(master2, slave2).addNode(master3, slave3);
    process = clusterRunner.run();
    Config config = new Config();
    config.useClusterServers().setSubscriptionMode(SubscriptionMode.SLAVE).setLoadBalancer(new RandomLoadBalancer()).addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    redisson = Redisson.create(config);
    connection = new RedissonClusterConnection(redisson);
}
Also used : Config(org.redisson.config.Config) RedisRunner(org.redisson.RedisRunner) ClusterRunner(org.redisson.ClusterRunner) RandomLoadBalancer(org.redisson.connection.balancer.RandomLoadBalancer) BeforeClass(org.junit.BeforeClass)

Example 93 with Config

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

the class RedissonExample method main.

public static void main(String[] args) {
    Config config = new Config();
    // 
    config.useSingleServer().setAddress(// 
    "redis://localhost:6379").setDatabase(0);
    RedissonClient client = Redisson.create(config);
    RList<Object> list = client.getList("test:list");
    list.add("A");
    list.add("B");
    list.add("C");
    System.out.println("size:" + list.size());
    for (Object element : list) {
        System.out.println(element);
    }
    list.delete();
    client.shutdown();
}
Also used : RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config)

Example 94 with Config

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

the class RedisStore method initialize.

/**
 * Initialize the data store by reading the credentials, setting the client's
 * properties up and reading the mapping file. Initialize is called when then
 * the call to {@link org.apache.gora.store.DataStoreFactory#createDataStore}
 * is made.
 *
 * @param keyClass Gora's key class
 * @param persistentClass Persistent class
 * @param properties Configurations for the data store
 * @throws org.apache.gora.util.GoraException Unexpected exception during initialization
 */
@Override
public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) throws GoraException {
    try {
        super.initialize(keyClass, persistentClass, properties);
        InputStream mappingStream;
        if (properties.containsKey(XML_MAPPING_DEFINITION)) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("{} = {}", XML_MAPPING_DEFINITION, properties.getProperty(XML_MAPPING_DEFINITION));
            }
            mappingStream = IOUtils.toInputStream(properties.getProperty(XML_MAPPING_DEFINITION), (Charset) null);
        } else {
            mappingStream = getClass().getClassLoader().getResourceAsStream(getConf().get(PARSE_MAPPING_FILE_KEY, DEFAULT_MAPPING_FILE));
        }
        RedisMappingBuilder mappingBuilder = new RedisMappingBuilder(this);
        mapping = mappingBuilder.readMapping(mappingStream);
        Config config = new Config();
        String storage = getConf().get(GORA_REDIS_STORAGE, properties.getProperty(GORA_REDIS_STORAGE));
        mode = StorageMode.valueOf(storage);
        String modeString = getConf().get(GORA_REDIS_MODE, properties.getProperty(GORA_REDIS_MODE));
        ServerMode connectionMode = ServerMode.valueOf(modeString);
        String name = getConf().get(GORA_REDIS_MASTERNAME, properties.getProperty(GORA_REDIS_MASTERNAME));
        String readm = getConf().get(GORA_REDIS_READMODE, properties.getProperty(GORA_REDIS_READMODE));
        // Override address in tests
        String[] hosts = getConf().get(GORA_REDIS_ADDRESS, properties.getProperty(GORA_REDIS_ADDRESS)).split(",");
        for (int indexHosts = 0; indexHosts < hosts.length; indexHosts++) {
            hosts[indexHosts] = PREFIX + hosts[indexHosts];
        }
        switch(connectionMode) {
            case SINGLE:
                config.useSingleServer().setAddress(hosts[0]).setDatabase(mapping.getDatabase());
                break;
            case CLUSTER:
                config.useClusterServers().addNodeAddress(hosts);
                break;
            case REPLICATED:
                config.useReplicatedServers().addNodeAddress(hosts).setDatabase(mapping.getDatabase());
                break;
            case SENTINEL:
                config.useSentinelServers().setMasterName(name).setReadMode(ReadMode.valueOf(readm)).addSentinelAddress(hosts);
                break;
            default:
                throw new AssertionError(connectionMode.name());
        }
        redisInstance = Redisson.create(config);
        if (autoCreateSchema && !schemaExists()) {
            createSchema();
        }
    } catch (IOException ex) {
        throw new GoraException(ex);
    }
}
Also used : GoraException(org.apache.gora.util.GoraException) InputStream(java.io.InputStream) Config(org.redisson.config.Config) Charset(java.nio.charset.Charset) IOException(java.io.IOException) ServerMode(org.apache.gora.redis.util.ServerMode)

Example 95 with Config

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

the class RedissonTwoLockedThread method before.

@Before
public void before() throws IOException, InterruptedException {
    if (RedissonRuntimeEnvironment.isTravis) {
        RedisRunner.startDefaultRedisServerInstance();
        redisson = createInstance();
    }
    Config config = BaseTest.createConfig();
    config.setCodec(codec);
    redisson = Redisson.create(config);
}
Also used : Config(org.redisson.config.Config) Before(org.junit.Before)

Aggregations

Config (org.redisson.config.Config)182 Test (org.junit.jupiter.api.Test)109 RedissonClient (org.redisson.api.RedissonClient)69 RedisProcess (org.redisson.RedisRunner.RedisProcess)52 RandomLoadBalancer (org.redisson.connection.balancer.RandomLoadBalancer)33 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)30 ClusterProcesses (org.redisson.ClusterRunner.ClusterProcesses)23 IOException (java.io.IOException)22 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)17 RedisRunner (org.redisson.RedisRunner)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)15 BaseTest (org.redisson.BaseTest)15 RandomString (net.bytebuddy.utility.RandomString)14 URL (java.net.URL)12 RedisClientConfig (org.redisson.client.RedisClientConfig)12 Test (org.junit.Test)11 RLock (org.redisson.api.RLock)10 RedissonNodeConfig (org.redisson.config.RedissonNodeConfig)10 CountDownLatch (java.util.concurrent.CountDownLatch)9