Skip to content

redis-field-engineering/redis-smart-cache-cli

Repository files navigation

Redis Smart Cache CLI

The Redis Smart Cache CLI is a tool for managing and configuring Redis Smart Cache.

This CLI lets you view your application’s queries, analyze query performance, and select which queries you want cached.

Installation

Homebrew

You can install the Redis Smart Cache CLI by running:

brew install redis-field-engineering/tap/smart-cache-cli

Download the Binaries

You can also download the Redis Smart Cache CLI binaries directly, select the latest release to download. We provide builds for Linux, macOS, and Windows, across a variety of architectures.

Usage

There are two ways to use the CLI:

  1. In interactive mode, you can navigate the CLI’s menus to observe the queries and tables being profiled by Smart Cache. You can then apply updates to the rules used to guide Smart Cache’s caching decisions.

  2. In scripted mode, you can run ad-hoc commands. This is useful when scripting interactions with Smart Cache.

Common Flags

Flag Name Shortcut Type Description Default

--application

-s

string

The application namespace to use

smartcache

--host

-n

string

Host to connect to Redis on

localhost

--port

-p

string

Port to connect to Redis on

6379

--user

-u

string

User to authenticate to Redis with

default

--password

-a

string

Redis password

--help

Interactive

To run Redis Smart Cache CLI in interactive mode, execute smart-cache-cli with the flags needed to connect to your Redis instance. You’ll then see a text-based dialog with the following options:

  1. List Queries

  2. Rule List

  3. Create Rule

  4. Table List

List Queries

The List Queries table shows you the queries that Smart Cache is currently tracking:

Query List Table

This dialog lets you choose which queries you want to create rules for. To create a pending rule for a given query, select the query you want and then press return. This will open a rule dialog which will show you expanded details for the query. You can then provide a TTL, which will enable caching for this query.

Query Rule Dialog

List Rules

The List Rules dialog displays the rules currently in force for Smart Cache. You can batch the creation, editing, and deletion of rules.

Rule List

Rule Creation

The Rule Creation dialog allows you to create and prioritize caching rules.

Rule Creation Dialog

Table List

The Table List view provides you a table-level view of the profiling done by Smart Cache.

You can see your tables, their access frequency, and the mean query time for all queries executed against them. You can also see whether a query is cached, including the configured TTL for any cached queries.

Table List

Non-Interactive Commands

The Smart Cache CLI provides several non-interactive (i.e., scriptable) commands. These include:

  1. List Queries

  2. Create Rules

List Queries

The List Queries command lists the queries seen by Smart Cache. Example:

smart-cache-cli listqueries

List Queries

List Queries flags
Flag Name Shortcut Type Description Default

--sortDirection

-d

string

The direction to sort by. Valid options include DESC and ASC.

DESC

--sortby

-b

string

The column to sort by. Valid options include 'queryTime', 'accessFrequency', 'tables', and 'id'.

queryTime

Rule Creation

The makerule command lets you create rules on the fly. This command is non-interactive (i.e., scriptable) when you include the y flag (to confirm rule creation). See the flag descriptions below for details:

Rule Creation Flags
Flag Name Shortcut Type Description required

--ttl

-t

string

The time to live as a duration (e.g. 5m, 300s, 2d) the rule. Essentially, this is how long the query will be cached for.

yes

--confirm

-y

Provide this flag with a value of -y to run this command in non-interactive (i.e., scripted) mode.

no

--queryIds

-q

string

Comma-delimited unordered list of the IDs of the queries that the rule will apply to.

no

--regex

-r

string

The regex to use to match this rule. If the regex matches, the rule will apply.

no

--tablesAll

-l

string

Comma-delimited unordered set of table names. Matches if all of these tables in the set appear in the query (other tables may appear, as well).

no

--tablesAny

-x

string

Comma-delimited unordered set of table names. Matches if any of these tables appear in the query.

no

--tablesExact

-e

string

Comma-delimited unordered set of table names. Matches of all of these tables – and no others – appear in the query.

no

Support

Redis Smart Cache CLI is supported by Redis, Inc. on a good faith effort basis. To report bugs, request features, or receive assistance, please file an issue.

License

Redis Smart Cache CLI is licensed under the MIT License. Copyright © 2023 Redis, Inc.