I recently attended the KSUG.ai MCP Meetup held at the Microsoft Office in Bangalore. One of the sessions that struck me was Himanshumalis session about the AI and MCP Capabilities in Redis.
I’ve been working with the installed version of Redis on either on-premises or EC2 instances. While attending the sessions, I learned about the different Redis AI offerings, especially the Redis MCP Server, Semantic Search, Redis Vector Set, and RAG capabilities. Though the session was primarily focused on Redis, in this article, I am attempting to consolidate how to leverage Redis AI-related offerings on AWS.
Redis Offerings in AWS
AWS primarily offers Redis-based managed services named AWS ElastiCache and AWS MemoryDB for Redis (formerly AWS Memcached service). These are managed services from AWS, where AWS handles the heavy lifting. Your applications can simply connect to these cache services and take advantage of managed cache functionality. Choosing between ElastiCache and MemoryDB depends on your application’s requirements. The key considerations are persistence and latency; everything else — API, features, management — remains similar.
If your applications need a fast cache with sub-millisecond latency and no persistence (data will be available on restart), you should go with ElastiCache for Redis. However, if you can compensate for sub-millisecond latency with 1–3 ms latency and durable persistent storage (managed by AWS), you should go with MemoryDB for Redis. Please be aware that there is also a separate ElastiCache non-Redis offering from AWS available.
Connecting Your Application to ElastiCache / MemoryDB (Based on .NET Core)
The Redis client code is identical for both services; only the connection string and infrastructure differ.
We start by installing the required Redis NuGet package. For JavaScript frameworks or Java, equivalent npm packages or Java code will be available.
Install-Package StackExchange.Redis
The next step is to create the required Redis managed service in AWS — either ElastiCache for Redis or MemoryDB for Redis. Grab the connection string and set it in your application’s configuration.
{ "ConnectionStrings": { "ElastiCache": "your-elasticache-cluster.cache.amazonaws.com:6379", "MemoryDB": "clustercfg.your-memorydb.memorydb.us-east-1.amazonaws.com:6379" } }
The next step is to inject Dependency Injection to use Redis services. DI in .NET Core is specifically designed to inject custom behaviors and implementations throughout your application.
// Program.cs var builder = WebApplication.CreateBuilder(args); // ElastiCache builder.Services.AddSingleton<IConnectionMultiplexer>("ElastiCache", provider => { var connectionString = builder.Configuration.GetConnectionString("ElastiCache"); return ConnectionMultiplexer.Connect(connectionString); }); // MemoryDB builder.Services.AddSingleton<IConnectionMultiplexer>("MemoryDB", provider => { var connectionString = builder.Configuration.GetConnectionString("MemoryDB"); return ConnectionMultiplexer.Connect(connectionString); });
And finally, the actual Program.cs code that has the Redis implementations. The code shows implementations for both ElastiCache and MemoryDB; however, your application may use either one of those or both.
using StackExchange.Redis; using System.Text.Json; public class RedisService { private readonly IDatabase _database; private readonly string _serviceName; public RedisService(string connectionString, string serviceName = "Redis") { var redis = ConnectionMultiplexer.Connect(connectionString); _database = redis.GetDatabase(); _serviceName = serviceName; } public async Task SetAsync(string key, string value, TimeSpan? expiry = null) { await _database.StringSetAsync(key, value, expiry); Console.WriteLine($"[{_serviceName}] Set key: {key}"); } public async Task<string> GetAsync(string key) { var value = await _database.StringGetAsync(key); Console.WriteLine($"[{_serviceName}] Get key: {key}, Found: {value.HasValue}"); return value; } public async Task<T> GetObjectAsync<T>(string key) { var json = await _database.StringGetAsync(key); if (!json.HasValue) return default(T); return JsonSerializer.Deserialize<T>(json); } public async Task SetObjectAsync<T>(string key, T obj, TimeSpan? expiry = null) { var json = JsonSerializer.Serialize(obj); await _database.StringSetAsync(key, json, expiry); } public async Task<bool> DeleteAsync(string key) { return await _database.KeyDeleteAsync(key); } }
By following the above approach, you can connect your existing applications, whether on-premises or in the cloud, to take advantage of managed Redis services offered by AWS.
Connecting Your EC2, Container / Kubernetes Services to Redis
Based on your requirements, sometimes your application may be running on an EC2 instance or container instances like AWS Fargate or Kubernetes, and you want to connect to Redis. For EC2, Container, and Kubernetes, you can follow the same approach. You can use IAM roles to retrieve Redis connection strings from AWS services (Parameter Store/Secrets Manager), but you still need to explicitly connect to Redis with that endpoint. Redis itself doesn’t use IAM authentication like other AWS services.
Connecting to Serverless Instances with Lambda (with C#)
The approach is almost the same; you have to use NuGet packages, and the code looks identical. However, for Lambda, storing credentials via Environment Variables is more common.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))] public class Function { private static readonly Lazy<IConnectionMultiplexer> _redis = new Lazy<IConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(Environment.GetEnvironmentVariable("REDIS_CONNECTION_STRING")) ); public async Task<string> FunctionHandler(string input, ILambdaContext context) { var database = _redis.Value.GetDatabase(); await database.StringSetAsync("key", input); return await database.StringGetAsync("key"); } }
Alternatively, you can use a Parameter Store with an IAM Role.
public class Function { private static IConnectionMultiplexer _redis; private static readonly AmazonSimpleSystemsManagementClient _ssmClient = new(); public async Task<string> FunctionHandler(string input, ILambdaContext context) { // Initialize Redis connection if not already done if (_redis == null) { var parameter = await _ssmClient.GetParameterAsync(new GetParameterRequest { Name = "/myapp/redis/endpoint" }); _redis = ConnectionMultiplexer.Connect(parameter.Parameter.Value); } var database = _redis.GetDatabase(); return await database.StringGetAsync("key"); } }
And your Lambda role should have the following permission:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["ssm:GetParameter"], "Resource": "arn:aws:ssm:*:*:parameter/myapp/redis/*" } ] }
While writing Lambda code, make sure to use static variables and reuse the connection.
// Good - Static connection (reused across invocations) private static readonly Lazy<IConnectionMultiplexer> _redis = new Lazy<IConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(connectionString) ); // Bad - New connection per invocation (slow) public async Task Handler() { var redis = ConnectionMultiplexer.Connect(connectionString); // Don't do this }
To use MemoryDB with Lambda, your Lambda must be inside a VPC with the required VPC configuration. The SAM YAML infrastructure as code looks like this:
VpcConfig: SecurityGroupIds: - sg-12345678 # Allow outbound to Redis port 6379 SubnetIds: - subnet-12345678 - subnet-87654321
Real-World Uses of Caches with AWS ElastiCache or MemoryDB
AWS ElastiCache
AWS ElastiCache is widely adopted across industries for high-performance caching solutions. Airbnb uses ElastiCache for Redis to cache search results and user sessions, handling millions of property searches with sub-millisecond response times. Snapchat leverages it to store user stories and chat metadata, processing billions of snaps daily while managing massive engagement spikes. Expedia Group caches hotel pricing and availability data to reduce database load for travel searches, while Samsung implements ElastiCache for mobile app backend caching, supporting millions of Galaxy users globally. Duolingo uses ElastiCache for Redis to cache user progress and lesson data for over 500 million language learners, enabling real-time leaderboards and progress tracking. Common use patterns include e-commerce product catalogs and shopping carts, gaming leaderboards and player stats, media content metadata, financial trading data, and social media user feeds. These implementations typically achieve 10–100x performance improvements and significant cost savings for high-traffic applications.
ElastiCache — Common Use Patterns
- E-commerce: Product catalogs, shopping carts, user sessions
- Gaming: Leaderboards, player stats, real-time game state
- Media: Content metadata, user preferences, streaming data
- Financial: Trading data, user portfolios, transaction caching
- Social: User feeds, notifications, friend connections
AWS MemoryDB for Redis (formerly Memcached)
MemoryDB for Redis is adopted by companies requiring simple, high-performance key-value caching. Pinterest uses MemoryDB for caching user feed data and board recommendations, handling billions of pins with its lightweight architecture and multi-threading capabilities. Reddit implements MemoryDB for caching comment threads and user data, benefiting from its simplicity for high-volume read operations alongside other caching layers. Flickr leverages MemoryDB extensively for photo metadata caching, using its simple protocol to serve millions of photo requests daily with minimal overhead.
Companies choose MemoryDB over ElastiCache for Redis when they need pure key-value storage without complex data structures, better CPU utilization through multi-threading, lower memory overhead, and faster performance for simple caching operations. Common use cases include web application session storage, database query result caching, API response caching, and simple object caching where Redis’s advanced features would be unnecessary complexity.
MemoryDB — Common Use Patterns
- Web application session storage
- Database query result caching
- API response caching
- Simple object caching
Taking Advantage of Redis AI Features
Once you have a grasp of basic Redis awareness and how to connect your application, let’s see how to take advantage of some of the AI features offered by Redis. This was the core theme of Himanshu’s presentation. Redis recently launched the Redis MCP Server and a set of AI capabilities along with it. The MCP Server is separate from Redis AI modules (RedisAI, RediSearch, etc.). However, to take advantage of these Redis-specific AI features in AWS, you need to use Redis Cloud or a self-hosted Redis Stack for AI features. We will discuss both of these, starting with using Redis Cloud with AWS.
Redis Cloud with AWS or Self-Hosted to Take Advantage of AI Features?
Redis Cloud is a managed service provided by Redis Labs. You have the option to create a Redis environment and an underlying cloud provider (AWS, Azure, or GCP) as needed. Your created environment will be inside a separate account within an AWS VPC. To map your environment (AWS account) to it, you have to use VPC Peering. Your set of services will be inside your VPC, and you have to VPC peer to the Redis Cloud Instance VPC. Alternative options like AWS PrivateLink, Public internet (with security groups), and AWS Transit Gateway are also possible to connect to the Redis environment. Once your VPC is connected to the respective Redis VPC, you can take advantage of Redis AI Offerings. Your applications will interact with the Redis instances hosted in Redis Cloud via the respective SDK.
Another option is to use a self-hosted Redis Stack on your EC2 instance. While this offers more flexibility, the management overhead related to maintaining EC2 servers, their cost, availability, and upgrading Redis Stack remains with you. Self-hosted Redis Stack on EC2 costs ₹5,000-₹20,000/month in direct AWS charges but requires significant engineering time for setup, maintenance, and operations. Redis Cloud costs ₹8,000-₹25,000/month but is fully managed with zero operational overhead. While self-hosted appears cheaper upfront, Redis Cloud often provides a better total cost of ownership when factoring in engineering resources and operational complexity.
MCP Server: How It Helps ?
This is a natural question for most developers: What is the need for an MCP Server for a cache service like Redis? From above, we could see applications interact with Redis (whether it’s managed services like ElastiCache or MemoryDB, or a self-hosted Redis Stack) primarily through Redis protocol/SDKs. The MCP Server allows one to interact with underlying Redis services through Natural Language. This is achieved through a combination of LLM (AI models) plus the MCP server (which allows a protocol for LLMs to interact and initiate actions). The MCP server manages user actions. I’ll provide a few samples for common Redis operations here:
Basic Data Operations:
User: “Store user John with email john@example.com” Redis MCP: Executes → HSET user:john email "john@example.com"
User: “Get all information about user John” Redis MCP: Executes → HGETALL user:john
User: “Delete user John’s data” Redis MCP: Executes → DEL user:john
Search and Analytics
User: “Show me all users who logged in today” Redis MCP: Executes → ZRANGEBYSCORE login_times [today_timestamp] +inf
User: “Find the top 10 most active users this week” Redis MCP: Executes → ZREVRANGE user_activity 0 9 WITHSCORES
User: “How many users are currently online?” Redis MCP: Executes → SCARD online_users
Ecommerce Examples
User: “Add iPhone to John’s shopping cart” Redis MCP: Executes → SADD cart:john "iPhone"
User: “What’s in Sarah’s cart and how much does it cost?” Redis MCP: Executes → SMEMBERS cart:sarah + price lookups
User: “Show me products viewed more than 100 times” Redis MCP: Executes → ZRANGEBYSCORE product_views 100 +inf
Session Management
User: “Is user session abc123 still active?” Redis MCP: Executes → EXISTS session:abc123
User: “Extend user session for another hour” Redis MCP: Executes → EXPIRE session:abc123 3600
User: “Show all active sessions from the last 30 minutes” Redis MCP: Executes → ZRANGEBYSCORE active_sessions [30min_ago] +inf
User: “Cache this API response for 10 minutes” Redis MCP: Executes → SETEX api:response:123 600 "response_data"
User: “Clear all cached data older than 1 hour” Redis MCP: Executes → Custom script with TTL checks
User: “How much memory is Redis using?” Redis MCP: Executes → INFO memory
The key advantage is that non-technical users can interact with Redis data using plain English instead of learning Redis commands, while developers get the full power of Redis operations translated automatically.
Real-World Use Cases with Redis MCP Server
As it’s relatively new and too early to adopt as of this writing, there is a potential for the Redis MCP server. I’ve consolidated a few and provided them below:
Potential Early Use Cases for Redis MCP Server
DevOps and Operations:
Monitoring dashboards: “Show me Redis memory usage trends for the last hour”
Troubleshooting: “Find all keys that are consuming the most memory”
Performance analysis: “Which Redis operations are slowest today?”
Capacity planning: “How many active sessions do we have right now?”
Business Intelligence and Analytics:
Real-time metrics: “What are our top-selling products this week?”
User behavior: “How many users logged in from mobile devices today?”
A/B testing: “Compare conversion rates between test groups”
Revenue tracking: “Show me hourly sales data for the past 24 hours”
AI and Chatbot Integration:
Customer support bots: “Check if user’s session is still active”
Recommendation engines: “Get user’s recently viewed products”
Personalization: “What are this user’s preferences and settings?”
Content delivery: “Retrieve cached content for this geographic region”
Developer Productivity Tools:
Debugging interfaces: “Show me all failed login attempts in the last 10 minutes”
Data exploration: “List all users who have incomplete profiles”
Testing environments: “Clear all test data from yesterday”
API development: “Cache this API response for 5 minutes”
Internal Business Tools:
Admin panels: “How many premium subscribers do we have?”
Reporting systems: “Generate user engagement report for last month”
Inventory management: “Check stock levels for products in the cart”
Fraud detection: “Show suspicious login patterns from last week”
These use cases focus on making Redis data accessible to non-technical stakeholders and improving developer productivity through natural language interfaces.
Implementing a Redis MCP Server in AWS
A Redis MCP Server can be implemented using a self-hosted Redis Stack on EC2 or by using Redis Cloud with AWS. Additionally, you can also install a Redis MCP Server as a Fargate instance and connect to your AWS ElastiCache or MemoryDB managed services. We will now explore each of these implementations using .NET.
Let’s start with the self-hosted EC2 Instance. Spin up a new EC2 instance in AWS and connect using SSH.
docker run -d -p 6379:6379 -p 3000:3000 redis/redis-stack:latest npm install -g @redis/mcp-server redis-mcp-server --redis-url redis://localhost:6379 --port 3000
And from your .NET application, you can connect to your Redis MCP server. Please be aware that for simplicity, we are keeping the MCP Server and Redis instance on the same EC2. In a real-world application, the MCP and actual Redis instance can be separate.
public class SelfHostedRedisService { private readonly HttpClient _mcpClient; private readonly IConnectionMultiplexer _directRedis; public SelfHostedRedisService() { _mcpClient = new HttpClient { BaseAddress = new Uri("http://your-ec2-ip:3000") }; _directRedis = ConnectionMultiplexer.Connect("your-ec2-ip:6379"); } // Natural language via MCP public async Task<string> QueryNaturalLanguage(string query) { var request = new { query = query }; var response = await _mcpClient.PostAsJsonAsync("/query", request); return await response.Content.ReadAsStringAsync(); } // Direct Redis access public async Task<string> GetDirect(string key) { var db = _directRedis.GetDatabase(); return await db.StringGetAsync(key); } }
Data Flow
[Your .NET App] → [EC2:3000 MCP Server] → [EC2:6379 Redis Stack] → Response
Redis MCP Server on Redis Cloud with AWS
The second approach is to use Redis Cloud. This helps to get all the benefits offered by Redis Cloud with the least management overhead, but you have to consider the cost aspects. By leveraging Redis Cloud, you get all the up-to-date features offered by Redis Cloud. Let’s see how this works in reality.
For the Redis Cloud approach, you first sign up at redis.com and create a Redis database instance by selecting AWS as your cloud provider to ensure optimal connectivity and performance. Then, you deploy an MCP server on AWS EC2 or Fargate that connects to your Redis Cloud endpoint. Configure VPC peering or PrivateLink between your AWS environment and Redis Cloud for secure connectivity. Finally, connect your .NET Core application to both the MCP server for natural language queries and directly to Redis Cloud for standard operations using the provided connection string that includes authentication credentials.
Once this is done, set the connection string details in your .NET Core application’s appsettings.json.
{ "RedisCloud": { "ConnectionString": "redis://:your-password@redis-12345.c1.us-east-1-1.ec2.cloud.redislabs.com:12345", "MCPEndpoint": "http://your-mcp-server-ip:3000" } }
And in your application, you simply connect to the Redis MCP server. The main code areas are the RedisCloudService which connects to the MCP endpoint, and the RedisController.cs which simply uses the RedisCloudService.
public class RedisCloudService { private readonly HttpClient _mcpClient; private readonly IConnectionMultiplexer _redisCloud; public RedisCloudService(IConfiguration config) { // MCP Server (your AWS infrastructure) _mcpClient = new HttpClient { BaseAddress = new Uri(config["RedisCloud:MCPEndpoint"]) }; // Redis Cloud (external managed service) var connectionString = config["RedisCloud:ConnectionString"]; _redisCloud = ConnectionMultiplexer.Connect(connectionString); } // Natural language via MCP server public async Task<string> QueryNaturalLanguage(string query) { var request = new { query = query, database = "redis-cloud" }; var response = await _mcpClient.PostAsJsonAsync("/api/query", request); return await response.Content.ReadAsStringAsync(); } // Direct Redis Cloud access public async Task<string> GetDirectFromCloud(string key) { var db = _redisCloud.GetDatabase(); return await db.StringGetAsync(key); } // Store data in Redis Cloud public async Task SetInCloud(string key, string value, TimeSpan? expiry = null) { var db = _redisCloud.GetDatabase(); await db.StringSetAsync(key, value, expiry); } }
[ApiController] [Route("api/[controller]")] public class RedisController : ControllerBase { private readonly RedisCloudService _redisService; public RedisController(RedisCloudService redisService) { _redisService = redisService; } [HttpPost("ask")] public async Task<IActionResult> AskRedis([FromBody] NaturalLanguageRequest request) { try { var result = await _redisService.QueryNaturalLanguage(request.Query); // Changed AskRedis to QueryNaturalLanguage return Ok(new { query = request.Query, result = result }); } catch (Exception ex) { return BadRequest(new { error = ex.Message }); } } [HttpGet("get/{key}")] public async Task<IActionResult> GetValue(string key) { try { var value = await _redisService.GetDirectFromCloud(key); // Changed GetDirect to GetDirectFromCloud return Ok(new { key = key, value = value }); } catch (Exception ex) { return BadRequest(new { error = ex.Message }); } } [HttpPost("set")] public async Task<IActionResult> SetValue([FromBody] SetValueRequest request) { try { await _redisService.SetInCloud(request.Key, request.Value, request.ExpiryMinutes.HasValue ? TimeSpan.FromMinutes(request.ExpiryMinutes.Value) : (TimeSpan?)null); // Changed SetDirect to SetInCloud and added TimeSpan conversion return Ok(new { message = "Value set successfully" }); } catch (Exception ex) { return BadRequest(new { error = ex.Message }); } } [HttpPost("query-analytics")] public async Task<IActionResult> QueryAnalytics([FromBody] NaturalLanguageRequest request) { try { var result = await _redisService.QueryNaturalLanguage($"Analytics: {request.Query}"); // Changed AskRedis to QueryNaturalLanguage return Ok(new { query = request.Query, analytics = result }); } catch (Exception ex) { return BadRequest(new { error = ex.Message }); } } } public class NaturalLanguageRequest { public string Query { get; set; } } public class SetValueRequest { public string Key { get; set; } public string Value { get; set; } public int? ExpiryMinutes { get; set; } }
The application can query using natural language as given below. The data flow is as follows:
- .NET app sends natural language query to MCP server
- MCP server (on AWS) translates to Redis commands
- MCP server connects to Redis Cloud database
- Redis Cloud processes commands and returns data
- MCP server formats response back to .NET app
Redis MCP Server on AWS Fargate
Finally, we could use the serverless option, which is AWS Fargate, to connect to Redis Cloud.
FROM node:18-alpine RUN npm install -g @redis/mcp-server EXPOSE 3000 CMD ["redis-mcp-server", "--redis-url", "$REDIS_CLOUD_URL", "--port", "3000", "--host", "0.0.0.0"]
This allows your serverless services to connect via AWS Fargate. The difference with this approach compared to the EC2 approach is that you don’t have to manage an EC2 instance and can save EC2 cost. AWS Fargate allows you to keep persistent connections with Redis Cloud and is always available for requests, thus this model is suitable for serverless scenarios, and the cost will be much cheaper than that of EC2. You cannot use AWS Lambda here as AWS Lambda functions are short-running services that run on demand and lack persistent connections.
Conclusion
Before winding up, we’ll quickly touch on a few other AI-related offerings from Redis. I will provide you with reference links to explore more. These are additional features added on top of Redis, so all that we discussed related to .NET Core still applies. To utilize these services, you need either Redis Cloud with AWS or a self-hosted Redis Stack in EC2. The AWS Fargate option is applicable only for utilizing the Redis MCP Server.
Redis AI Offerings Summary
- RedisAI: Machine learning model serving platform that allows you to run AI models directly within Redis, supporting TensorFlow, PyTorch, and ONNX models for real-time inference with sub-millisecond latency. Learn more: https://redis.io/docs/stack/ai/
- RediSearch with Vector Similarity: Full-text search engine with vector similarity search capabilities, enabling semantic search, recommendation systems, and similarity matching using vector embeddings for AI applications. Learn more: https://redis.io/docs/stack/search/
- RedisJSON with AI Integration: JSON document database that works seamlessly with AI workflows, allowing storage and querying of complex JSON documents containing embeddings, metadata, and AI model outputs. Learn more: https://redis.io/docs/stack/json/
- RedisGraph: Graph database for AI applications requiring relationship analysis, social networks, fraud detection, and recommendation engines with graph-based machine learning algorithms. Learn more: https://redis.io/docs/stack/graph/
- RedisTimeSeries: Time-series database optimized for AI/ML workloads, IoT data, monitoring metrics, and real-time analytics with built-in aggregation and downsampling capabilities. Learn more: https://redis.io/docs/stack/timeseries/
- RedisGears: Programmable data processing engine that enables real-time data transformations, ETL pipelines, and AI model triggering based on data changes within Redis. Learn more: https://redis.io/docs/stack/gears/
- RedisBloom: Probabilistic data structures for AI applications including Bloom filters, Cuckoo filters, Count-Min sketches, and Top-K for approximate analytics and machine learning feature engineering. Learn more: https://redis.io/docs/stack/bloom/
- General Redis Stack Documentation: https://redis.io/docs/stack/
Disclaimer : All opinions are personal.
Top comments (0)