Skip to content

Commit 607025d

Browse files
DOC-4440 added auth command examples using Jedis class (#4058)
* DOC-4440 added placeholder for auth command examples * DOC-4440 added auth command examples using Jedis class
1 parent 8f8fe1f commit 607025d

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// EXAMPLE: cmds_cnxmgmt
2+
// REMOVE_START
3+
package io.redis.examples;
4+
5+
import org.junit.Assert;
6+
import org.junit.Test;
7+
// REMOVE_END
8+
9+
import redis.clients.jedis.Jedis;
10+
11+
// HIDE_START
12+
public class CmdsCnxmgmtExample {
13+
@Test
14+
public void run() {
15+
// HIDE_END
16+
Jedis jedis = new Jedis("redis://localhost:6379");
17+
18+
// STEP_START auth1
19+
// REMOVE_START
20+
jedis.configSet("requirepass", "temp_pass");
21+
// REMOVE_END
22+
// Note: you must use the `Jedis` class rather than `UnifiedJedis`
23+
// to access the `auth` commands.
24+
String authResult1 = jedis.auth("default", "temp_pass");
25+
System.out.println(authResult1); // >>> OK
26+
// REMOVE_START
27+
Assert.assertEquals("OK", authResult1);
28+
jedis.configSet("requirepass", "");
29+
// REMOVE_END
30+
// STEP_END
31+
32+
// STEP_START auth2
33+
// REMOVE_START
34+
jedis.aclSetUser("test-user", "on", ">strong_password", "+acl");
35+
// REMOVE_END
36+
// Note: you must use the `Jedis` class rather than `UnifiedJedis`
37+
// to access the `auth` commands.
38+
String authResult2 = jedis.auth("test-user", "strong_password");
39+
System.out.println(authResult2); // >>> OK
40+
// REMOVE_START
41+
Assert.assertEquals("OK", authResult2);
42+
jedis.aclDelUser("test-user");
43+
// REMOVE_END
44+
// STEP_END
45+
46+
// HIDE_START
47+
}
48+
}
49+
// HIDE_END

0 commit comments

Comments
 (0)