Skip to content

Commit

Permalink
Added example for topK
Browse files Browse the repository at this point in the history
  • Loading branch information
Ranjeet Singh committed Dec 20, 2023
1 parent 21e2a90 commit ab19331
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/test/java/io/redis/examples/TopKExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//EXAMPLE: topk_tutorial
//HIDE_START
package io.redis.examples;
//HIDE_END

//REMOVE_START
import org.junit.Test;
import redis.clients.jedis.UnifiedJedis;

import java.util.List;
//REMOVE_END

public class TopKExample {
@Test
public void run(){
//HIDE_START
UnifiedJedis unifiedJedis = new UnifiedJedis("redis://127.0.0.1:6379");
//HIDE_END

//REMOVE_START
unifiedJedis.del("bikes:keywords");
//REMOVE_END

//STEP_START topk
String res1 = unifiedJedis.topkReserve("bikes:keywords", 5L, 2000L, 7L, 0.925D);
System.out.println(res1); // >>> True

List<String> res2 = unifiedJedis.topkAdd("bikes:keywords",
"store",
"seat",
"handlebars",
"handles",
"pedals",
"tires",
"store",
"seat");

System.out.println(res2); // >>> [None, None, None, None, None, 'handlebars', None, None]

List<String> res3 = unifiedJedis.topkList("bikes:keywords");
System.out.println(res3); // >>> ['store', 'seat', 'pedals', 'tires', 'handles']

List<Boolean> res4 = unifiedJedis.topkQuery("bikes:keywords", "store", "handlebars");
System.out.println(res4); // >>> [1, 0]
//STEP_END
}
}

0 comments on commit ab19331

Please sign in to comment.