Copied!
Redis

Redis Introduction, Installation & Commands for Beginners

redis-introduction,-installation-&-commands
Shahroz Javed
Nov 04, 2025 . 15 views

Table Of Contents

 

Redis Introduction, Installation & Basic Commands

Redis is a fast, advanced key-value data store often used for caching, real-time analytics, message queues, and session management. It provides a richer set of commands than traditional caching systems like APC or Memcached.

⚡ Redis stores data in memory, making it extremely fast — often processing millions of requests per second.

1. What is Redis?

Redis (Remote Dictionary Server) is an open-source, in-memory data structure store that supports multiple data types — not just strings. It’s widely used in modern web apps for:

2. Installation & Setup

Download Redis from the official Windows port or GitHub repository:

After installation, set the path in environment variables for easy command-line access. Redis runs on default port 6379.

🧠 Bonus: Use RedisInsight — the official Redis GUI — for a visual view of your databases and keys.

3. Common Redis Commands

Here’s a quick reference of useful commands for Redis setup, connection, and data management.

🔹 Server & Connection Commands

redis-server                 # Start Redis server
net stop Redis               # Stop Redis service (Windows)
net start Redis              # Start Redis service again
sudo systemctl restart redis # Restart Redis (Linux/macOS)
netstat -ano | findstr :6379 # Check if Redis is running on port 6379
redis-cli                    # Open Redis command line interface

CONFIG GET requirepass        # Check if password protection is enabled
    

🔹 1. Connection & Info

PING              # Check if Redis is alive → returns PONG
AUTH password     # Authenticate if Redis has a password
SELECT 0          # Switch to database (0–15 default)
FLUSHDB           # Delete all keys in current DB
FLUSHALL          # Delete all keys in all DBs
INFO              # Get Redis server info (clients, memory, etc.)
    

🔹 2. Strings (Basic Key-Value)

SET key value              # Store a string
GET key                    # Retrieve a string
DEL key                    # Delete a key
EXPIRE key seconds         # Set expiry
INCR key                   # Increment integer value
DECR key                   # Decrement integer value
SETEX key seconds value    # Set with expiry
APPEND key value           # Append to existing value
    

🔹 3. Lists

LPUSH key value            # Add to start
RPUSH key value            # Add to end
LPOP key                   # Remove first element
RPOP key                   # Remove last element
LRANGE key 0 -1            # Get all list items
LLEN key                   # Get list length
    

🔹 4. Hash

HSET key field value       # Set hash field
HGET key field             # Get single field
HGETALL key                # Get all fields
HDEL key field             # Delete a field
HEXISTS key field          # Check if field exists
HINCRBY key field number   # Increment numeric field
    

🔹 5. Set

SADD key value             # Add unique values
SREM key value             # Remove value
SMEMBERS key               # Get all members
SISMEMBER key value        # Check existence
SCARD key                  # Count items
SUNION key [key...]        # Union of sets
SINTER key [key...]        # Intersection of sets
    

🔹 6. Pub/Sub

PUBLISH channel message     # Send message to a channel
SUBSCRIBE channel           # Listen for messages
UNSUBSCRIBE channel         # Stop listening
PSUBSCRIBE pattern          # Subscribe to pattern channels
    

4. Extra Handy Commands

KEYS *                     # List all keys (avoid in production)
TTL key                    # Check key expiry
RENAME oldKey newKey       # Rename a key
EXISTS key                 # Check if key exists
TYPE key                   # Show key type (string, list, etc.)
PERSIST key                # Remove expiry and make permanent
    

5. Quick Test

After running redis-cli:

> SET name "Shahroz"
OK
> GET name
"Shahroz"
> INCR counter
(integer) 1
> KEYS *
1) "name"
2) "counter"
    
✅ You’ve now successfully installed and tested Redis locally! You can now explore advanced topics like Lists, Hashes, Sets, and Pub/Sub.

15 Shares

Similar Posts