0
0
Redisquery~5 mins

Authentication with requirepass in Redis

Choose your learning style9 modes available
Introduction
Authentication with requirepass helps protect your Redis database by requiring a password before allowing access.
When you want to prevent unauthorized users from accessing your Redis data.
When your Redis server is exposed to a network and needs basic security.
When multiple users share the same Redis server and you want to control access.
When you want to add a simple layer of protection without complex security setups.
Syntax
Redis
requirepass yourpassword
This command is set in the Redis configuration file (redis.conf) or via CONFIG SET.
Replace 'yourpassword' with a strong password you choose.
Examples
Sets the password to 'mysecret123' for Redis authentication.
Redis
requirepass mysecret123
Sets the password dynamically without restarting Redis.
Redis
CONFIG SET requirepass anotherPass!
Sample Program
This example shows setting the password in the config file, then authenticating with AUTH command before running other commands.
Redis
# In redis.conf file
requirepass mysecret123

# Then connect with redis-cli
redis-cli
> AUTH mysecret123
OK
> SET key1 "hello"
OK
> GET key1
"hello"
OutputSuccess
Important Notes
After setting requirepass, clients must use AUTH before running commands.
If you forget the password, you must edit redis.conf and restart Redis to reset it.
Using requirepass is a simple security step but consider additional security for production.
Summary
requirepass sets a password to protect Redis access.
Clients must authenticate with AUTH command using the password.
Password can be set in redis.conf or dynamically with CONFIG SET.