search button
78c3230bc9779ffaaad1f48e3e95fe6636c5c436
2 files changed
RedisGui/FormMain.Designer.csRedisGui/FormMain.cs
diff --git a/RedisGui/FormMain.Designer.cs b/RedisGui/FormMain.Designer.cs
index 9ae2e87..b65c547 100644
--- a/RedisGui/FormMain.Designer.cs
+++ b/RedisGui/FormMain.Designer.cs
@@ -36,6 +36,9 @@
toolStripStatusLabel1 = new ToolStripStatusLabel();
splitContainer1 = new SplitContainer();
splitContainer2 = new SplitContainer();
+ txtMaxKeys = new TextBox();
+ label4 = new Label();
+ txtSearch = new TextBox();
treeView1 = new TreeView();
imageList1 = new ImageList(components);
label3 = new Label();
@@ -56,10 +59,7 @@
timer1 = new System.Windows.Forms.Timer(components);
contextMenuStrip3 = new ContextMenuStrip(components);
deleteKeyToolStripMenuItem = new ToolStripMenuItem();
- label1 = new Label();
- txtSearch = new TextBox();
- label4 = new Label();
- txtMaxKeys = new TextBox();
+ button1 = new Button();
menuStrip1.SuspendLayout();
statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
@@ -141,10 +141,10 @@
//
// splitContainer2.Panel1
//
+ splitContainer2.Panel1.Controls.Add(button1);
splitContainer2.Panel1.Controls.Add(txtMaxKeys);
splitContainer2.Panel1.Controls.Add(label4);
splitContainer2.Panel1.Controls.Add(txtSearch);
- splitContainer2.Panel1.Controls.Add(label1);
splitContainer2.Panel1.Controls.Add(treeView1);
//
// splitContainer2.Panel2
@@ -159,6 +159,30 @@
splitContainer2.SplitterWidth = 10;
splitContainer2.TabIndex = 0;
//
+ // txtMaxKeys
+ //
+ txtMaxKeys.Location = new Point(279, 10);
+ txtMaxKeys.Name = "txtMaxKeys";
+ txtMaxKeys.Size = new Size(41, 23);
+ txtMaxKeys.TabIndex = 4;
+ txtMaxKeys.Text = "100";
+ //
+ // label4
+ //
+ label4.AutoSize = true;
+ label4.Location = new Point(219, 13);
+ label4.Name = "label4";
+ label4.Size = new Size(54, 15);
+ label4.TabIndex = 3;
+ label4.Text = "MaxKeys";
+ //
+ // txtSearch
+ //
+ txtSearch.Location = new Point(3, 10);
+ txtSearch.Name = "txtSearch";
+ txtSearch.Size = new Size(143, 23);
+ txtSearch.TabIndex = 2;
+ //
// treeView1
//
treeView1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
@@ -223,7 +247,7 @@
listView1.GridLines = true;
listView1.Location = new Point(12, 49);
listView1.Name = "listView1";
- listView1.Size = new Size(645, 248);
+ listView1.Size = new Size(639, 248);
listView1.TabIndex = 0;
listView1.UseCompatibleStateImageBehavior = false;
listView1.View = View.Details;
@@ -250,7 +274,7 @@
txtData.Name = "txtData";
txtData.ReadOnly = true;
txtData.ScrollBars = ScrollBars.Both;
- txtData.Size = new Size(1000, 164);
+ txtData.Size = new Size(1000, 158);
txtData.TabIndex = 5;
//
// contextMenuStrip1
@@ -316,38 +340,15 @@
deleteKeyToolStripMenuItem.Text = "Delete Key";
deleteKeyToolStripMenuItem.Click += DeleteKeyToolStripMenuItem_Click;
//
- // label1
- //
- label1.AutoSize = true;
- label1.Location = new Point(9, 13);
- label1.Name = "label1";
- label1.Size = new Size(41, 15);
- label1.TabIndex = 1;
- label1.Text = "search";
+ // button1
//
- // txtSearch
- //
- txtSearch.Location = new Point(56, 10);
- txtSearch.Name = "txtSearch";
- txtSearch.Size = new Size(157, 23);
- txtSearch.TabIndex = 2;
- //
- // label4
- //
- label4.AutoSize = true;
- label4.Location = new Point(219, 13);
- label4.Name = "label4";
- label4.Size = new Size(54, 15);
- label4.TabIndex = 3;
- label4.Text = "MaxKeys";
- //
- // txtMaxKeys
- //
- txtMaxKeys.Location = new Point(279, 10);
- txtMaxKeys.Name = "txtMaxKeys";
- txtMaxKeys.Size = new Size(41, 23);
- txtMaxKeys.TabIndex = 4;
- txtMaxKeys.Text = "100";
+ button1.Location = new Point(152, 10);
+ button1.Name = "button1";
+ button1.Size = new Size(61, 23);
+ button1.TabIndex = 5;
+ button1.Text = "search";
+ button1.UseVisualStyleBackColor = true;
+ button1.Click += Search_Click;
//
// FormMain
//
@@ -409,13 +410,12 @@
private ToolStripSeparator toolStripSeparator1;
private ToolStripMenuItem closeConnectionToolStripMenuItem;
private System.Windows.Forms.Timer timer1;
- private ToolStripSplitButton toolStripSplitButton1;
private ToolStripStatusLabel toolStripStatusLabel1;
private ContextMenuStrip contextMenuStrip3;
private ToolStripMenuItem deleteKeyToolStripMenuItem;
private TextBox txtMaxKeys;
private Label label4;
private TextBox txtSearch;
- private Label label1;
+ private Button button1;
}
}
diff --git a/RedisGui/FormMain.cs b/RedisGui/FormMain.cs
index d44b706..447c300 100644
--- a/RedisGui/FormMain.cs
+++ b/RedisGui/FormMain.cs
@@ -3,6 +3,7 @@ using RedisGui.Properties;
using StackExchange.Redis;
using System.Diagnostics;
using System.Net;
+using System.Windows.Forms;
namespace RedisGui;
@@ -45,54 +46,11 @@ public partial class FormMain : Form
var node = this.treeView1.Nodes.Add("", endPoint.ToString(), 1, 1);
- await LoadKeysAsync(node);
+ await SearchAsync();
this.timer1.Start();
}
- private async Task<List<RedisKey>> SearchRedisKeysAsync(string key)
- {
- if (this.server == null)
- return [];
-
- _ = int.TryParse(this.txtMaxKeys.Text, out int PageSize);
-
- IAsyncEnumerator<RedisKey> keysAsync = this.server
- .KeysAsync(pattern: $"{key}*", pageSize: PageSize)
- .GetAsyncEnumerator();
- List<RedisKey> keys = [];
- while (await keysAsync.MoveNextAsync())
- {
- keys.Add(keysAsync.Current);
- }
- return keys;
- }
-
-
- private async Task LoadKeysAsync(TreeNode node)
- {
- if (this.server == null)
- return;
-
- try
- {
- var strSearch = this.txtSearch.Text.Trim();
-
- var keys = await SearchRedisKeysAsync(strSearch);
-
- node.Nodes.Clear();
-
- foreach (var key in keys)
- {
- node.Nodes.Add(new TreeNode(key, 2, 2));
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show($"Error loading keys: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
-
private void TreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
if (e.Node == null)
@@ -309,7 +267,28 @@ public partial class FormMain : Form
this.toolStripStatusLabel1.Image = Resources.green;
- var keys = await SearchRedisKeysAsync(string.Empty);
+ await SearchAsync();
+
+ this.toolStripStatusLabel1.Image = Resources.blue;
+ }
+
+ private async Task SearchAsync()
+ {
+ if (this.server == null)
+ return;
+
+ var strSearch = this.txtSearch.Text.Trim();
+
+ _ = int.TryParse(this.txtMaxKeys.Text, out int PageSize);
+
+ IAsyncEnumerator<RedisKey> keysAsync = this.server
+ .KeysAsync(pattern: $"{strSearch}*", pageSize: PageSize)
+ .GetAsyncEnumerator();
+ List<RedisKey> keys = [];
+ while (await keysAsync.MoveNextAsync())
+ {
+ keys.Add(keysAsync.Current);
+ }
foreach (TreeNode connectionNode in this.treeView1.Nodes)
{
@@ -328,7 +307,6 @@ public partial class FormMain : Form
}
}
- this.toolStripStatusLabel1.Image = Resources.blue;
}
private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
@@ -336,6 +314,11 @@ public partial class FormMain : Form
this.Close();
}
+ private async void Search_Click(object sender, EventArgs e)
+ {
+ await SearchAsync();
+ }
+
private async void DeleteKeyToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.db == null)
@@ -357,4 +340,5 @@ public partial class FormMain : Form
}
}
+
}