-
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.
- Loading branch information
Ranjeet Singh
committed
Dec 20, 2023
1 parent
21e2a90
commit ab19331
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: 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 | ||
} | ||
} |