Skip to content

Instantly share code, notes, and snippets.

@mp911de
Created May 12, 2017 06:58
Show Gist options
  • Save mp911de/2c33e0445eb7955eafb5d485c990afa4 to your computer and use it in GitHub Desktop.
Save mp911de/2c33e0445eb7955eafb5d485c990afa4 to your computer and use it in GitHub Desktop.
import com.lambdaworks.redis.RedisClient;
import com.lambdaworks.redis.ScriptOutputType;
import com.lambdaworks.redis.api.StatefulRedisConnection;
import com.lambdaworks.redis.codec.ByteArrayCodec;
/**
* @author Mark Paluch
*/
public class EvalWithByteArrayCodec {
public static void main(String[] args) {
RedisClient client = RedisClient.create("redis://localhost");
StatefulRedisConnection<byte[], byte[]> connection = client.connect(ByteArrayCodec.INSTANCE);
byte[] keyOne = "one".getBytes();
byte[] keyTwo = "two".getBytes();
byte[] valueOne = "foo".getBytes();
byte[] valueTwo = "bar".getBytes();
connection.sync().set(keyOne, "foo".getBytes());
connection.sync().set(keyTwo, "bar".getBytes());
connection.sync().eval("redis.call(\"MSET\", KEYS[1], ARGV[1], KEYS[2], ARGV[2])", ScriptOutputType.VALUE,
new byte[][] { keyOne, keyTwo }, valueOne, valueTwo);
System.out.println(connection.sync().eval("return redis.call(\"MGET\", KEYS[1], KEYS[2])", ScriptOutputType.MULTI,
keyOne, keyTwo));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment