How to Test Redis Cache Using Redis Insight: A Tester’s Guide

Quick summary

This blog post provides a guide for testing Redis cache using Redis Insight. It starts by explaining what Redis and cache are, highlighting their roles in improving application performance.

What is Redis?

Redis (Remote Dictionary Server) is an open-source, in-memory data structure store primarily used as a cache, database, and message broker. It allows for fast retrieval and storage of data by keeping it in memory, making it much quicker than disk-based storage systems. Redis is widely used to cache frequently accessed data, reducing the load on databases and improving application performance.

In simple terms, Redis’s flexibility and speed make it a popular choice for improving the performance and scalability of web applications.

What is Cache?

Cache refers to a storage layer that temporarily holds data to enable faster access to frequently used information. It’s commonly used in computing to improve performance by reducing the time it takes to access data from slower storage systems, such as hard drives or remote servers.

Steps to perform Redis Cache testing:

1. Pre-requisites  

  1. Install Redis insight tool:

    • Download and install Redis Insight by visiting Redis Insight Install Guide.

    • Follow the installation steps specific to your OS.

  1. Redis database:

    • Coordinate with the development or DevOps team to gain access to a Redis database.

    • Ensure that the database environment (live or staging) is clearly identified.

    • Obtain necessary details like username, password, host, and port for Redis Insight.

  1. Install postman tool:

    • Download Postman from Postman Download Link.

    • Acquire the Postman collection file with APIs for the project.

    • Verify the environment (Live APIs or Staging APIs).

  1. Check dependencies:

    • Ensure that APIs match the environment of the Redis database (Live or Staging).

    • Confirm the website URL where QA will be performed.

2. Connecting Redis Database Externally

  1. Establish connection:

    • In Redis Insight, enable the SSH Tunnel checkbox.

    • Enter credentials like username, password, host, and port.

    • Test the connection or add the Redis database.

  1. Verify database connection:

    • Confirm that the Redis database connects successfully.

    • Ensure the project alias appears in Redis Insight, and keys are visible.

  1. Confirm key visibility:

    • Navigate to the database alias and verify the visibility of keys in the Redis Insight dashboard.

Test cases for Redis cache testing:

1. Clearing cache in Redis insight dashboard  

  1. Connect to Redis instance:

    • Open Redis Insight and connect to your Redis instance using the provided connection details.

  1. Navigate to data explorer:

    • On the left sidebar, click on the Data Explorer tab to view data stored in the Redis database.

  1. Choose the correct database:

    • Select the database where cached data is stored (default is database 0).

  1. Search for cache keys:

    • Use the search bar to filter keys (e.g., cache:* or session:*).

  1. Inspect keys before cache clear:

    • Verify the data stored in keys relevant to the test case.

  1. Clear cache:

    • Trigger cache clearing via the application’s API, UI, or Redis command.

  1. Verify cache removal:

    • Refresh the Redis Insight dashboard.

    • Ensure that cleared keys are no longer visible.

  1. Test cache behavior:

    • Reload the application or trigger data fetches to validate cache repopulation.

  1. Confirm no residual data:

    • Ensure no unexpected keys or data remain in the cache.

2. Validating data in Redis insight dashboard

  1. Open Redis insight:

    • Launch Redis Insight and connect to your Redis instance.

  1. Navigate to data explorer:

    • Use the Data Explorer tab to explore and view data.

  1. Select the database:

    • Identify and select the correct database (usually numbered 0 to 15).

  1. Examine key types:

    • Redis stores various data types (e.g., Strings, Lists, Hashes). Choose the appropriate type for inspection.

  1. Search for keys:

    • Filter keys using patterns like user:* or cache:*.

  1. Inspect key data:

    • Click keys to view detailed data. For instance:

      • String: Display key values.

      • Hash: Show fields and values.

      • List: View items in the list.

  1. Verify data changes:

    • Check if data updates align with the expected application behavior.

  1. Run commands (optional):

    • Use the Redis CLI tab in Redis Insight for manual verification.

  1. Test cache efficiency:

    • Perform application actions to populate or clear the cache and validate data changes in Redis Insight.

Best practices for Redis cache testing using Redis insight

  1. Understand cache requirements:

    • Familiarize yourself with application caching logic and key patterns.

  1. Use appropriate environments:

    • Perform tests in staging environments before live deployment.

  1. Validate API responses:

    • Use Postman or other API tools to confirm correct interactions with the cache.

  1. Test under load:

    • Simulate high-traffic scenarios to validate cache performance and efficiency.

  1. Document observations:

    • Maintain detailed logs of cache behavior, including key creations and deletions.

Redis Insight Features for Testers

  • Data explorer: Simplifies data inspection and key searches.

  • CLI access: Enables direct command execution for deeper testing.

  • Performance monitoring: Tracks latency and other metrics to identify bottlenecks.

Redis Insight is a powerful tool for testing Redis cache, ensuring application performance, and validating cache behavior. By following these steps and best practices, testers can optimize their cache testing processes and ensure efficient application behavior.

Author : Naveen Dudhyal Date: December 24, 2024