Redis Quick Setup Guide
1. Installing Redis
For Ubuntu/Debian:
sudo apt update && sudo apt install redis redis-tools
Verify Installation:
redis-cli -h <redis_host> -p <redis_port> PING
2. Managing Redis Service
sudo systemctl start redis # Start Redis
sudo systemctl enable redis # Enable Redis on boot
sudo systemctl status redis # Check Redis status
3. Configuring Redis
Edit Redis configuration file:
sudo nano /etc/redis/redis.conf
- Set a password:
requirepass yourpassword
- Change the bind address if needed.
Restart Redis after changes:
sudo systemctl restart redis
4. Flushing Redis Database
redis-cli FLUSHALL # Flush all databases
redis-cli FLUSHDB # Flush the current database
5. Basic Redis Commands
redis-cli SET key "value" # Set a key-value pair
redis-cli GET key # Retrieve value of a key
redis-cli DEL key # Delete a key
redis-cli KEYS * # List all keys
redis-cli EXISTS key # Check if a key exists
redis-cli TTL key # Check time-to-live for a key
redis-cli INCR counter # Increment a key's value
redis-cli DECR counter # Decrement a key's value
6. Installing RedisInsight (Redis GUI)
Download and install RedisInsight:
wget https://downloads.redisinsight.redis.com/latest/redisinsight-linux64.tar.gz
mkdir redisinsight && tar -xvzf redisinsight-linux64.tar.gz -C redisinsight
cd redisinsight && ./redisinsight
Access RedisInsight via browser at http://localhost:8001
and connect to your Redis instance.
Conclusion
Redis is now set up and ready to use. You can manage it via CLI or RedisInsight for a GUI-based experience.