The Wayback Machine - https://web.archive.org/web/20220712140412/https://github.com/laravel/framework/discussions/38737
Skip to content

Specify username for Redis authentication #38737

Answered by xelab
game5413 asked this question in Ideas
Specify username for Redis authentication #38737
Sep 9, 2021 · 3 answers · 9 replies

I was wondering, can laravel specify Redis user that want authenticated from .env ? i'm using phpredis and lookup into documentation link it can be specified using array or array associative. Maybe something like REDIS_USERNAME on .env side, i'd tried that already, it seem that illuminate/redis only using password for authentication $client->auth($config['password']);.

Hello, I'm waiting this feature too but FYI there is a workaround, in your database.php file you can set this :
'redis' => [ 'default' => [ ..., 'password' => ['user' => 'user', 'pass' => 'pass'], ... ], ]

Replies

3 suggested answers
·
9 replies

Hello, I'm waiting this feature too but FYI there is a workaround, in your database.php file you can set this :
'redis' => [ 'default' => [ ..., 'password' => ['user' => 'user', 'pass' => 'pass'], ... ], ]

2 replies
@barismar

Thanks!
This is a workaround but I found a better way to do that, you can add context in your database config starting from Laravel 6.
Screen Shot 2021-11-08 at 14 20 33
It only works if the version of your phpredis extension is >= 5.3.0, to check the version please go to this Link.

@xelab

You're right, that's a more elegant way!

Answer selected by game5413

@xelab I'm already tried that, but still the user that used for authenticated still not changed. My first schema create new user with name admin for administration, and create another user with name myuser for general task, and deleting the default user. After set config from database.php still not changed (and got an error because user default already deleted), i think because Laravel not passing username like the example from phpredis. It only using SETNAME for changing display name on CLIENT LIST, so not changing the user name that we using for authentication. In below i'm attaching the illuminate/redis code when creating connection.

image

Because the first schema was failed, for now i'm just create username admin for administration and login by that user and change for permission the default user.

7 replies
@xelab

That's weird, I have no problem with my solution, as I put in "$config['password'] the whole associative array with user and pass, I guess params are passed like PHPRedis wants it. It's important to put an associative array, I tried with a simple array and that didn't work.

@game5413

Ahh.. i see, i'm trying with just an regular array back then, but i don't think that so selective before because the example provided the regular array method and associative array. I not try yet using associative array, but you already did. Thanks for the information @xelab .

@game5413

And yeah, it just like weird if we put an array into password it seem like have two password 😅

You can use php-redis to authenticate using ACL (username and password combo)

Following example works for me using AWS MemoryDB for redis.

$redis = new \Redis();
$redis->connect('tsl://ENDPOINT', 6379);
$redis->rawCommand("auth", "USERNAME", "PASSWORD");
echo $redis->set("test","2");
echo $redis->get("test");
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
4 participants