Skip to content

Instantly share code, notes, and snippets.

@andreybleme
Last active March 28, 2020 06:25
Show Gist options
  • Save andreybleme/2b6378a5ea04c3bdb6abff203ed49ce3 to your computer and use it in GitHub Desktop.
Save andreybleme/2b6378a5ea04c3bdb6abff203ed49ce3 to your computer and use it in GitHub Desktop.
andreybleme.com | Creating page visit statistics using Redis
import java.util.Random;
import redis.clients.jedis.Jedis;
public class StoringAccessDataUsingBitmap {
public void store(long userCode, String date) {
Jedis jedis = new Jedis("localhost");
String key = String.format("access:%s", date);
jedis.setbit(key, userCode, true);
}
public static void main(String[] args) {
int amountOfUsers = 500;
int amountOfAccess = 1000;
int amountOfDays = 30;
Random random = new Random();
StoringAccessDataUsingBitmap acesso = new StoringAccessDataUsingBitmap();
for(Integer numero = 1; numero <= amountOfAccess; numero++) {
long user = (random.nextInt(amountOfUsers) + 1);
String date = String.format("%02d/11/2018", (random.nextInt(amountOfDays) + 1));
acesso.store(user, date);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment