DATAREDIS-1030 - Refine RedisScript creation.
Allow RedisScript.of(…) creation from a Resource. Original Pull Request: #473
This commit is contained in:
committed by
Christoph Strobl
parent
ac4909f139
commit
85669e6e69
@@ -75,7 +75,7 @@ public class DefaultRedisScript<T> implements RedisScript<T>, InitializingBean {
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
public void afterPropertiesSet() {
|
||||
Assert.state(this.scriptSource != null, "Either script, script location," + " or script source is required");
|
||||
}
|
||||
|
||||
|
||||
@@ -15,15 +15,17 @@
|
||||
*/
|
||||
package org.springframework.data.redis.core.script;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A script to be executed using the <a href="https://redis.io/commands/eval">Redis scripting support</a> available as of
|
||||
* version 2.6
|
||||
* A script to be executed using the <a href="https://redis.io/commands/eval">Redis scripting support</a> available as
|
||||
* of version 2.6
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @param <T> The script result type. Should be one of Long, Boolean, List, or deserialized value type. Can be
|
||||
* {@litearl null} if the script returns a throw-away status (i.e "OK")
|
||||
*/
|
||||
@@ -80,4 +82,43 @@ public interface RedisScript<T> {
|
||||
|
||||
return new DefaultRedisScript(script, resultType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new {@link RedisScript} from {@link Resource}.
|
||||
*
|
||||
* @param resource must not be {@literal null}.
|
||||
* @return new instance of {@link RedisScript}.
|
||||
* @since 2.2
|
||||
*/
|
||||
static <T> RedisScript<T> of(Resource resource) {
|
||||
|
||||
Assert.notNull(resource, "Resource must not be null!");
|
||||
|
||||
DefaultRedisScript<T> script = new DefaultRedisScript<>();
|
||||
script.setLocation(resource);
|
||||
script.afterPropertiesSet();
|
||||
|
||||
return script;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new {@link RedisScript} from {@link Resource}.
|
||||
*
|
||||
* @param resource must not be {@literal null}.
|
||||
* @param resultType must not be {@literal null}.
|
||||
* @return new instance of {@link RedisScript}.
|
||||
* @since 2.2
|
||||
*/
|
||||
static <T> RedisScript<T> of(Resource resource, Class<T> resultType) {
|
||||
|
||||
Assert.notNull(resource, "Resource must not be null!");
|
||||
Assert.notNull(resultType, "ResultType must not be null!");
|
||||
|
||||
DefaultRedisScript<T> script = new DefaultRedisScript<>();
|
||||
script.setResultType(resultType);
|
||||
script.setLocation(resource);
|
||||
script.afterPropertiesSet();
|
||||
|
||||
return script;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user