Skip to content

Commit

Permalink
DOC-4440 added auth command examples using Jedis class
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-stark-redis committed Jan 17, 2025
1 parent df729f9 commit 8e17365
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/test/java/io/redis/examples/CmdsCnxmgmtExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,45 @@
// 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

// Not currently supported by Jedis.

// 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

// Not currently supported by Jedis.

// 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
Expand Down

0 comments on commit 8e17365

Please sign in to comment.