Last active
May 31, 2016 21:47
-
-
Save jpe42/3f99095e1addac8f6e4afd7dbe9ec2ee to your computer and use it in GitHub Desktop.
Jedipus BITFIELD Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BITFIELD command taken from http://redis.io/commands/BITFIELD | |
// BITFIELD mykey INCRBY i5 100 1 GET u4 0 | |
final CmdByteArray<long[]> bitfieldCmd = CmdByteArray.startBuilding(Cmds.BITFIELD, 9) | |
.addSlotKey("mykey") | |
.addSubCmd(Cmds.BITFIELD_INCRBY, "i5", "100", "1") | |
.addSubCmd(Cmds.BITFIELD_GET, "u4", "0").create(); | |
try (final RedisClient client = | |
RedisClientFactory.startBuilding().create(Node.create("localhost", 6379))) { | |
// never auto boxed | |
final long[] reply = client.sendDirectPrimArray(bitfieldCmd); | |
// [1, 0] | |
System.out.println(Arrays.toString(reply)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BITFIELD command taken from http://redis.io/commands/BITFIELD | |
// BITFIELD mykey incrby u2 100 1 OVERFLOW SAT incrby u2 102 1 | |
final CmdByteArray<long[]> cmd = CmdByteArray.startBuilding(Cmds.BITFIELD, 12) | |
.addSlotKey("mykey") | |
.addSubCmd(Cmds.BITFIELD_INCRBY, "u2", "100", "1") | |
.addSubCmd(Cmds.BITFIELD_OVERFLOW, Cmds.BITFIELD_SAT.name(), Cmds.BITFIELD_INCRBY.name(), "u2", "102", "1") | |
.create(); | |
try (final RedisClusterExecutor rce = | |
RedisClusterExecutor.startBuilding(Node.create("localhost", 7000)).create()) { | |
rce.acceptPipelinedTransaction(cmd.getSlot(), pipeline -> { | |
final FutureReply<long[]> fr1 = pipeline.sendDirectPrimArray(cmd); | |
final FutureReply<long[]> fr2 = pipeline.sendDirectPrimArray(cmd); | |
final FutureReply<long[]> fr3 = pipeline.sendDirectPrimArray(cmd); | |
final FutureReply<long[]> fr4 = pipeline.sendDirectPrimArray(cmd); | |
// Use bulk exec reply. long arrays are never auto boxed. | |
for (final long[] reply : pipeline.primArrayExecSync().get()) { | |
System.out.println(Arrays.toString(reply)); | |
} | |
// OR use individual replies. Both are backed by the same long[]'s. | |
// pipeline.primArrayExecSync(); | |
// [1, 1] | |
System.out.println(Arrays.toString(fr1.get())); | |
// [2, 2] | |
System.out.println(Arrays.toString(fr2.get())); | |
// [3, 3] | |
System.out.println(Arrays.toString(fr3.get())); | |
// [0, 3] | |
System.out.println(Arrays.toString(fr4.get())); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment