Skip to content

Commit

Permalink
RScript.scriptExists fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita committed Jul 25, 2015
1 parent 10ed742 commit f20d45b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 17 deletions.
27 changes: 27 additions & 0 deletions src/main/java/org/redisson/RedissonScript.java
Expand Up @@ -15,6 +15,7 @@
*/ */
package org.redisson; package org.redisson;


import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;


Expand Down Expand Up @@ -140,6 +141,32 @@ public Future<Void> scriptKillAsync(String key) {
return commandExecutor.writeAsync(key, RedisCommands.SCRIPT_KILL); return commandExecutor.writeAsync(key, RedisCommands.SCRIPT_KILL);
} }


@Override
public List<Boolean> scriptExists(String ... shaDigests) {
return commandExecutor.get(scriptExistsAsync(shaDigests));
}

@Override
public Future<List<Boolean>> scriptExistsAsync(final String ... shaDigests) {
return commandExecutor.writeAllAsync(RedisCommands.SCRIPT_EXISTS, new SlotCallback<List<Boolean>, List<Boolean>>() {
volatile List<Boolean> result = new ArrayList<Boolean>(shaDigests.length);
@Override
public synchronized void onSlotResult(List<Boolean> result) {
for (int i = 0; i < result.size(); i++) {
if (this.result.size() == i) {
this.result.add(false);
}
this.result.set(i, this.result.get(i) | result.get(i));
}
}

@Override
public List<Boolean> onFinish() {
return new ArrayList<Boolean>(result);
}
}, (Object[])shaDigests);
}

public List<Boolean> scriptExists(String key, String ... shaDigests) { public List<Boolean> scriptExists(String key, String ... shaDigests) {
return commandExecutor.get(scriptExistsAsync(key, shaDigests)); return commandExecutor.get(scriptExistsAsync(key, shaDigests));
} }
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/org/redisson/client/protocol/RedisCommands.java
Expand Up @@ -48,14 +48,14 @@ public interface RedisCommands {
RedisStrictCommand<Void> UNWATCH = new RedisStrictCommand<Void>("UNWATCH", new VoidReplayConvertor()); RedisStrictCommand<Void> UNWATCH = new RedisStrictCommand<Void>("UNWATCH", new VoidReplayConvertor());
RedisStrictCommand<Void> WATCH = new RedisStrictCommand<Void>("WATCH", new VoidReplayConvertor()); RedisStrictCommand<Void> WATCH = new RedisStrictCommand<Void>("WATCH", new VoidReplayConvertor());
RedisStrictCommand<Void> MULTI = new RedisStrictCommand<Void>("MULTI", new VoidReplayConvertor()); RedisStrictCommand<Void> MULTI = new RedisStrictCommand<Void>("MULTI", new VoidReplayConvertor());
RedisCommand<List<Object>> EXEC = new RedisCommand<List<Object>>("EXEC", new ObjectListReplayDecoder()); RedisCommand<List<Object>> EXEC = new RedisCommand<List<Object>>("EXEC", new ObjectListReplayDecoder<Object>());


RedisCommand<Long> SREM = new RedisCommand<Long>("SREM", 2, ValueType.OBJECTS); RedisCommand<Long> SREM = new RedisCommand<Long>("SREM", 2, ValueType.OBJECTS);
RedisCommand<Boolean> SADD = new RedisCommand<Boolean>("SADD", new BooleanAmountReplayConvertor(), 2, ValueType.OBJECTS); RedisCommand<Boolean> SADD = new RedisCommand<Boolean>("SADD", new BooleanAmountReplayConvertor(), 2, ValueType.OBJECTS);
RedisCommand<Boolean> SADD_SINGLE = new RedisCommand<Boolean>("SADD", new BooleanReplayConvertor(), 2); RedisCommand<Boolean> SADD_SINGLE = new RedisCommand<Boolean>("SADD", new BooleanReplayConvertor(), 2);
RedisCommand<Boolean> SREM_SINGLE = new RedisCommand<Boolean>("SREM", new BooleanReplayConvertor(), 2); RedisCommand<Boolean> SREM_SINGLE = new RedisCommand<Boolean>("SREM", new BooleanReplayConvertor(), 2);
RedisCommand<List<Object>> SMEMBERS = new RedisCommand<List<Object>>("SMEMBERS", new ObjectListReplayDecoder()); RedisCommand<List<Object>> SMEMBERS = new RedisCommand<List<Object>>("SMEMBERS", new ObjectListReplayDecoder<Object>());
RedisCommand<ListScanResult<Object>> SSCAN = new RedisCommand<ListScanResult<Object>>("SSCAN", new NestedMultiDecoder(new ObjectListReplayDecoder(), new ListScanResultReplayDecoder()), ValueType.MAP); RedisCommand<ListScanResult<Object>> SSCAN = new RedisCommand<ListScanResult<Object>>("SSCAN", new NestedMultiDecoder(new ObjectListReplayDecoder<Object>(), new ListScanResultReplayDecoder()), ValueType.MAP);
RedisCommand<Boolean> SISMEMBER = new RedisCommand<Boolean>("SISMEMBER", new BooleanReplayConvertor(), 2); RedisCommand<Boolean> SISMEMBER = new RedisCommand<Boolean>("SISMEMBER", new BooleanReplayConvertor(), 2);
RedisStrictCommand<Integer> SCARD = new RedisStrictCommand<Integer>("SCARD", new IntegerReplayConvertor()); RedisStrictCommand<Integer> SCARD = new RedisStrictCommand<Integer>("SCARD", new IntegerReplayConvertor());


Expand Down Expand Up @@ -84,22 +84,22 @@ public interface RedisCommands {


RedisCommand<Long> RPOP = new RedisCommand<Long>("RPOP"); RedisCommand<Long> RPOP = new RedisCommand<Long>("RPOP");
RedisCommand<Long> LPUSH = new RedisCommand<Long>("LPUSH"); RedisCommand<Long> LPUSH = new RedisCommand<Long>("LPUSH");
RedisCommand<List<Object>> LRANGE = new RedisCommand<List<Object>>("LRANGE", new ObjectListReplayDecoder()); RedisCommand<List<Object>> LRANGE = new RedisCommand<List<Object>>("LRANGE", new ObjectListReplayDecoder<Object>());
RedisCommand<Long> RPUSH = new RedisCommand<Long>("RPUSH", 2, ValueType.OBJECTS); RedisCommand<Long> RPUSH = new RedisCommand<Long>("RPUSH", 2, ValueType.OBJECTS);
RedisCommand<Boolean> RPUSH_BOOLEAN = new RedisCommand<Boolean>("RPUSH", new TrueReplayConvertor(), 2, ValueType.OBJECTS); RedisCommand<Boolean> RPUSH_BOOLEAN = new RedisCommand<Boolean>("RPUSH", new TrueReplayConvertor(), 2, ValueType.OBJECTS);


RedisStrictCommand<String> SCRIPT_LOAD = new RedisStrictCommand<String>("SCRIPT", "LOAD", new StringDataDecoder()); RedisStrictCommand<String> SCRIPT_LOAD = new RedisStrictCommand<String>("SCRIPT", "LOAD", new StringDataDecoder());
RedisStrictCommand<Boolean> SCRIPT_KILL = new RedisStrictCommand<Boolean>("SCRIPT", "KILL", new BooleanReplayConvertor()); RedisStrictCommand<Boolean> SCRIPT_KILL = new RedisStrictCommand<Boolean>("SCRIPT", "KILL", new BooleanReplayConvertor());
RedisStrictCommand<Boolean> SCRIPT_FLUSH = new RedisStrictCommand<Boolean>("SCRIPT", "FLUSH", new BooleanReplayConvertor()); RedisStrictCommand<Boolean> SCRIPT_FLUSH = new RedisStrictCommand<Boolean>("SCRIPT", "FLUSH", new BooleanReplayConvertor());
RedisStrictCommand<List<Object>> SCRIPT_EXISTS = new RedisStrictCommand<List<Object>>("SCRIPT", "EXISTS", new ObjectListReplayDecoder(), new BooleanReplayConvertor()); RedisStrictCommand<List<Boolean>> SCRIPT_EXISTS = new RedisStrictCommand<List<Boolean>>("SCRIPT", "EXISTS", new ObjectListReplayDecoder<Boolean>(), new BooleanReplayConvertor());


RedisStrictCommand<Boolean> EVAL_BOOLEAN = new RedisStrictCommand<Boolean>("EVAL", new BooleanReplayConvertor()); RedisStrictCommand<Boolean> EVAL_BOOLEAN = new RedisStrictCommand<Boolean>("EVAL", new BooleanReplayConvertor());
RedisStrictCommand<String> EVAL_STRING = new RedisStrictCommand<String>("EVAL", new StringReplayDecoder()); RedisStrictCommand<String> EVAL_STRING = new RedisStrictCommand<String>("EVAL", new StringReplayDecoder());
RedisStrictCommand<Long> EVAL_INTEGER = new RedisStrictCommand<Long>("EVAL"); RedisStrictCommand<Long> EVAL_INTEGER = new RedisStrictCommand<Long>("EVAL");
RedisCommand<List<Object>> EVAL_LIST = new RedisCommand<List<Object>>("EVAL", new ObjectListReplayDecoder()); RedisCommand<List<Object>> EVAL_LIST = new RedisCommand<List<Object>>("EVAL", new ObjectListReplayDecoder<Object>());
RedisCommand<Object> EVAL_OBJECT = new RedisCommand<Object>("EVAL"); RedisCommand<Object> EVAL_OBJECT = new RedisCommand<Object>("EVAL");
RedisCommand<Object> EVAL_MAP_VALUE = new RedisCommand<Object>("EVAL", ValueType.MAP_VALUE); RedisCommand<Object> EVAL_MAP_VALUE = new RedisCommand<Object>("EVAL", ValueType.MAP_VALUE);
RedisCommand<List<Object>> EVAL_MAP_VALUE_LIST = new RedisCommand<List<Object>>("EVAL", new ObjectListReplayDecoder(), ValueType.MAP_VALUE); RedisCommand<List<Object>> EVAL_MAP_VALUE_LIST = new RedisCommand<List<Object>>("EVAL", new ObjectListReplayDecoder<Object>(), ValueType.MAP_VALUE);


RedisStrictCommand<Long> INCR = new RedisStrictCommand<Long>("INCR"); RedisStrictCommand<Long> INCR = new RedisStrictCommand<Long>("INCR");
RedisStrictCommand<Long> INCRBY = new RedisStrictCommand<Long>("INCRBY"); RedisStrictCommand<Long> INCRBY = new RedisStrictCommand<Long>("INCRBY");
Expand All @@ -118,12 +118,12 @@ public interface RedisCommands {
RedisStrictCommand<String> HINCRBYFLOAT = new RedisStrictCommand<String>("HINCRBYFLOAT"); RedisStrictCommand<String> HINCRBYFLOAT = new RedisStrictCommand<String>("HINCRBYFLOAT");
RedisCommand<MapScanResult<Object, Object>> HSCAN = new RedisCommand<MapScanResult<Object, Object>>("HSCAN", new NestedMultiDecoder(new ObjectMapReplayDecoder(), new MapScanResultReplayDecoder()), ValueType.MAP); RedisCommand<MapScanResult<Object, Object>> HSCAN = new RedisCommand<MapScanResult<Object, Object>>("HSCAN", new NestedMultiDecoder(new ObjectMapReplayDecoder(), new MapScanResultReplayDecoder()), ValueType.MAP);
RedisCommand<Map<Object, Object>> HGETALL = new RedisCommand<Map<Object, Object>>("HGETALL", new ObjectMapReplayDecoder(), ValueType.MAP); RedisCommand<Map<Object, Object>> HGETALL = new RedisCommand<Map<Object, Object>>("HGETALL", new ObjectMapReplayDecoder(), ValueType.MAP);
RedisCommand<List<Object>> HVALS = new RedisCommand<List<Object>>("HVALS", new ObjectListReplayDecoder(), ValueType.MAP_VALUE); RedisCommand<List<Object>> HVALS = new RedisCommand<List<Object>>("HVALS", new ObjectListReplayDecoder<Object>(), ValueType.MAP_VALUE);
RedisCommand<Boolean> HEXISTS = new RedisCommand<Boolean>("HEXISTS", new BooleanReplayConvertor(), 2, ValueType.MAP_KEY); RedisCommand<Boolean> HEXISTS = new RedisCommand<Boolean>("HEXISTS", new BooleanReplayConvertor(), 2, ValueType.MAP_KEY);
RedisStrictCommand<Integer> HLEN = new RedisStrictCommand<Integer>("HLEN", new IntegerReplayConvertor()); RedisStrictCommand<Integer> HLEN = new RedisStrictCommand<Integer>("HLEN", new IntegerReplayConvertor());
RedisCommand<Set<Object>> HKEYS = new RedisCommand<Set<Object>>("HKEYS", new ObjectSetReplayDecoder(), ValueType.MAP_KEY); RedisCommand<Set<Object>> HKEYS = new RedisCommand<Set<Object>>("HKEYS", new ObjectSetReplayDecoder(), ValueType.MAP_KEY);
RedisCommand<String> HMSET = new RedisCommand<String>("HMSET", new StringReplayDecoder(), 1, ValueType.MAP); RedisCommand<String> HMSET = new RedisCommand<String>("HMSET", new StringReplayDecoder(), 1, ValueType.MAP);
RedisCommand<List<Object>> HMGET = new RedisCommand<List<Object>>("HMGET", new ObjectListReplayDecoder(), 2, ValueType.MAP_KEY, ValueType.MAP_VALUE); RedisCommand<List<Object>> HMGET = new RedisCommand<List<Object>>("HMGET", new ObjectListReplayDecoder<Object>(), 2, ValueType.MAP_KEY, ValueType.MAP_VALUE);
RedisCommand<Object> HGET = new RedisCommand<Object>("HGET", 2, ValueType.MAP_KEY, ValueType.MAP_VALUE); RedisCommand<Object> HGET = new RedisCommand<Object>("HGET", 2, ValueType.MAP_KEY, ValueType.MAP_VALUE);
RedisCommand<Long> HDEL = new RedisStrictCommand<Long>("HDEL", 2, ValueType.MAP_KEY); RedisCommand<Long> HDEL = new RedisStrictCommand<Long>("HDEL", 2, ValueType.MAP_KEY);


Expand Down
Expand Up @@ -21,16 +21,16 @@


import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;


public class ObjectListReplayDecoder implements MultiDecoder<List<Object>> { public class ObjectListReplayDecoder<T> implements MultiDecoder<List<T>> {


@Override @Override
public Object decode(ByteBuf buf, State state) { public Object decode(ByteBuf buf, State state) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }


@Override @Override
public List<Object> decode(List<Object> parts, State state) { public List<T> decode(List<Object> parts, State state) {
return parts; return (List<T>) parts;
} }


@Override @Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/redisson/core/RScript.java
Expand Up @@ -55,6 +55,8 @@ public RedisCommand<?> getCommand() {


String scriptLoad(String luaScript); String scriptLoad(String luaScript);


List<Boolean> scriptExists(String ... shaDigests);

void scriptKill(); void scriptKill();


void scriptFlush(); void scriptFlush();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/redisson/core/RScriptAsync.java
Expand Up @@ -32,6 +32,8 @@ public interface RScriptAsync {


Future<String> scriptLoadAsync(String luaScript); Future<String> scriptLoadAsync(String luaScript);


Future<List<Boolean>> scriptExistsAsync(String ... shaDigests);

Future<Void> scriptKillAsync(); Future<Void> scriptKillAsync();


} }
10 changes: 5 additions & 5 deletions src/test/java/org/redisson/RedissonScriptTest.java
Expand Up @@ -32,16 +32,16 @@ public void testEvalAsync() {
@Test @Test
public void testScriptExists() { public void testScriptExists() {
RScript s = redisson.getScript(); RScript s = redisson.getScript();
String r = s.scriptLoad(null, "return redis.call('get', 'foo')"); String r = s.scriptLoad("return redis.call('get', 'foo')");
Assert.assertEquals("282297a0228f48cd3fc6a55de6316f31422f5d17", r); Assert.assertEquals("282297a0228f48cd3fc6a55de6316f31422f5d17", r);


List<Boolean> r1 = s.scriptExists(null, r); List<Boolean> r1 = s.scriptExists(r);
Assert.assertEquals(1, r1.size()); Assert.assertEquals(1, r1.size());
Assert.assertTrue(r1.get(0)); Assert.assertTrue(r1.get(0));


s.scriptFlush(); s.scriptFlush();


List<Boolean> r2 = s.scriptExists(null, r); List<Boolean> r2 = s.scriptExists(r);
Assert.assertEquals(1, r2.size()); Assert.assertEquals(1, r2.size());
Assert.assertFalse(r2.get(0)); Assert.assertFalse(r2.get(0));
} }
Expand Down Expand Up @@ -83,7 +83,7 @@ public void testScriptLoadAsync() {
@Test @Test
public void testEvalSha() { public void testEvalSha() {
RScript s = redisson.getScript(); RScript s = redisson.getScript();
String res = s.scriptLoad(null, "return redis.call('get', 'foo')"); String res = s.scriptLoad("return redis.call('get', 'foo')");
Assert.assertEquals("282297a0228f48cd3fc6a55de6316f31422f5d17", res); Assert.assertEquals("282297a0228f48cd3fc6a55de6316f31422f5d17", res);


redisson.getBucket("foo").set("bar"); redisson.getBucket("foo").set("bar");
Expand All @@ -94,7 +94,7 @@ public void testEvalSha() {
@Test @Test
public void testEvalshaAsync() { public void testEvalshaAsync() {
RScript s = redisson.getScript(); RScript s = redisson.getScript();
String res = s.scriptLoad(null, "return redis.call('get', 'foo')"); String res = s.scriptLoad("return redis.call('get', 'foo')");
Assert.assertEquals("282297a0228f48cd3fc6a55de6316f31422f5d17", res); Assert.assertEquals("282297a0228f48cd3fc6a55de6316f31422f5d17", res);


redisson.getBucket("foo").set("bar"); redisson.getBucket("foo").set("bar");
Expand Down

0 comments on commit f20d45b

Please sign in to comment.