Access
คุณสามารถเข้าถึง Redis ได้ที่ redis://localhost:6379
ตัวอย่างการเข้าถึง interactive shell:
redis-cli
127.0.0.1:6379> set example "Hello Redis"
127.0.0.1:6379> get example
"Hello Redis"
ไฟล์และไดเรกทอรีสำคัญ
/etc/redis/redis.conf→ ไฟล์การกำหนดค่าหลัก/var/lib/redis/→ ไดเรกทอรีข้อมูลสำหรับ persistence/var/log/redis/redis-server.log→ Log file/usr/bin/redis-cli→ เครื่องมือ command-line ของ Redis/usr/bin/redis-server→ ไบนารี daemon ของ Redis
Service Management
คำสั่งใช้งานบริการทั่วไป:
systemctl restart redis-server # Restart Redis
systemctl stop redis-server # Stop Redis
systemctl status redis-server # View Redis status
การตั้งค่า
ไฟล์คอนฟิกของ Redis: /etc/redis/redis.conf
- bind — กำหนด network interface ที่ Redis รับการเชื่อมต่อ
- protected-mode — ต้องปิดใช้งานหากเปิดให้เข้าถึงจากระยะไกล
- requirepass — ตั้งรหัสผ่านสำหรับยืนยันตัวตน client
- maxmemory — จำกัดการใช้งาน RAM (สำหรับกรณีใช้เป็น cache)
- appendonly — เปิดใช้งาน AOF persistence
หลังแก้ไขค่าคอนฟิกใดก็ตาม:
systemctl restart redis-server
เครื่องมือและคำสั่งที่มีประโยชน์
Redis มีเครื่องมือในตัวหลายตัว:
redis-cli→ อินเทอร์เฟซ command-line สำหรับ Redisredis-benchmark→ Benchmarking utilityredis-check-aofและredis-check-rdb→ ตรวจสอบความถูกต้องของไฟล์ AOF/RDB persistenceredis-server→ เริ่ม Redis daemon ด้วยตนเอง
Log และการมอนิเตอร์
Check logs:
journalctl -u redis-server -f
Monitor activity:
redis-cli monitor
ดู client ที่เชื่อมต่ออยู่:
redis-cli client list
Persistence Modes
Redis รองรับตัวเลือก persistence สองแบบ:
- RDB snapshots → บันทึกสถานะฐานข้อมูลเป็นช่วง ๆ (ใช้ทรัพยากรน้อย)
- AOF (Append Only File) → บันทึกทุก write operation (ปลอดภัยกว่า แต่ไฟล์ใหญ่กว่า)
เปิดใช้งานทั้งสองแบบได้ใน /etc/redis/redis.conf for durability.