-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: M Sazzadul Hoque <[email protected]>
- Loading branch information
1 parent
337d8ca
commit b90fd0b
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// EXAMPLE: bitfield_tutorial | ||
// REMOVE_START | ||
package io.redis.examples; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import java.util.List; | ||
// REMOVE_END | ||
|
||
// HIDE_START | ||
import redis.clients.jedis.UnifiedJedis; | ||
// HIDE_END | ||
|
||
// HIDE_START | ||
public class BitfieldExample { | ||
@Test | ||
public void run() { | ||
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); | ||
// HIDE_END | ||
|
||
//REMOVE_START | ||
// Clear any keys here before using them in tests. | ||
jedis.del("bike:1:stats"); | ||
//REMOVE_END | ||
|
||
// STEP_START bf | ||
List<Long> res1 = jedis.bitfield("bike:1:stats", "SET", "u32", "#0", "1000"); | ||
System.out.println(res1); // >>> [0] | ||
|
||
List<Long> res2 = jedis.bitfield("bike:1:stats", "INCRBY", "u32", "#0", "-50", "INCRBY", "u32", "#1", "1"); | ||
System.out.println(res2); // >>> [950, 1] | ||
|
||
List<Long> res3 = jedis.bitfield("bike:1:stats", "INCRBY", "u32", "#0", "500", "INCRBY", "u32", "#1", "1"); | ||
System.out.println(res3); // >>> [1450, 2] | ||
|
||
List<Long> res4 = jedis.bitfield("bike:1:stats", "GET", "u32", "#0", "GET", "u32", "#1"); | ||
System.out.println(res4); // >>> [1450, 2] | ||
// STEP_END | ||
|
||
// Tests for 'bf' step. | ||
// REMOVE_START | ||
Assert.assertEquals("[0]", res1.toString()); | ||
Assert.assertEquals("[950, 1]", res2.toString()); | ||
Assert.assertEquals("[1450, 2]", res3.toString()); | ||
Assert.assertEquals("[1450, 2]", res4.toString()); | ||
// REMOVE_END | ||
|
||
// HIDE_START | ||
jedis.close(); | ||
} | ||
} | ||
// HIDE_END |