DATAREDIS-789 - Polishing.
Remove trailing whitespaces. Original pull request: #324.
This commit is contained in:
@@ -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<Boolean> script() {
|
||||
DefaultRedisScript<Boolean> redisScript = new DefaultRedisScript<Boolean>();
|
||||
@Bean
|
||||
public RedisScript<Boolean> script() {
|
||||
DefaultRedisScript<Boolean> redisScript = new DefaultRedisScript<Boolean>();
|
||||
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<Boolean> script;
|
||||
public boolean checkAndSet(String expectedValue, String newValue) {
|
||||
return redisTemplate.execute(script, Collections.singletonList("key"), expectedValue, newValue);
|
||||
}
|
||||
public class Example {
|
||||
@Autowired
|
||||
RedisScript<Boolean> 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 <<tx>> and <<pipeline>> 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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user