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

Merge doc tests into main branch to keep in-sync with the code #3861

Merged
merged 26 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1578b98
Fix search_quickstart example
uglide May 17, 2023
50544dc
Add data_class step to SearchQuickstartExample
uglide May 18, 2023
a0043ff
Update examples with new bikes and align to new tutorial
elena-kolevska Jul 4, 2023
c5dd771
Fixes doctests for search tutorial
elena-kolevska Jul 4, 2023
2ba7bdb
Small fixes doctests
elena-kolevska Jul 4, 2023
5b0a7f8
Updates search tutorial doc examples to new format and data
elena-kolevska Jul 5, 2023
dd76c48
Merge branch 'master' into emb-examples
elena-kolevska Jul 5, 2023
ec0e1a3
Fix formatting in doc tests
uglide Jul 18, 2023
983b677
Add Hashes and String Example (#3477)
bsbodden Jul 20, 2023
4ddc215
Add Geospatial data type example (#3487)
bsbodden Aug 8, 2023
d8f4153
Merge branch 'master' into emb-examples
sazzad16 Dec 6, 2023
0526f6c
Added example Java code snippets for Streams (#3641)
Harsh4902 Dec 6, 2023
ccf74cf
Java example code snippets for T-Digest and TopK (#3660)
Ranjeet0611 Dec 29, 2023
cea57ff
Create Java code snippets for sets redis#3626 (#3661)
suraj11chauhan Jan 2, 2024
da8e25c
Create Java code snippets for count min sketch (#3644)
Harsh4902 Jan 13, 2024
7878e46
Added Java code snippets for Bloom #3630 (#3671)
Ranjeet0611 Jan 13, 2024
783f92e
Added java code snippet for hyperloglog (#3674)
Ranjeet0611 Jan 13, 2024
b21daab
Added Java code snippets for cuckoo filters (#3679)
Ranjeet0611 Jan 13, 2024
fbed166
Create Java code snippet for lists #3625 (#3677)
suraj11chauhan Jan 13, 2024
c467015
Create Java code snippet for sorted sets (#3680)
Harsh4902 Jan 16, 2024
118cc1d
Added Java code snippet for bitmap (#3687)
Ranjeet0611 Jan 16, 2024
ced33a9
Merge branch 'master' into emb-examples
sazzad16 Jan 17, 2024
5d58ae6
Merge branch 'master' into emb-examples
sazzad16 Jan 17, 2024
f217596
Merge branch 'master' into emb-examples
sazzad16 Feb 27, 2024
79d7ec7
Merge branch 'master' into emb-examples
uglide Jun 12, 2024
4035a46
Merge branch 'master' into emb-examples
uglide Jun 18, 2024
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
}
}
49 changes: 49 additions & 0 deletions src/test/java/io/redis/examples/BloomFilterExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// EXAMPLE: bf_tutorial

// HIDE_START
package io.redis.examples;

import redis.clients.jedis.UnifiedJedis;
import org.junit.Test;
import org.junit.Assert;
import java.util.List;

public class BloomFilterExample {

@Test
public void run() {
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379");
// HIDE_END

// REMOVE_START
jedis.del("bikes:models");
// REMOVE_END

// STEP_START bloom
String res1 = jedis.bfReserve("bikes:models", 0.01, 1000);
System.out.println(res1); // >>> OK

// REMOVE_START
Assert.assertEquals("OK", res1);
// REMOVE_END

boolean res2 = jedis.bfAdd("bikes:models", "Smoky Mountain Striker");
System.out.println(res2); // >>> True

boolean res3 = jedis.bfExists("bikes:models", "Smoky Mountain Striker");
System.out.println(res3); // >>> True

List<Boolean> res4 = jedis.bfMAdd("bikes:models",
"Rocky Mountain Racer",
"Cloudy City Cruiser",
"Windy City Wippet");
System.out.println(res4); // >>> [True, True, True]

List<Boolean> res5 = jedis.bfMExists("bikes:models",
"Rocky Mountain Racer",
"Cloudy City Cruiser",
"Windy City Wippet");
System.out.println(res5); // >>> [True, True, True]
// STEP_END
}
}
49 changes: 49 additions & 0 deletions src/test/java/io/redis/examples/CMSExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//EXAMPLE: cms_tutorial
//HIDE_START
package io.redis.examples;
//HIDE_END

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

import java.util.HashMap;
import java.util.List;
import java.util.Map;
//REMOVE_END

public class CMSExample {

@Test
public void run() {

//HIDE_START
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379");
//HIDE_END

//REMOVE_START
jedis.del("bikes:profit");
//REMOVE_END

//STEP_START cms
String res1 = jedis.cmsInitByProb("bikes:profit", 0.001d, 0.002d);
System.out.println(res1); // >>> OK

long res2 = jedis.cmsIncrBy("bikes:profit", "Smoky Mountain Striker", 100L);
System.out.println(res2); // >>> 100

List<Long> res3 = jedis.cmsIncrBy("bikes:profit", new HashMap<String, Long>() {{
put("Rocky Mountain Racer", 200L);
put("Cloudy City Cruiser", 150L);
}});
System.out.println(res3); // >>> [200, 150]

List<Long> res4 = jedis.cmsQuery("bikes:profit", "Smoky Mountain Striker");
System.out.println(res4); // >>> [100]

Map<String, Object> res5 = jedis.cmsInfo("bikes:profit");
System.out.println(res5.get("width") + " " + res5.get("depth") + " " + res5.get("count")); // >>> 2000 9 450
//STEP_END
}

}
45 changes: 45 additions & 0 deletions src/test/java/io/redis/examples/CuckooFilterExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// EXAMPLE: cuckoo_tutorial

// HIDE_START
package io.redis.examples;

import org.junit.Assert;
import org.junit.Test;
import redis.clients.jedis.UnifiedJedis;

public class CuckooFilterExample {
@Test
public void run() {
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379");
// HIDE_END

// REMOVE_START
jedis.del("bikes:models");
// REMOVE_END

// STEP_START cuckoo
String res1 = jedis.cfReserve("bikes:models", 1000000);
System.out.println(res1); // >>> OK

// REMOVE_START
Assert.assertEquals(res1, "OK");
// REMOVE_END

boolean res2 = jedis.cfAdd("bikes:models", "Smoky Mountain Striker");
System.out.println(res2); // >>> True

boolean res3 = jedis.cfExists("bikes:models", "Smoky Mountain Striker");
System.out.println(res3); // >>> True

boolean res4 = jedis.cfExists("bikes:models", "Terrible Bike Name");
System.out.println(res4); // >>> False

boolean res5 = jedis.cfDel("bikes:models", "Smoky Mountain Striker");
System.out.println(res5); // >>> True

// REMOVE_START
Assert.assertTrue(res5);
// REMOVE_END
// STEP_END
}
}
60 changes: 60 additions & 0 deletions src/test/java/io/redis/examples/GeoExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//EXAMPLE: geo_tutorial
package io.redis.examples;

// REMOVE_START
import org.junit.Test;
// REMOVE_END
import redis.clients.jedis.GeoCoordinate;
import redis.clients.jedis.UnifiedJedis;
import redis.clients.jedis.args.GeoUnit;
import redis.clients.jedis.resps.GeoRadiusResponse;

import java.util.List;
import java.util.stream.Collectors;

import static org.junit.Assert.assertEquals;

public class GeoExample {
@Test
public void run() {
try (UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379")) {
// REMOVE_START
jedis.del("bikes:rentable");
// REMOVE_END

// STEP_START geoadd
long res1 = jedis.geoadd("bikes:rentable", -122.27652, 37.805186, "station:1");
System.out.println(res1); // 1

long res2 = jedis.geoadd("bikes:rentable", -122.2674626, 37.8062344, "station:2");
System.out.println(res2); // 1

long res3 = jedis.geoadd("bikes:rentable", -122.2469854, 37.8104049, "station:3");
System.out.println(res2); // 1
// STEP_END

// REMOVE_START
assertEquals(1, res1);
assertEquals(1, res1);
assertEquals(1, res1);
// REMOVE_END

// STEP_START geosearch
List<GeoRadiusResponse> res4 = jedis.geosearch(
"bikes:rentable",
new GeoCoordinate(-122.27652, 37.805186),
5,
GeoUnit.KM
);
List<String> members = res4.stream() //
.map(GeoRadiusResponse::getMemberByString) //
.collect(Collectors.toList());
System.out.println(members); // [station:1, station:2, station:3]
// STEP_END

// REMOVE_START
assertEquals("[station:1, station:2, station:3]", members.toString());
// REMOVE_END
}
}
}
101 changes: 101 additions & 0 deletions src/test/java/io/redis/examples/HashExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//EXAMPLE: hash_tutorial
package io.redis.examples;

import redis.clients.jedis.UnifiedJedis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
//REMOVE_START
import org.junit.Test;
import static org.junit.Assert.assertEquals;
//REMOVE_END

public class HashExample {
@Test
public void run() {
try (UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379")) {
// REMOVE_START
jedis.del("bike:1", "bike:1:stats");
// REMOVE_END

// STEP_START set_get_all
Map<String, String> bike1 = new HashMap<>();
bike1.put("model", "Deimos");
bike1.put("brand", "Ergonom");
bike1.put("type", "Enduro bikes");
bike1.put("price", "4972");

Long res1 = jedis.hset("bike:1", bike1);
System.out.println(res1); // 4

String res2 = jedis.hget("bike:1", "model");
System.out.println(res2); // Deimos

String res3 = jedis.hget("bike:1", "price");
System.out.println(res3); // 4972

Map<String, String> res4 = jedis.hgetAll("bike:1");
System.out.println(res4); // {type=Enduro bikes, brand=Ergonom, price=4972, model=Deimos}
// STEP_END

// REMOVE_START
assertEquals(4, res1.longValue());
assertEquals("Deimos", res2);
assertEquals("4972", res3);
assertEquals("Deimos", res4.get("model"));
assertEquals("Ergonom", res4.get("brand"));
assertEquals("Enduro bikes", res4.get("type"));
assertEquals("4972", res4.get("price"));
// REMOVE_END

// STEP_START hmget
List<String> res5 = jedis.hmget("bike:1", "model", "price");
System.out.println(res5); // [Deimos, 4972]
// STEP_END

// REMOVE_START
assert res5.toString().equals("[Deimos, 4972]");
// REMOVE_END

// STEP_START hincrby
Long res6 = jedis.hincrBy("bike:1", "price", 100);
System.out.println(res6); // 5072
Long res7 = jedis.hincrBy("bike:1", "price", -100);
System.out.println(res7); // 4972
// STEP_END

// REMOVE_START
assertEquals(5072, res6.longValue());
assertEquals(4972, res7.longValue());
// REMOVE_END

// STEP_START incrby_get_mget
Long res8 = jedis.hincrBy("bike:1:stats", "rides", 1);
System.out.println(res8); // 1
Long res9 = jedis.hincrBy("bike:1:stats", "rides", 1);
System.out.println(res9); // 2
Long res10 = jedis.hincrBy("bike:1:stats", "rides", 1);
System.out.println(res10); // 3
Long res11 = jedis.hincrBy("bike:1:stats", "crashes", 1);
System.out.println(res11); // 1
Long res12 = jedis.hincrBy("bike:1:stats", "owners", 1);
System.out.println(res12); // 1
String res13 = jedis.hget("bike:1:stats", "rides");
System.out.println(res13); // 3
List<String> res14 = jedis.hmget("bike:1:stats", "crashes", "owners");
System.out.println(res14); // [1, 1]
// STEP_END

// REMOVE_START
assertEquals(1, res8.longValue());
assertEquals(2, res9.longValue());
assertEquals(3, res10.longValue());
assertEquals(1, res11.longValue());
assertEquals(1, res12.longValue());
assertEquals("3", res13);
assertEquals("[1, 1]", res14.toString());
// REMOVE_END
}
}
}
41 changes: 41 additions & 0 deletions src/test/java/io/redis/examples/HyperLogLogExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// EXAMPLE: hll_tutorial
package io.redis.examples;

import org.junit.Assert;
import org.junit.Test;
import redis.clients.jedis.UnifiedJedis;

public class HyperLogLogExample {

@Test
public void run() {
// HIDE_START
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379");
// HIDE_END

// REMOVE_START
jedis.del("bikes", "commuter_bikes", "all_bikes");
// REMOVE_END

// STEP_START pfadd
long res1 = jedis.pfadd("bikes", "Hyperion", "Deimos", "Phoebe", "Quaoar");
System.out.println(res1); // >>> 1

long res2 = jedis.pfcount("bikes");
System.out.println(res2); // >>> 4

long res3 = jedis.pfadd("commuter_bikes", "Salacia", "Mimas", "Quaoar");
System.out.println(res3); // >>> 1

String res4 = jedis.pfmerge("all_bikes", "bikes", "commuter_bikes");
System.out.println(res4); // >>> OK

// REMOVE_START
Assert.assertEquals("OK", res4);
// REMOVE_END

long res5 = jedis.pfcount("all_bikes");
System.out.println(res5); // >>> 6
// STEP_END
}
}
Loading
Loading