org.redisson.config.TransportMode Java Examples

The following examples show how to use org.redisson.config.TransportMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Settings.java    From kyoko with MIT License 6 votes vote down vote up
@JsonIgnore
public Config configureRedis() throws URISyntaxException {
    var redisConfig = new Config();
    var redis = new URI(Settings.instance().redisUrl());
    if (!redis.getScheme().equals("redis") && !redis.getScheme().equals("rediss")) {
        throw new IllegalArgumentException("Invalid scheme for Redis connection URI!");
    }

    var database = redis.getPath() == null || redis.getPath().isBlank() ? 0
            : Integer.parseUnsignedInt(redis.getPath().substring(1));

    redisConfig.setTransportMode(Epoll.isAvailable() ? TransportMode.EPOLL : TransportMode.NIO);
    redisConfig.setNettyThreads(16);
    redisConfig.useSingleServer()
            .setAddress(redis.getScheme() + "://"
                    + requireNonNullElse(redis.getHost(), "localhost") + ":"
                    + requireNonNullElse(redis.getPort(), 6379))
            .setDatabase(database)
            .setPassword(redis.getUserInfo());

    return redisConfig;
}
 
Example #2
Source File: BaseRedissonSessionManager.java    From redis-session-manager with Apache License 2.0 5 votes vote down vote up
@Override
protected final RedisSessionClient buildClient() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    Config config = new Config()
        .setCodec(new ContextClassloaderSerializationCodec(getContainerClassLoader()))
        .setTransportMode(isEpollSupported() ? TransportMode.EPOLL : TransportMode.NIO);
    return new RedissonSessionClient(configure(config));
}
 
Example #3
Source File: RedissonProperties.java    From redisson-spring-boot-starter with GNU Lesser General Public License v3.0 4 votes vote down vote up
public TransportMode getTransportMode() {
    return transportMode;
}
 
Example #4
Source File: RedissonProperties.java    From redisson-spring-boot-starter with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setTransportMode(TransportMode transportMode) {
    this.transportMode = transportMode;
}
 
Example #5
Source File: MasterSlaveConnectionManager.java    From redisson with Apache License 2.0 4 votes vote down vote up
protected MasterSlaveConnectionManager(Config cfg, UUID id) {
    this.id = id.toString();
    Version.logVersion();

    if (cfg.getTransportMode() == TransportMode.EPOLL) {
        if (cfg.getEventLoopGroup() == null) {
            this.group = new EpollEventLoopGroup(cfg.getNettyThreads(), new DefaultThreadFactory("redisson-netty"));
        } else {
            this.group = cfg.getEventLoopGroup();
        }

        this.socketChannelClass = EpollSocketChannel.class;
        if (PlatformDependent.isAndroid()) {
            this.resolverGroup = DefaultAddressResolverGroup.INSTANCE;
        } else {
            this.resolverGroup = cfg.getAddressResolverGroupFactory().create(EpollDatagramChannel.class, DnsServerAddressStreamProviders.platformDefault());
        }
    } else if (cfg.getTransportMode() == TransportMode.KQUEUE) {
        if (cfg.getEventLoopGroup() == null) {
            this.group = new KQueueEventLoopGroup(cfg.getNettyThreads(), new DefaultThreadFactory("redisson-netty"));
        } else {
            this.group = cfg.getEventLoopGroup();
        }

        this.socketChannelClass = KQueueSocketChannel.class;
        if (PlatformDependent.isAndroid()) {
            this.resolverGroup = DefaultAddressResolverGroup.INSTANCE;
        } else {
            this.resolverGroup = cfg.getAddressResolverGroupFactory().create(KQueueDatagramChannel.class, DnsServerAddressStreamProviders.platformDefault());
        }
    } else {
        if (cfg.getEventLoopGroup() == null) {
            this.group = new NioEventLoopGroup(cfg.getNettyThreads(), new DefaultThreadFactory("redisson-netty"));
        } else {
            this.group = cfg.getEventLoopGroup();
        }

        this.socketChannelClass = NioSocketChannel.class;
        if (PlatformDependent.isAndroid()) {
            this.resolverGroup = DefaultAddressResolverGroup.INSTANCE;
        } else {
            this.resolverGroup = cfg.getAddressResolverGroupFactory().create(NioDatagramChannel.class, DnsServerAddressStreamProviders.platformDefault());
        }
    }
    
    if (cfg.getExecutor() == null) {
        int threads = Runtime.getRuntime().availableProcessors() * 2;
        if (cfg.getThreads() != 0) {
            threads = cfg.getThreads();
        }
        executor = Executors.newFixedThreadPool(threads, new DefaultThreadFactory("redisson"));
    } else {
        executor = cfg.getExecutor();
    }

    this.cfg = cfg;
    this.codec = cfg.getCodec();
    this.commandExecutor = new CommandSyncService(this);
}