Skip to content

TobiahRex/redis-sandbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

Redis is an open-source, in-memory data structure store that can be used as a database, cache, and message broker. It is known for its high performance, flexibility, and simplicity. Redis supports various data structures such as strings, lists, sets, hashes, sorted sets, bitmaps, and hyperloglogs. It's widely used in modern web applications and distributed systems due to its fast read and write operations.

Here's a brief overview of some key concepts and commands in Redis:

  1. Data Structures:

    • Strings: Used to store text or binary data, with a maximum size of 512MB.
    • Lists: Collections of ordered elements.
    • Sets: Unordered collections of unique elements.
    • Hashes: Maps between fields and values.
    • Sorted Sets: Similar to sets but with an associated score for each member, allowing them to be sorted.
    • Bitmaps: Essentially a set of bits that can be manipulated with special commands.
    • HyperLogLogs: Used to estimate the cardinality of a set.
  2. Basic Commands:

    • SET key value: Set a key to hold a string value.
    • GET key: Get the value of a key.
    • DEL key [key ...]: Delete one or more keys.
    • INCR key: Increment the integer value of a key by one.
    • LPUSH key value [value ...]: Insert one or multiple values at the beginning of a list.
    • SADD key member [member ...]: Add one or more members to a set.
  3. Expiry and Persistence:

    • Redis allows setting an expiry time for keys using the EXPIRE command, making it useful for caching purposes.
    • Data can be persisted to disk periodically using snapshots, or by appending every command to a log file.
  4. Pub/Sub (Publish/Subscribe):

    • Redis supports messaging patterns where publishers send messages to channels, and subscribers receive those messages from subscribed channels.

To start learning Redis, you can follow these steps:

  1. Installation:

    • Redis can be installed on various platforms, including Linux, macOS, and Windows. You can check the official Redis website or use package managers like apt (Ubuntu/Debian) or brew (macOS) for installation.
  2. Getting Started:

    • Once Redis is installed, you can start the Redis server, and you can interact with it using the Redis CLI or libraries available in different programming languages.
  3. Documentation:

    • The Redis documentation (https://redis.io/documentation) is a valuable resource. It covers all the commands, data structures, and concepts in detail.
  4. Tutorials and Examples:

    • Look for online tutorials and examples to understand how Redis can be used in real-world scenarios.
  5. Hands-On Practice:

    • The best way to learn Redis is to use it hands-on. Try out different data structures and commands to get a feel for how Redis works.

Remember that Redis is often used in combination with other technologies to create robust and scalable applications. Learning Redis will open up new possibilities for caching, real-time data processing, and more. Enjoy your journey into the world of Redis!

Setup

Setting up Redis on your local computer and eventually deploying a Redis cluster on AWS ECS (Elastic Container Service) or EC2 (Elastic Compute Cloud) involves several steps. I'll provide detailed instructions for each stage of the process. Let's get started:

Setting Up Redis on Your Local Computer:

  1. Installation:

    1. Local Install
      • brew install redis
      • To test your Redis installation, you can run the redis-server executable from the command line: $ redis-server * If successful, you'll see the startup logs for Redis, and Redis will be running in the foreground. * To stop Redis, enter Ctrl-C.
        • To connect to the Redis server, open another terminal window and run the redis-cli executable:
          $ redis-cli
          
          • You can now use the Redis CLI to interact with Redis. For example:
            SET mykey "Hello, Redis!"
            GET mykey
            
    2. Docker Install
      • To get started with Redis Stack using Docker, you first need to select a Docker image: redis/redis-stack contains both Redis Stack server and RedisInsight. This container is best for local development because you can use the embedded RedisInsight to visualize your data. redis/redis-stack-server provides Redis Stack server only. This container is best for production deployment.
      • docker run --name redis-stack-server -p 6379:6379 -d redis/redis-stack-server:latest
      • To test your Redis installation, you can run the redis-server executable from the command line: $ redis-server * If successful, you'll see the startup logs for Redis, and Redis will be running in the foreground. * To stop Redis, enter Ctrl-C.
        • To connect to the Redis server, open another terminal window and run the redis-cli executable:
          $ redis-cli
          
          • You can now use the Redis CLI to interact with Redis. For example:
            SET mykey "Hello, Redis!"
            GET mykey
            
  2. Compile Redis:

    • Open a terminal (Linux/macOS) or Command Prompt (Windows).
    • Navigate to the Redis folder you extracted in the previous step.
    • Run the following commands to compile Redis:
      $ make
      $ make test (optional but recommended to ensure Redis is working correctly)
      
  3. Start Redis Server:

    • In the same terminal or Command Prompt, run the following command to start the Redis server:
      $ src/redis-server
      
    • By default, Redis will listen on port 6379. You can modify this in the Redis configuration file (redis.conf) if needed.
  4. Verify Redis Server:

    • Open another terminal or Command Prompt.
    • Connect to the Redis server using the Redis CLI by running:
      $ src/redis-cli
      
    • Test if Redis is running by typing PING. You should get a reply of "PONG."
  5. Interacting with Redis:

    • With the Redis CLI, you can now use various commands to interact with Redis. For example:
      SET mykey "Hello, Redis!"
      GET mykey
      

Deploying Redis on AWS ECS (Elastic Container Service):

  1. Create an ECS Cluster:

    • Log in to your AWS Management Console.
    • Navigate to the Amazon ECS service and create a new cluster. Choose the "EC2 Linux + Networking" cluster type.
  2. Prepare Task Definition:

    • In the ECS service, create a new task definition that defines how your Redis container will run.
    • Specify the Redis container image (you can use the official Redis Docker image).
    • Configure environment variables, ports, resource limits, etc.
  3. Configure Security Group:

    • Create a security group that allows inbound traffic to the Redis port (default 6379) from trusted sources (e.g., your IP address).
  4. Launch ECS Instances:

    • Launch EC2 instances within the same VPC as the ECS cluster.
    • Assign the security group you created to the instances.
  5. Register Task and Start Service:

    • Register the task definition you created earlier with the ECS cluster.
    • Create a new service using the registered task definition, specifying the desired number of tasks (instances) to run.
  6. Accessing Redis:

    • Once the service is running, you can access Redis using the public IP or DNS of any of the ECS instances on port 6379.

Deploying Redis on AWS EC2 (Elastic Compute Cloud):

  1. Launch EC2 Instance:

    • Log in to your AWS Management Console.
    • Launch a new EC2 instance using the official Redis Amazon Machine Image (AMI) or a custom AMI with Redis installed.
  2. Configure Security Group:

    • Create a security group that allows inbound traffic to the Redis port (default 6379) from trusted sources (e.g., your IP address).
    • Assign this security group to the EC2 instance.
  3. Start Redis Server:

    • Connect to the EC2 instance via SSH.
    • Start the Redis server using the same command as on your local computer:
      $ src/redis-server
      
  4. Accessing Redis:

    • Once the Redis server is running, you can access it using the public IP or DNS of the EC2 instance on port 6379.

Redis Cluster in AWS:

For creating a Redis cluster on AWS, you have two options: Redis Cluster or ElastiCache for Redis. ElastiCache is a managed Redis service provided by AWS, making it easier to set up and maintain, but it comes with some limitations compared to Redis Cluster.

  1. Redis Cluster (Manual Setup):

    • You can set up a Redis Cluster manually by creating multiple Redis instances and configuring them to work together as a cluster.
    • This involves setting up Redis Sentinel nodes for high availability and failover.
  2. ElastiCache for Redis (Managed Service):

    • In the AWS Management Console, navigate to ElastiCache.
    • Create a new Redis cluster with the desired configuration, specifying the number of nodes and replication settings.
    • AWS will manage the cluster for you, including scaling, failover, and backups.

Keep in mind that Redis Cluster and ElastiCache for Redis have different configuration requirements and limitations, so choose the one that best fits your use case.

Remember that when deploying Redis in a production environment, consider enabling authentication and securing your Redis instances to prevent unauthorized access.

Setting up Redis locally and then deploying it on AWS ECS or EC2 will give you hands-on experience with Redis and help you understand how it works in different environments. Good luck with your Redis journey!

About

Experiment with Redis Configs, API & Sandbox Scenarios

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages