Skip to content

Commit

Permalink
Added Java code snippet for bitmap (#3687)
Browse files Browse the repository at this point in the history
* 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
3 people authored Jan 16, 2024
1 parent c467015 commit 118cc1d
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/test/java/io/redis/examples/BitMapsExample.java
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
}
}

0 comments on commit 118cc1d

Please sign in to comment.