Skip to content

Commit

Permalink
Added Redis client (Jedis).
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Sep 6, 2015
1 parent 81e9864 commit 858431a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
10 changes: 9 additions & 1 deletion rapidoid-app/pom.xml
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -42,6 +43,13 @@
<artifactId>rapidoid-oauth</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.7.3</version>
</dependency>

<dependency>
<groupId>org.rapidoid</groupId>
<artifactId>rapidoid-test-appctx-helper</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions rapidoid-app/src/main/java/org/rapidoid/app/Dollar.java
Expand Up @@ -25,6 +25,8 @@
import org.rapidoid.sql.SQLAPI;
import org.rapidoid.util.U;

import redis.clients.jedis.Jedis;

/*
* #%L
* rapidoid-app
Expand Down Expand Up @@ -130,4 +132,8 @@ public DollarPage page(Object value) {
return page(value, Collections.EMPTY_MAP);
}

public final Jedis jedis() {
return JedisTool.get();
}

}
51 changes: 51 additions & 0 deletions rapidoid-app/src/main/java/org/rapidoid/app/JedisTool.java
@@ -0,0 +1,51 @@
package org.rapidoid.app;

/*
* #%L
* rapidoid-app
* %%
* Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;
import org.rapidoid.cls.Cls;
import org.rapidoid.config.Conf;
import org.rapidoid.util.U;

import redis.clients.jedis.Jedis;

@Authors("Nikolche Mihajlovski")
@Since("4.2.0")
public class JedisTool {

private static Jedis jedis;

public static Jedis get() {
if (jedis == null) {
String host = Conf.nested("redis", "host");
host = U.or(host, "localhost");

Object rport = Conf.nested("redis", "port");
int port = rport != null ? Cls.convert(rport, int.class) : 6379;

jedis = new Jedis(host, port);
}

return jedis;
}

}

0 comments on commit 858431a

Please sign in to comment.