Skip to main content

Launching Redis

Learn how to launch and deploy Redis on KloudBean. KloudBean provides managed Redis database with high performance and robust security policies.

Overview

KloudBean provides managed Redis database. KloudBean databases are high performant and having good security policies as well.

KloudBean Managed Redis Benefits

High Performance:

  • Optimized Configuration: Pre-configured for optimal performance
  • Fast Operations: In-memory data structure store for ultra-fast operations
  • Efficient Resource Usage: Smart resource allocation
  • Scalable Architecture: Built to scale with your needs
  • Low Latency: Sub-millisecond response times

Security Policies:

  • Encrypted Connections: SSL/TLS encryption for secure connections
  • Access Control: Granular access control and IP whitelisting
  • Password Protection: Strong password authentication
  • Regular Updates: Automatic security updates and patches

Easy Setup and Access:

  • Few Steps Installation: It is a few steps installation process
  • Quick Deployment: Database creation takes only 2-5 minutes
  • Simple Configuration: Minimal configuration required
  • Easy Access: Straightforward access to database credentials
  • User-Friendly Interface: Intuitive dashboard for management

Additional Benefits:

  • High Availability: Built-in replication and failover
  • Monitoring: Real-time performance monitoring
  • Scalability: Easy scaling as your needs grow
  • Support: Expert support from KloudBean team
  • Persistence Options: RDB and AOF persistence for data durability

Prerequisites

  • An active KloudBean account
  • Understanding of caching and data structure requirements
  • Payment method for database provisioning

Launching Redis Database

Step 1: Navigate to Database Section

In order to launch Redis database:

From your KloudBean dashboard navigate to Managed database or from top header click on "DBS".

On DBS page there is a button "Launch Database".

Database Step 1

Once you click it will take you to database provision page.

Step 2: Select Database Engine

Where you have to select:

Database engine: Select Redis from here.

Redis Launch Step 1

Step 3: Provide Database Details

Next step is to provide following database detail:

Redis Launch Step 2

Required Information:

  1. Database Name:

    • Enter a unique name for your Redis instance
    • Use lowercase letters, numbers, and underscores
    • Example: myapp_cache, session_store
  2. Database User:

    • Create a username for Redis access (optional, Redis primarily uses password)
    • Use lowercase letters, numbers, and underscores
    • Example: redis_user, cache_admin
  3. Database Version:

    • Select Redis version:
      • Redis 7.x (latest, recommended)
      • Redis 6.x (stable)
      • Redis 5.x (legacy support)
    • Choose based on your application requirements
  4. Server Location:

    • Choose the geographic location for your database
    • Select region closest to your application servers
    • Consider data residency requirements

Step 4: Select Server Size

Once these details are added:

Decide server size and select most suitable size. Note that you can scale your database up any time, contact KloudBean for that.

Server Size Options:

  • Small: Suitable for development and testing
  • Medium: Good for small to medium applications
  • Large: For production applications with high traffic
  • Custom: Custom configuration for specific needs

Scaling Options:

  • Vertical Scaling: Increase CPU, RAM, or storage
  • Horizontal Scaling: Add replica nodes or cluster nodes
  • Contact Support: Reach out to KloudBean support for scaling assistance

Considerations:

  • Current Needs: Start with size that meets current needs
  • Growth Projection: Consider future growth when selecting size
  • Cost Optimization: Start smaller and scale as needed
  • Performance: Larger sizes offer better performance
  • Memory Requirements: Redis is memory-based, ensure sufficient RAM

Step 5: Launch Database

Click on "Launch now" button, it will take you to the payment screen, where you will complete your payment.

Payment Process:

  1. Review Configuration: Verify all settings are correct
  2. Payment Method: Select your payment method
  3. Complete Payment: Complete the payment process
  4. Confirmation: Receive confirmation of payment

Once payment is completed, your database creation process will be initiated, and it will take around 2-5 minutes to create and configure your high performance database.

Creation Process:

  • Database instance provisioning
  • Redis installation and configuration
  • Security setup and encryption
  • Network configuration

Once created you will see your database in DBS page.

Redis Access Step 1

Accessing Database Details

Step 1: Navigate to Database Administration

In order to get database access detail click on your database and it will take you to database administration page where all the database access information is listed.

Redis Access Step 2

Step 2: View Database Credentials

Database Access Information:

Host:

  • Database server hostname or IP address
  • Use this to connect to your database
  • Example: redis-123456.kloudbeansite.com or 192.168.1.100

Port:

  • Redis port number (usually 6379)
  • Default Redis port for connections
  • Example: 6379

Database Name:

  • Name of your Redis instance
  • Use this for identification
  • Example: myapp_cache

Master User:

  • Username for Redis access (if configured)
  • Primary database user credentials
  • Example: redis_user

Database Password:

  • Password for Redis authentication
  • Keep this secure and never expose publicly
  • Use this for authentication

IP Address:

  • Database server IP address
  • Use for IP whitelisting if needed
  • Example: 192.168.1.100

You can use this information to use this database in your application.

Accessing Database

Database Access Status

By default, the public access to your database is disabled.

In order to check access status, navigate to "Database Specifications" section of "Access" tab.

Database Public Access

This represents that access is disabled and you cannot access it.

Enabling Database Access

In order to access database you have to whitelist the IP address of your source server or you have to enable public access of your database.

Important: Do Not Enable Public Access Unnecessarily

Why Public Access Should Be Avoided:

  • Security Risk: Public access exposes your database to the entire internet
  • Attack Surface: Increases vulnerability to attacks and unauthorized access
  • Compliance Issues: May violate data protection regulations
  • Best Practice: Always use IP whitelisting instead of public access

When Public Access Might Be Needed:

  • Development/Testing: Only for non-production environments
  • Temporary Access: For specific, time-limited tasks
  • With Additional Security: Combined with strong passwords and SSL

Recommended Approach:

  • IP Whitelisting: Always prefer IP whitelisting over public access
  • Specific IPs: Whitelist only specific IP addresses that need access
  • Source Server IP: Whitelist your application server's IP address
  • VPN Access: Consider VPN for additional security layer

To get to know how you can update database access, read document: Controlling Database Access

Once access is enabled, now you can access your database.

Accessing Database from Shell/Command Line

Step 1: Install Redis Client

On Linux (Ubuntu/Debian):

sudo apt update
sudo apt install redis-tools

On macOS:

brew install redis

On Windows:

  • Download Redis from Redis Downloads
  • Or use WSL (Windows Subsystem for Linux)

Step 2: Connect to Database

Basic Connection Command:

redis-cli -h [HOST] -p [PORT] -a [PASSWORD]

Example:

redis-cli -h redis-123456.kloudbeansite.com -p 6379 -a your_password

Alternative: Interactive Connection:

redis-cli -h [HOST] -p [PORT]
# Then authenticate with: AUTH password

Example:

redis-cli -h redis-123456.kloudbeansite.com -p 6379
AUTH your_password

Step 3: Basic Redis Commands

Once connected, you can run Redis commands:

String Operations:

# Set value
SET key "value"

# Get value
GET key

# Set with expiration (seconds)
SETEX key 3600 "value"

# Set if not exists
SETNX key "value"

# Increment
INCR counter
INCRBY counter 5

# Decrement
DECR counter
DECRBY counter 5

List Operations:

# Push to left
LPUSH list_name "item1"

# Push to right
RPUSH list_name "item2"

# Pop from left
LPOP list_name

# Pop from right
RPOP list_name

# Get range
LRANGE list_name 0 -1

# Get length
LLEN list_name

Set Operations:

# Add to set
SADD set_name "member1" "member2"

# Get all members
SMEMBERS set_name

# Check membership
SISMEMBER set_name "member1"

# Remove from set
SREM set_name "member1"

# Get set size
SCARD set_name

Hash Operations:

# Set hash field
HSET hash_name field1 "value1"

# Set multiple fields
HMSET hash_name field1 "value1" field2 "value2"

# Get hash field
HGET hash_name field1

# Get all fields
HGETALL hash_name

# Get multiple fields
HMGET hash_name field1 field2

# Delete field
HDEL hash_name field1

Sorted Set Operations:

# Add to sorted set
ZADD sorted_set 100 "member1"

# Get range (ascending)
ZRANGE sorted_set 0 -1

# Get range (descending)
ZREVRANGE sorted_set 0 -1

# Get score
ZSCORE sorted_set "member1"

# Get rank
ZRANK sorted_set "member1"

Key Management:

# Check if key exists
EXISTS key

# Delete key
DEL key

# Delete multiple keys
DEL key1 key2 key3

# Get all keys (use with caution)
KEYS *

# Get keys matching pattern
KEYS user:*

# Set expiration
EXPIRE key 3600

# Get time to live
TTL key

# Remove expiration
PERSIST key

Database Selection:

# Select database (0-15)
SELECT 0

# Get current database
INFO keyspace

Info and Monitoring:

# Get server info
INFO

# Get memory info
INFO memory

# Get client info
CLIENT LIST

# Get database size
DBSIZE

Exit Redis CLI:

exit
-- or
quit

Using Database Credentials in Your Application

Connection String Format

Standard Redis Connection String:

redis://:[PASSWORD]@[HOST]:[PORT]/[DATABASE_NUMBER]

Example:

redis://:[email protected]:6379/0

Node.js

Using redis package:

const redis = require('redis');

const client = redis.createClient({
host: 'redis-123456.kloudbeansite.com',
port: 6379,
password: 'your_password'
});

client.on('error', (err) => console.log('Redis Client Error', err));

await client.connect();

// Set value
await client.set('key', 'value');

// Get value
const value = await client.get('key');

// Set with expiration
await client.setEx('key', 3600, 'value');

// Increment
await client.incr('counter');

// List operations
await client.lPush('list', 'item1');
await client.rPop('list');

// Set operations
await client.sAdd('set', 'member1');
await client.sMembers('set');

// Hash operations
await client.hSet('hash', 'field1', 'value1');
await client.hGetAll('hash');

client.quit();

Using ioredis package:

const Redis = require('ioredis');

const redis = new Redis({
host: 'redis-123456.kloudbeansite.com',
port: 6379,
password: 'your_password'
});

// Use redis
await redis.set('key', 'value');
const value = await redis.get('key');

redis.quit();

Python

Using redis package:

import redis

r = redis.Redis(
host='redis-123456.kloudbeansite.com',
port=6379,
password='your_password',
decode_responses=True
)

# Set value
r.set('key', 'value')

# Get value
value = r.get('key')

# Set with expiration
r.setex('key', 3600, 'value')

# Increment
r.incr('counter')

# List operations
r.lpush('list', 'item1')
r.rpop('list')

# Set operations
r.sadd('set', 'member1')
r.smembers('set')

# Hash operations
r.hset('hash', 'field1', 'value1')
r.hgetall('hash')

PHP

Using phpredis:

<?php
$redis = new Redis();
$redis->connect('redis-123456.kloudbeansite.com', 6379);
$redis->auth('your_password');

// Set value
$redis->set('key', 'value');

// Get value
$value = $redis->get('key');

// Set with expiration
$redis->setex('key', 3600, 'value');

// Increment
$redis->incr('counter');

// List operations
$redis->lPush('list', 'item1');
$redis->rPop('list');

// Set operations
$redis->sAdd('set', 'member1');
$redis->sMembers('set');

// Hash operations
$redis->hSet('hash', 'field1', 'value1');
$redis->hGetAll('hash');
?>

Best Practices

Security

  • Strong Passwords: Use strong, unique passwords for Redis
  • IP Whitelisting: Always use IP whitelisting instead of public access
  • SSL/TLS: Enable SSL/TLS encryption for all connections
  • Regular Updates: Keep Redis updated to latest version
  • Access Control: Implement proper access control

Performance

  • Connection Pooling: Use connection pooling in applications
  • Pipelining: Use pipelining for multiple commands
  • Key Naming: Use consistent key naming conventions
  • TTL Management: Set appropriate TTL for cache keys
  • Resource Monitoring: Monitor memory usage regularly
  • Eviction Policies: Configure appropriate eviction policies

Management

  • Monitor Usage: Monitor database usage and performance
  • Scale When Needed: Scale your database as your needs grow
  • Documentation: Document your database configuration
  • Memory Management: Monitor and manage memory usage

Troubleshooting

Connection Issues

Cannot Connect to Database:

  • Check IP Whitelist: Verify your IP is whitelisted
  • Check Credentials: Verify host, port, and password
  • Check Network: Verify network connectivity
  • Check Firewall: Check firewall rules
  • Review Access Settings: Check database access configuration

Authentication Errors:

  • Verify Password: Check password is correct
  • Check AUTH Command: Verify AUTH command is used correctly
  • Check Configuration: Verify Redis configuration

Performance Issues

Memory Issues:

  • Monitor Memory: Check memory usage with INFO memory
  • Set Eviction Policy: Configure appropriate eviction policy
  • Check Keys: Review and clean up unused keys
  • Increase Memory: Consider increasing server size

Slow Operations:

  • Check Commands: Review slow commands
  • Use Pipelining: Use pipelining for multiple operations
  • Optimize Data Structures: Use appropriate data structures
  • Check Network: Verify network latency

Connection Limits:

  • Check Limits: Verify connection limits
  • Close Connections: Close unused connections
  • Use Connection Pooling: Implement connection pooling
  • Review Active Connections: Check for connection leaks

Next Steps

After launching your Redis database: