All Guides

Redis Setup

Install Redis in-memory data store. Caching and session management.

Beginner15 min

Setup Steps

1. Install Redis:

sudo apt update
sudo apt install redis-server -y

2. Start the service:

sudo systemctl start redis-server
sudo systemctl enable redis-server

3. Test Redis:

redis-cli ping
# You should get a PONG response

4. Basic commands:

redis-cli
SET key "value"
GET key
DEL key
EXPIRE key 3600
TTL key

5. Set a password (/etc/redis/redis.conf):

requirepass StrongPass123!

6. Restart the service:

sudo systemctl restart redis-server

7. Node.js usage:

npm install redis
javascript
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