|
15 | 15 | */
|
16 | 16 | package org.springframework.data.redis.core.script;
|
17 | 17 |
|
| 18 | +import org.springframework.core.io.Resource; |
18 | 19 | import org.springframework.lang.Nullable;
|
19 | 20 | import org.springframework.util.Assert;
|
20 | 21 |
|
21 | 22 | /**
|
22 |
| - * A script to be executed using the <a href="https://redis.io/commands/eval">Redis scripting support</a> available as of |
23 |
| - * version 2.6 |
| 23 | + * A script to be executed using the <a href="https://redis.io/commands/eval">Redis scripting support</a> available as |
| 24 | + * of version 2.6 |
24 | 25 | *
|
25 | 26 | * @author Jennifer Hickey
|
26 | 27 | * @author Christoph Strobl
|
| 28 | + * @author Mark Paluch |
27 | 29 | * @param <T> The script result type. Should be one of Long, Boolean, List, or deserialized value type. Can be
|
28 | 30 | * {@litearl null} if the script returns a throw-away status (i.e "OK")
|
29 | 31 | */
|
@@ -80,4 +82,43 @@ static <T> RedisScript of(String script, Class<T> resultType) {
|
80 | 82 |
|
81 | 83 | return new DefaultRedisScript(script, resultType);
|
82 | 84 | }
|
| 85 | + |
| 86 | + /** |
| 87 | + * Creates new {@link RedisScript} from {@link Resource}. |
| 88 | + * |
| 89 | + * @param resource must not be {@literal null}. |
| 90 | + * @return new instance of {@link RedisScript}. |
| 91 | + * @since 2.2 |
| 92 | + */ |
| 93 | + static <T> RedisScript<T> of(Resource resource) { |
| 94 | + |
| 95 | + Assert.notNull(resource, "Resource must not be null!"); |
| 96 | + |
| 97 | + DefaultRedisScript<T> script = new DefaultRedisScript<>(); |
| 98 | + script.setLocation(resource); |
| 99 | + script.afterPropertiesSet(); |
| 100 | + |
| 101 | + return script; |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Creates new {@link RedisScript} from {@link Resource}. |
| 106 | + * |
| 107 | + * @param resource must not be {@literal null}. |
| 108 | + * @param resultType must not be {@literal null}. |
| 109 | + * @return new instance of {@link RedisScript}. |
| 110 | + * @since 2.2 |
| 111 | + */ |
| 112 | + static <T> RedisScript<T> of(Resource resource, Class<T> resultType) { |
| 113 | + |
| 114 | + Assert.notNull(resource, "Resource must not be null!"); |
| 115 | + Assert.notNull(resultType, "ResultType must not be null!"); |
| 116 | + |
| 117 | + DefaultRedisScript<T> script = new DefaultRedisScript<>(); |
| 118 | + script.setResultType(resultType); |
| 119 | + script.setLocation(resource); |
| 120 | + script.afterPropertiesSet(); |
| 121 | + |
| 122 | + return script; |
| 123 | + } |
83 | 124 | }
|
0 commit comments