Setup Steps
1. Install Redis:
sudo apt update
sudo apt install redis-server -y2. Start the service:
sudo systemctl start redis-server
sudo systemctl enable redis-server3. Test Redis:
redis-cli ping
# You should get a PONG response4. Basic commands:
redis-cli
SET key "value"
GET key
DEL key
EXPIRE key 3600
TTL key5. Set a password (/etc/redis/redis.conf):
requirepass StrongPass123!6. Restart the service:
sudo systemctl restart redis-server7. Node.js usage:
npm install redisjavascript
import { createClient } from 'redis';
const client = createClient({ password: 'StrongPass123!' });
await client.connect();
await client.set('key', 'value');
const value = await client.get('key');8. Check memory usage:
redis-cli INFO memory