Skip to content

Commit 978fe3a

Browse files
committed
add example to documentation and clean excess var
1 parent c48b7d8 commit 978fe3a

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

modules/jooby-jedis/src/main/java/org/jooby/jedis/RedisSentinel.java

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,11 @@
209209
import org.jooby.Env;
210210
import redis.clients.jedis.JedisSentinelPool;
211211

212-
import java.net.URI;
213212
import java.util.HashSet;
214213
import java.util.List;
215214
import java.util.Set;
216215
import java.util.concurrent.TimeUnit;
217216

218-
import static java.util.Objects.requireNonNull;
219-
220217
/**
221218
* Created by
222219
*
@@ -225,11 +222,6 @@
225222
*/
226223
public class RedisSentinel extends Redis {
227224

228-
/**
229-
* Database name.
230-
*/
231-
private String name = "db";
232-
233225
/**
234226
* <p>
235227
* Creates a new {@link RedisSentinel} instance and connect to the provided database. Please note, the
@@ -246,32 +238,29 @@ public class RedisSentinel extends Redis {
246238
* application.conf
247239
*
248240
* <pre>
249-
* db1 = ""redis://localhost:6379""
250241
* jedis.sentinel.hosts = ["localhost:26379"]
251242
* jedis.sentinel.master = "master"
252243
* jedis.password = ""
253244
* </pre>
254245
*
255-
* Default database name is: <code>db</code>
256-
*
257-
* @param name A database name.
246+
* Example:
247+
* <pre>
248+
* try (Jedis redis = request.require(JedisSentinelPool.class).getResource()) {
249+
* System.out.println( redis.set("test", "this is work") );
250+
* System.out.println( redis.get("test");
251+
* } catch (Exception e) {
252+
* e.printStackTrace();
253+
* }
254+
* </pre>
258255
*/
259-
public RedisSentinel(final String name) {
260-
this.name = requireNonNull(name, "A db property is required.");
261-
}
262-
263-
public RedisSentinel() {
264-
this("db");
265-
}
266256

267257
@Override
268258
public void configure(Env env, Config config, Binder binder) {
269259
/**
270260
* Pool
271261
*/
272-
GenericObjectPoolConfig poolConfig = poolConfig(config, name);
262+
GenericObjectPoolConfig poolConfig = poolConfig(config.getConfig("jedis.pool"));
273263
int timeout = (int) config.getDuration("jedis.timeout", TimeUnit.MILLISECONDS);
274-
URI uri = URI.create(config.getString(name));
275264

276265
List<String> hosts = config.getStringList("jedis.sentinel.hosts");
277266
if (hosts.size() < 1) throw new IllegalArgumentException("List of hosts (jedis.sentinel.hosts) can not be empty");
@@ -287,12 +276,12 @@ public void configure(Env env, Config config, Binder binder) {
287276
pool = new JedisSentinelPool(MASTER_NAME, sentinels, poolConfig, timeout);
288277
}
289278

290-
RedisProvider provider = new RedisProvider(pool, uri, poolConfig);
279+
RedisProvider provider = new RedisProvider(pool, null, poolConfig);
291280
env.onStart(provider::start);
292281
env.onStop(provider::stop);
293282

294283
Env.ServiceKey serviceKey = env.serviceKey();
295-
serviceKey.generate(JedisSentinelPool.class, name, k -> binder.bind(k).toInstance(pool));
284+
serviceKey.generate(JedisSentinelPool.class, "db", k -> binder.bind(k).toInstance(pool));
296285
}
297286

298287
}

0 commit comments

Comments
 (0)