Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions BulkUpdateConfirmation/BulkUpdateConfirmation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package BulkUpdateConfirmation

import (
"fmt"
"smart-cache-cli/RedisCommon"
"strings"

"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/redis/go-redis/v9"
"smart-cache-cli/RedisCommon"
"strings"
)

func (m Model) Init() tea.Cmd {
Expand Down Expand Up @@ -69,7 +70,7 @@ func (m Model) View() string {
}
}

body.WriteString("y/N")
body.WriteString("Do you want to continue? (y/N)")
return body.String()
}

Expand Down
8 changes: 4 additions & 4 deletions ConfirmationDialog/confirmation.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ func (m Model) View() string {
noun = "rules"
}

body.WriteString(fmt.Sprintf("Would you like to commit the following %s to Redis?\n", noun))
body.WriteString("=============Rules To Commit==============\n")
body.WriteString(fmt.Sprintf("Would you like to commit the following caching %s?\n", noun))
body.WriteString("============= Rules to Commit ==============\n")
for _, r := range m.pendingRules {
body.WriteString(r.Formatted())
body.WriteString("\n")

}

body.WriteString("===========================================\n")
body.WriteString("y/N")
body.WriteString("============================================\n")
body.WriteString("(y)es / (N)o?")
return body.String()
}

Expand Down
29 changes: 15 additions & 14 deletions RedisCommon/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/charmbracelet/lipgloss"
"github.com/evertras/bubble-table/table"
"github.com/redis/go-redis/v9"
"hash/fnv"
"reflect"
"regexp"
Expand All @@ -16,6 +13,10 @@ import (
"sort"
"strconv"
"strings"

"github.com/charmbracelet/lipgloss"
"github.com/evertras/bubble-table/table"
"github.com/redis/go-redis/v9"
)

var ctx = context.Background()
Expand Down Expand Up @@ -319,18 +320,18 @@ func splitAcrossLines(s string, width int) string {
func (query *Query) Formatted(width int) string {
builder := strings.Builder{}

builder.WriteString("Query Details:\n")
builder.WriteString("=== Query Details ===\n\n")
builder.WriteString(fmt.Sprintf("Id:\t\t\t%s\n", query.Id))
builder.WriteString(fmt.Sprintf("Pending Rule:\t%s\n", GetPendingOrEmptyString(query)))
builder.WriteString(fmt.Sprintf("Pending rule:\t%s\n", GetPendingOrEmptyString(query)))
builder.WriteString(fmt.Sprintf("Key:\t\t\t%s\n", query.Key))
builder.WriteString(fmt.Sprintf("Table:\t\t\t%s\n", query.Table))
if len(query.Sql)+4 > width {
builder.WriteString(fmt.Sprintf("SQL:\n\n%s\n\n", splitAcrossLines(query.Sql, width)))
} else {
builder.WriteString(fmt.Sprintf("SQL:%s\n", query.Sql))
}
builder.WriteString(fmt.Sprintf("Access Frequency %s\n", strconv.Itoa(query.Count)))
builder.WriteString(fmt.Sprintf("Mean Query Time: %.2fms\n", query.MeanTime))
builder.WriteString(fmt.Sprintf("Access frequency %s\n", strconv.Itoa(query.Count)))
builder.WriteString(fmt.Sprintf("Mean query time: %.2fms\n", query.MeanTime))
builder.WriteString(fmt.Sprintf("Current TTL: %s\n", GetTtlOrEmptyString(query)))

return builder.String()
Expand Down Expand Up @@ -384,7 +385,7 @@ func GetHeader(colWidth int) string {
func (r Rule) GetJson() string {
b, err := json.Marshal(r)
if err != nil {
fmt.Println("unable to serialize rule")
fmt.Println("Error: Unable to serialize rule.")
panic(r)
}

Expand Down Expand Up @@ -443,7 +444,7 @@ func GetQueries(rdb *redis.Client, applicationName string) ([]*Query, error) {

arr, ok := res.([]interface{})
if !ok {
return nil, errors.New("failed to parse result from Redis")
return nil, errors.New("Error: Failed to parse result from Redis")
}

queries := make(map[string]*Query)
Expand Down Expand Up @@ -599,13 +600,13 @@ func GetRules(rdb *redis.Client, applicationName string) ([]Rule, error) {
value := res[0].Values[key]
split := strings.Split(key, ".")
if len(split) < 3 {
fmt.Printf("Skipping invalid rule %s\n", res[0].Values[key])
fmt.Printf("Skipping invalid rule '%s'\n", res[0].Values[key])
continue
}

ruleNum, err := strconv.Atoi(split[1])
if err != nil {
fmt.Printf("skipping rule %s invalid rule number %s\n", key)
fmt.Printf("Skipping rule '%s'. Invalid rule number %s\n", key)
continue
}

Expand Down Expand Up @@ -836,7 +837,7 @@ func UpdateRules(rdb *redis.Client, rulesToAdd []Rule, rulesToUpdate map[int]Rul

for index, rule := range rulesToUpdate {
if index >= len(currentRules) {
return fmt.Errorf("unable to update rules, rules out of sync")
return fmt.Errorf("Unable to update rules: rules out of sync.")
}

rulesToCommit[index] = rule
Expand Down Expand Up @@ -901,8 +902,8 @@ func CheckSmartCacheIndex(rdb *redis.Client, applicationName string) error {
}

if !contains(strs, fmt.Sprintf("%s-query-idx", applicationName)) {
return errors.New(fmt.Sprintf("smart cache does not appear to be configured to be configured for keyspace %s - "+
"please ensure that smart cache is confgigured and pointed at the configured instance of Redis", applicationName))
return errors.New(fmt.Sprintf("Redis Smart Cache does not appear to be configured for application '%s'. "+
"Please ensure that Redis Smart Cache is running, configured with application '%s', and pointed at the correct Redis instance.", applicationName, applicationName))
}

return nil
Expand Down
19 changes: 10 additions & 9 deletions RuleList/RuleList.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package RuleList

import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/evertras/bubble-table/table"
"github.com/redis/go-redis/v9"
"smart-cache-cli/BulkUpdateConfirmation"
"smart-cache-cli/ConfirmationDialog"
"smart-cache-cli/RedisCommon"
"smart-cache-cli/RuleDialog"
"smart-cache-cli/SortDialog"
"smart-cache-cli/util"
"strings"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/evertras/bubble-table/table"
"github.com/redis/go-redis/v9"
)

type Model struct {
Expand Down Expand Up @@ -187,11 +188,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m Model) View() string {
body := strings.Builder{}

body.WriteString("Press ctrl+c or q to quit\n")
body.WriteString("press b to go back\n")
body.WriteString("press tab or enter or space to edit a rule\n")
body.WriteString("press n to create a rule\n")
body.WriteString("press c to commit rule updates\n")
body.WriteString("Press [CTRL-C] to quit\n")
body.WriteString("press 'b' to go back\n")
body.WriteString("press [ENTER] to edit a rule\n")
body.WriteString("press 'n' to create a rule\n")
body.WriteString("press 'c' to commit rule updates\n")
body.WriteString(m.table.View())

return body.String()
Expand Down
7 changes: 4 additions & 3 deletions RuleTtlView/RuleTtlView.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package RuleTtlView

import (
"fmt"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"smart-cache-cli/RedisCommon"
"smart-cache-cli/util"

"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
)

type TableTtlMsg struct {
Expand Down Expand Up @@ -52,7 +53,7 @@ func (m Model) Init() tea.Cmd {
}

func (m Model) View() string {
return fmt.Sprintf("%s\n\nPress ctrl+b or escape to return to the previous screen\nInput TTL in the form of a duration e.g. 1h, 300s, 5m:\n%s%s", m.table.Formatted(), m.textInput.View(), m.err)
return fmt.Sprintf("%s\n\nPress [ESC] to return to the previous screen.\nEnter TTL in the form of a duration (e.g. 300s, 5m, 1h):\n%s%s", m.table.Formatted(), m.textInput.View(), m.err)
}

func New(table *RedisCommon.Table, parentModel tea.Model) Model {
Expand Down
7 changes: 4 additions & 3 deletions SortDialog/sortDialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package SortDialog

import (
"fmt"
"io"

"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"io"
)

type Direction string
Expand Down Expand Up @@ -111,7 +112,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m Model) toDirectionMode() list.Model {
const defaultWidth = 50
l := list.New([]list.Item{item(Descending), item(Ascending)}, itemDelegate{}, defaultWidth, listHeight)
l.Title = "Select Sort Direction"
l.Title = "Select sort direction"
l.SetShowStatusBar(false)
l.SetFilteringEnabled(false)
l.Styles.Title = titleStyle
Expand All @@ -131,7 +132,7 @@ func New(candidates []string, parentModel tea.Model) Model {
}
const defaultWidth = 50
l := list.New(items, itemDelegate{}, defaultWidth, listHeight)
l.Title = "Select Sort Field"
l.Title = "Select sort field"
l.SetShowStatusBar(false)
l.SetFilteringEnabled(false)
l.Styles.Title = titleStyle
Expand Down
13 changes: 7 additions & 6 deletions TableList/TableList.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package TableList

import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/evertras/bubble-table/table"
"github.com/redis/go-redis/v9"
"smart-cache-cli/ConfirmationDialog"
"smart-cache-cli/RedisCommon"
"smart-cache-cli/RuleTtlView"
"smart-cache-cli/SortDialog"
"strings"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/evertras/bubble-table/table"
"github.com/redis/go-redis/v9"
)

var (
Expand Down Expand Up @@ -90,9 +91,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

func (m Model) View() string {
body := strings.Builder{}
body.WriteString("Press Enter to update the TTL for a table\n")
body.WriteString("Press [ENTER] to update the TTL for a table\n")
body.WriteString("Press 'b' to go back\n")
body.WriteString("Press 's' to change sorting.\n")
body.WriteString("Press 's' to change sorting\n")
body.WriteString(m.table.View())

return body.String()
Expand Down
8 changes: 4 additions & 4 deletions cmd/listqueries.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const (
// listqCmd represents the listq command
var listqCmd = &cobra.Command{
Use: "listqueries",
Short: "List Queries being tracked by smart cache",
Long: `Lists the queries being tracked by `,
Short: "List queries seen by Redis Smart Cache",
Long: `List queries seen by `,
Run: func(cmd *cobra.Command, args []string) {
rdb := redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%s", HostName, Port),
Expand All @@ -53,7 +53,7 @@ var listqCmd = &cobra.Command{
sdLower := strings.ToLower(sortDirection)

if sdLower != string(desc) && sdLower != asc {
fmt.Println(fmt.Sprintf("%s was not a valid sort direction (valid directions are asc/desc)", sortDirection))
fmt.Println(fmt.Sprintf("%s is not a valid sort order. Valid orders are 'ASC' and 'DESC'.", sortDirection))
os.Exit(1)
}

Expand Down Expand Up @@ -89,7 +89,7 @@ func init() {
listqCmd.Flags().StringVarP(&sortby, "sortby", "b", "queryTime", "The field in the"+
" queries table to use to sort. Valid options include 'queryTime', 'accessFrequency', 'tables', and 'id")
listqCmd.Flags().StringVarP(&sortDirection, "sortDirection", "d", "DESC", "the direction to "+
"sort, valid options are 'DESC' and 'ASC'")
"sort. Valid options are 'ASC' and 'DESC'.")

rootCmd.AddCommand(listqCmd)
}
11 changes: 6 additions & 5 deletions cmd/listtables.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ package cmd

import (
"fmt"
"github.com/redis/go-redis/v9"
"os"
"smart-cache-cli/RedisCommon"
"sort"
"strings"

"github.com/redis/go-redis/v9"

"github.com/spf13/cobra"
)

// listtablesCmd represents the listtables command
var listtablesCmd = &cobra.Command{
Use: "listtables",
Short: "List the tables that are profiled by smartcache.",
Long: `List the tables that are profiled by smartcache.`,
Short: "List the tables being profiled by Redis Smart Cache.",
Long: `List the tables being profiled by Redis Smart CAche.`,
Run: func(cmd *cobra.Command, args []string) {
rdb := redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%s", HostName, Port),
Expand All @@ -33,7 +34,7 @@ var listtablesCmd = &cobra.Command{
sdLower := strings.ToLower(sortDirection)

if sdLower != string(desc) && sdLower != asc {
fmt.Println(fmt.Sprintf("%s was not a valid sort direction (valid directions are asc/desc)", sortDirection))
fmt.Println(fmt.Sprintf("%s is not a valid sort order. Valid orders are 'ASC' and 'DESC'.", sortDirection))
os.Exit(1)
}

Expand Down Expand Up @@ -67,7 +68,7 @@ func init() {
listtablesCmd.Flags().StringVarP(&sortby, "sortby", "b", "queryTime", "The field in the"+
" tables table to use to sort. Valid options include 'queryTime', 'accessFrequency'")
listtablesCmd.Flags().StringVarP(&sortDirection, "sortDirection", "d", "DESC", "the direction to "+
"sort, valid options are 'DESC' and 'ASC'")
"sort. Valid options are 'ASC' and 'DESC'.")

rootCmd.AddCommand(listtablesCmd)
}
11 changes: 6 additions & 5 deletions cmd/makerule.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ package cmd

import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/redis/go-redis/v9"
"smart-cache-cli/ConfirmationDialog"
"smart-cache-cli/RedisCommon"
"strings"

tea "github.com/charmbracelet/bubbletea"
"github.com/redis/go-redis/v9"

"github.com/spf13/cobra"
)

// makeruleCmd represents the makerule command
var makeruleCmd = &cobra.Command{
Use: "makerule",
Short: "Create a rule for Smart Cache",
Long: `Creates a rule for Redis Smart Cache.`,
Short: "Create a Redis Smart Cache caching rule",
Long: `Creates a Redis Smart Cache caching rule`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("makerule called")
rdb := redis.NewClient(&redis.Options{
Expand Down Expand Up @@ -71,7 +72,7 @@ var makeruleCmd = &cobra.Command{
if err != nil {
panic(err)
}
fmt.Println("Successfully created rule in Redis.")
fmt.Println("Successfully created caching rule.")
}

},
Expand Down
Loading