Skip to content

Commit

Permalink
DOC-4440 added auth command examples using Jedis class (#4058)
Browse files Browse the repository at this point in the history
* DOC-4440 added placeholder for auth command examples

* DOC-4440 added auth command examples using Jedis class
  • Loading branch information
andy-stark-redis authored Jan 19, 2025
1 parent 8f8fe1f commit 607025d
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/test/java/io/redis/examples/CmdsCnxmgmtExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// EXAMPLE: cmds_cnxmgmt
// REMOVE_START
package io.redis.examples;

import org.junit.Assert;
import org.junit.Test;
// REMOVE_END

import redis.clients.jedis.Jedis;

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

// STEP_START auth1
// REMOVE_START
jedis.configSet("requirepass", "temp_pass");
// REMOVE_END
// Note: you must use the `Jedis` class rather than `UnifiedJedis`
// to access the `auth` commands.
String authResult1 = jedis.auth("default", "temp_pass");
System.out.println(authResult1); // >>> OK
// REMOVE_START
Assert.assertEquals("OK", authResult1);
jedis.configSet("requirepass", "");
// REMOVE_END
// STEP_END

// STEP_START auth2
// REMOVE_START
jedis.aclSetUser("test-user", "on", ">strong_password", "+acl");
// REMOVE_END
// Note: you must use the `Jedis` class rather than `UnifiedJedis`
// to access the `auth` commands.
String authResult2 = jedis.auth("test-user", "strong_password");
System.out.println(authResult2); // >>> OK
// REMOVE_START
Assert.assertEquals("OK", authResult2);
jedis.aclDelUser("test-user");
// REMOVE_END
// STEP_END

// HIDE_START
}
}
// HIDE_END

0 comments on commit 607025d

Please sign in to comment.