Overview

Synopsis

  • clearing your Redis Cache involves logging in to a server containing your Redis instance and running a few Redis commands to flush the cache
  • it doesn’t matter if you have your own server with a Redis cache installation, or hosted in the Cloud like in AWS Elasticache or Azure Cache for Redis, you can login just the same
  • there is a tool redis-cli available, but what if you don’t want to build it yourself, or you simply can’t, also this tool is only available in Linux, in this situation, we want to be able to do it from a Windows machine
  • there is a Linux networking utility called Netcat that can easily remotely connect to servers. There is also a port of this for Windows which we use in this post
  • so first you connect to your Redis cache with:
    nc <ipaddress of redis server> <port of redis server>
    // once connected, run the following Redis commands
    SELECT 0 // specify your Redis index here
    +OK      // Redis reply 
    FLUSHDB  // now flush that DB index
    +OK      // Redis reply
    QUIT     // and then disconnect
    +OK      // Redis reply
    

    Now that’s nice, however it is not clear what you need to do if you want to do this operation remotely from a Windows machine and plug it into your CI/CD system.

  • Powershell to the rescue!

Here is the Powershell script

It is surprisingly simple and can be done in a couple of lines of Powershell.

  $redisCommands = "SELECT $redisDBIndex`r`nFLUSHDB`r`nQUIT`r`n"
  $redisCommands | .\nc $redisServer 6379

In the first line, we are setting up the 3 Redis commands, but separating them in it’s own line (crlf). Because we are in Powershell we have the pipe (|) operator to make things easy. We simply pipe the commands to nc.

As simple as that.

2023

Back to top ↑

2022

Back to top ↑

2021

Back to top ↑

2020

DynamoDB and Single-Table Design

9 minute read

Follow along as I implement DynamoDB Single-Table Design - find out the tools and methods I use to make the process easier, and finally the light-bulb moment...

Back to top ↑

2019

Website Performance Series - Part 3

5 minute read

Speeding up your site is easy if you know what to focus on. Follow along as I explore the performance optimization maze, and find 3 awesome tips inside (plus...

Back to top ↑