-
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.
Added Java code snippet for bitmap (#3687)
* Add bitmap example * Change class name * Add assert for res3 and res4 * Update BitMapsExample.java * Format spaces in BitMapsExample.java --------- Co-authored-by: Ranjeet Singh <[email protected]> Co-authored-by: M Sazzadul Hoque <[email protected]>
- Loading branch information
1 parent
c467015
commit 118cc1d
Showing
1 changed file
with
47 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,47 @@ | ||
// EXAMPLE: bitmap_tutorial | ||
// HIDE_START | ||
package io.redis.examples; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import redis.clients.jedis.UnifiedJedis; | ||
|
||
public class BitMapsExample { | ||
|
||
@Test | ||
public void run() { | ||
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); | ||
// HIDE_END | ||
|
||
// REMOVE_START | ||
jedis.del("pings:2024-01-01-00:00"); | ||
// REMOVE_END | ||
|
||
|
||
// STEP_START ping | ||
boolean res1 = jedis.setbit("pings:2024-01-01-00:00", 123, true); | ||
System.out.println(res1); // >>> false | ||
|
||
boolean res2 = jedis.getbit("pings:2024-01-01-00:00", 123); | ||
System.out.println(res2); // >>> true | ||
|
||
boolean res3 = jedis.getbit("pings:2024-01-01-00:00", 456); | ||
System.out.println(res3); // >>> false | ||
// STEP_END | ||
|
||
// REMOVE_START | ||
Assert.assertFalse(res1); | ||
Assert.assertTrue(res2); | ||
Assert.assertFalse(res3); | ||
// REMOVE_END | ||
|
||
// STEP_START bitcount | ||
long res4 = jedis.bitcount("pings:2024-01-01-00:00"); | ||
System.out.println(res4); // >>> 1 | ||
// STEP_END | ||
|
||
// REMOVE_START | ||
Assert.assertEquals(res4, 1); | ||
// REMOVE_END | ||
} | ||
} |