Redis🔗
Installation🔗
Debain/Ubuntu
macOS
Setup🔗
Access Redis CLI : Connect to redis server🔗
Test Connection🔗
Set and Get Data: storing and retrieving key-value pairs🔗
Enabling Persistence🔗
Edit /etc/redis/redis.conf
- For RDB (snapshotting)
save 900 1 # Save if 1 key changes in 900 seconds
save 300 10 # Save if 10 keys change in 300 seconds
- For AOF (Append Only File)
Restart Redis
Security🔗
1. Set a Password🔗
Edit /etc/redis/redis.conf
2. Bind to Specific IP🔗
Edit /etc/redis/redis.conf
3. Disable Dangerous Commands🔗
4. Enable Firewall🔗
Essential Commands🔗
# set a key
SET mykey "Hello Redis"
# get a key
GET mykey
# delete a key
DEL mykey
# check if exists
EXISTS mykey
Data Types🔗
-
Lists
-
Sets
-
Hashes
-
Sorted Sets
Server Management🔗
Advanced Features🔗
Pub/Sub Messaging🔗
Transactions🔗
Use MULTI
and EXEC
for atomic operations
Lua Scripting🔗
Troubleshooting🔗
# view redis logs
sudo tail -f /var/log/redis/redis-server.log
# test connection
redis-cli -h 127.0.0.1 -p 6379 ping
# check memory usage
INFO memory