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);
}
}
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);
}
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();
}
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);
}
}
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);
}
Aggregations