Skip to content

Commit

Permalink
DOC-4102 INCR command example (#3946)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-stark-redis authored Sep 18, 2024
1 parent 933db73 commit bda181c
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/test/java/io/redis/examples/CmdsStringExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// EXAMPLE: cmds_string
// REMOVE_START
package io.redis.examples;

import org.junit.Assert;
import org.junit.Test;

// REMOVE_END
// HIDE_START
import redis.clients.jedis.UnifiedJedis;
// HIDE_END

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

//REMOVE_START
// Clear any keys here before using them in tests.
jedis.del("mykey");
//REMOVE_END
// HIDE_END

// STEP_START incr
String incrResult1 = jedis.set("mykey", "10");
System.out.println(incrResult1); // >>> OK

long incrResult2 = jedis.incr("mykey");
System.out.println(incrResult2); // >>> 11

String incrResult3 = jedis.get("mykey");
System.out.println(incrResult3); // >>> 11
// STEP_END

// Tests for 'incr' step.
// REMOVE_START
Assert.assertEquals("OK", incrResult1);
Assert.assertEquals(11, incrResult2);
Assert.assertEquals("11", incrResult3);
jedis.del("mykey");
// REMOVE_END

// HIDE_START
}
}
// HIDE_END

0 comments on commit bda181c

Please sign in to comment.