Skip to content

Commit

Permalink
Merge pull request #12 from kenti-lan/master
Browse files Browse the repository at this point in the history
1.add redis password support;
2.if there is redis key prefix difined,it will cause issue when split the redis key.
  • Loading branch information
jlinn committed May 5, 2016
2 parents 1d0a919 + 1e3658a commit e1fe249
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ org.quartz.jobStore.class = net.joelinn.quartz.jobstore.RedisJobStore
# set the Redis host (required)
org.quartz.jobStore.host = <your redis host or a comma-delimited list of host:port if clustered use is desired>
# set the redis password (optional, defaults null)
org.quartz.jobStore.password = <your redis password>
# set the redis port (optional, defaults to 6379)
org.quartz.jobStore.port = <your redis port>
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/net/joelinn/quartz/jobstore/RedisJobStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public class RedisJobStore implements JobStore {
*/
protected int port = 6379;

/**
* Redis password
*/
protected String password;

/**
* Redis database
*/
Expand Down Expand Up @@ -127,12 +132,12 @@ public void initialize(ClassLoadHelper loadHelper, SchedulerSignaler signaler) t
if (logger.isDebugEnabled()) {
logger.debug("Instantiating JedisSentinelPool using master " + masterGroupName + " and hosts " + host);
}
jedisPool = new JedisSentinelPool(masterGroupName, nodesAsStrings, jedisPoolConfig, Protocol.DEFAULT_TIMEOUT, null, database);
jedisPool = new JedisSentinelPool(masterGroupName, nodesAsStrings, jedisPoolConfig, Protocol.DEFAULT_TIMEOUT, password, database);
} else {
if (logger.isDebugEnabled()) {
logger.debug("Instantiating JedisPool using host " + host + " and port " + port);
}
jedisPool = new JedisPool(jedisPoolConfig, host, port, Protocol.DEFAULT_TIMEOUT, null, database);
jedisPool = new JedisPool(jedisPoolConfig, host, port, Protocol.DEFAULT_TIMEOUT, password, database);
}
storage = new RedisStorage(redisSchema, mapper, signaler, instanceId, lockTimeout);
}
Expand Down Expand Up @@ -1187,6 +1192,14 @@ public void setMasterGroupName(String masterGroupName) {
this.masterGroupName = masterGroupName;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

/**
* Inform the <code>JobStore</code> of the Scheduler instance's Id,
* prior to initialize being invoked.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ protected String addPrefix(String key){
* @return a list comprised of the split parts of the given string
*/
protected List<String> split(final String string){
return Arrays.asList(string.split(delimiter));
if (null!=prefix){
//remove prefix before split
return Arrays.asList(string.substring(prefix.length()).split(delimiter));
}else{
return Arrays.asList(string.split(delimiter));
}

}
}

0 comments on commit e1fe249

Please sign in to comment.