/** @see DATAREDIS-524 */ @Test public void testCreateSentinelWithPassword() { pool = new DefaultLettucePool( new RedisSentinelConfiguration("mymaster", Collections.singleton("host:1234"))); pool.setClientResources(LettuceTestClientResources.getSharedClientResources()); pool.setPassword("foo"); pool.afterPropertiesSet(); RedisURI redisUri = (RedisURI) getField(pool.getClient(), "redisURI"); assertThat(redisUri.getPassword(), is(equalTo(pool.getPassword().toCharArray()))); }
public static void main(String[] args) { // Syntax: redis://[password@]host[:port][/databaseNumber] RedisClient redisClient = new RedisClient(RedisURI.create("redis://password@localhost:6379/0")); RedisConnection<String, String> connection = redisClient.connect(); System.out.println("Connected to Redis"); connection.set("foo", "bar"); String value = connection.get("foo"); System.out.println(value); connection.close(); redisClient.shutdown(); }
@Override public ActorSystem buildActorSystem(Config config) throws Exception { // start redis final int redisPort = (config.hasPath("components.redis.port")) ? config.getInt("components.redis.port") : RedisURI.DEFAULT_REDIS_PORT; final String redisLogLevel = config.hasPath("components.redis.log-level") ? config.getString("components.redis.log-level") : "verbose"; String logBase = System.getenv("LOG_BASE"); if (StringUtils.isBlank(logBase)) logBase = System.getenv("TEMP"); final String redisLogFile = config.hasPath("components.redis.log-file") ? config.getString("components.redis.log-file") : logBase + "\\redis.log"; final String redisPidFile = config.hasPath("components.redis.pid-file") ? config.getString("components.redis.pid-file") : logBase + "\\redis.pid"; try { this.redis = RedisServer.builder() .redisExecProvider(RedisExecProvider.defaultProvider()) .port(redisPort) .setting("loglevel " + redisLogLevel) .setting("logfile " + redisLogFile) .setting("pidfile " + redisPidFile) .build(); } catch (Exception ex) { this.logger.error("Fail to build redis server.", ex); throw new IllegalStateException("Fail to build redis server.", ex); } new Thread() { @Override public void run() { try { redis.start(); logger.info("Started redis server on {} port", redisPort); } catch (Exception ex) { logger.error("Fail to start redis server.", ex); // @TODO Use future to stop the actor system at this point. } } }.start(); // create redis client String redisUri = "redis://" + this.getAddress().getHostAddress() + ":" + redisPort + "/0"; this.redisClient = new RedisClient(RedisURI.create(redisUri)); ActorSystem system = ActorSystem.create(this.getClusterName(), config); Camel camel = CamelExtension.get(system); this.baseUrl = "http://" + this.getAddress().getHostAddress() + ":" + this.getHttpPort() + "/" + this.getApplicationName(); String uri = "jetty:" + this.baseUrl; String recorderKeyBase = this.getClusterName() + ":" + "words"; ActorRef recordingService = system.actorOf( Props.create(RecordingService.class, recorderKeyBase, this.redisClient), "recorderService"); String tracerKey = this.getClusterName() + ":trace:node:1"; ActorRef traceLogService = system.actorOf( Props.create(TraceLogService.class, tracerKey, this.redisClient, this.jacksonMapper), "traceLogService"); ActorRef analysisService = system.actorOf( Props.create(AnalysisService.class, recordingService, traceLogService), "analysisService"); String pathBase = "akka.tcp://" + this.getClusterName() + "@" + this.getAddress().getHostAddress() + ":"; SimpleRoutingMap<String> routingMap = new SimpleRoutingMap<String>(); routingMap.putPath(new Key<String>("2551"), pathBase + "2551/user/analysisService"); routingMap.putPath(new Key<String>("2552"), pathBase + "2552/user/analysisService"); ActorRef httpClerk = system.actorOf(Props.create(WebService.class, uri, routingMap), "httpClerk"); Future<ActorRef> activationFuture = camel.activationFutureFor( httpClerk, new Timeout(Duration.create(10, TimeUnit.SECONDS)), system.dispatcher()); return system; }