From 8d932cb8e8155d7b98b2508c7dbb7db4a65c8a73 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 21 Mar 2018 16:20:10 +0100 Subject: [PATCH] DATAREDIS-789 - Polishing. Remove trailing whitespaces. Original pull request: #324. --- .../asciidoc/reference/redis-scripting.adoc | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/asciidoc/reference/redis-scripting.adoc b/src/main/asciidoc/reference/redis-scripting.adoc index 3e2e93b21..21d9ea8a5 100644 --- a/src/main/asciidoc/reference/redis-scripting.adoc +++ b/src/main/asciidoc/reference/redis-scripting.adoc @@ -11,34 +11,34 @@ Here's an example that executes a common "check-and-set" scenario using a Lua sc [source,java] ---- -@Bean -public RedisScript script() { - DefaultRedisScript redisScript = new DefaultRedisScript(); +@Bean +public RedisScript script() { + DefaultRedisScript redisScript = new DefaultRedisScript(); redisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("META-INF/scripts/checkandset.lua"))); - redisScript.setResultType(Boolean.class); + redisScript.setResultType(Boolean.class); } ---- [source,java] ---- -public class Example { - @Autowired - RedisScript script; - public boolean checkAndSet(String expectedValue, String newValue) { - return redisTemplate.execute(script, Collections.singletonList("key"), expectedValue, newValue); - } +public class Example { + @Autowired + RedisScript script; + public boolean checkAndSet(String expectedValue, String newValue) { + return redisTemplate.execute(script, Collections.singletonList("key"), expectedValue, newValue); + } } ---- [source,lua] ---- - -- checkandset.lua - local current = redis.call('GET', KEYS[1]) - if current == ARGV[1] - then redis.call('SET', KEYS[1], ARGV[2]) - return true - end - return false +-- checkandset.lua +local current = redis.call('GET', KEYS[1]) +if current == ARGV[1] + then redis.call('SET', KEYS[1], ARGV[2]) + return true +end +return false ---- The XML above configures a `DefaultRedisScript` pointing to a file called `checkandset.lua`, which is expected to return a boolean value. The script `resultType` should be one of `Long`, `Boolean`, `List`, or deserialized value type. It can also be null if the script returns a throw-away status (i.e "OK"). It is ideal to configure a single instance of `DefaultRedisScript` in your application context to avoid re-calculation of the script's SHA1 on every script execution. @@ -47,4 +47,3 @@ The checkAndSet method above then executes th Scripts can be executed within a `SessionCallback` as part of a transaction or pipeline. See <> and <> for more information. The scripting support provided by Spring Data Redis also allows you to schedule Redis scripts for periodic execution using the Spring Task and Scheduler abstractions. See the `Spring Framework` documentation for more details. -