Redis Commands: Hướng dẫn chi tiết các lệnh Redis phổ biến và cách sử dụng
5:00 read
Redis Commands và Redis CLI
Redis CLI (Command Line Interface) là công cụ mạnh mẽ để tương tác với Redis server, thực hiện operations, monitoring, và troubleshooting. Trong bài viết này, chúng ta sẽ đi sâu vào các lệnh Redis phổ biến, cách kết nối, và các kỹ thuật để làm việc hiệu quả với Redis.
Kết nối đến Redis Server
Cách kết nối cơ bản
Redis CLI cung cấp nhiều options để kết nối đến Redis server:
# Kết nối đến localhost (mặc định)
redis-cli
# Kết nối đến remote host
redis-cli -h <hostname>
# Kết nối với port cụ thể
redis-cli -h <hostname> -p <port>
# Ví dụ kết nối đến localhost port 6379
redis-cli -h localhost -p 6379
# Kết nối đến specific database (mặc định là db 0)
redis-cli -h localhost -n 1
Kết nối đến Azure Redis Cache
Azure Redis Cache có format hostname đặc biệt:
# Format: <name>.redis.cache.windows.net
redis-cli -h xxx.redis.cache.windows.net -p 6379
# Ví dụ cụ thể
redis-cli -h prod-myapp.redis.cache.windows.net -p 6380
# SSL connection (Azure Redis thường yêu cầu SSL trên port 6380)
redis-cli -h prod-myapp.redis.cache.windows.net -p 6380 --tls
Kết nối đến AWS ElastiCache
# AWS ElastiCache primary endpoint
redis-cli -h myapp.abcdef.0001.use1.cache.amazonaws.com -p 6379
# ElastiCache với encryption in-transit
redis-cli -h myapp.abcdef.ng.0001.use1.cache.amazonaws.com -p 6379 --tls
Yêu cầu đăng nhập
Vui lòng đăng nhập để truy cập nội dung này
Additional Resources
Course Guide
Comprehensive PDF guide with examples
GitHub Repository
Example code for all lessons
Discussion
Have a question about this lesson? Post it here and get answers from instructors and peers.
