Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Java code snippet for bitmap #3687

Merged
merged 5 commits into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading