-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathredis-command-explorer.html
More file actions
703 lines (675 loc) · 29.5 KB
/
redis-command-explorer.html
File metadata and controls
703 lines (675 loc) · 29.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="images/logo.png">
<link rel="apple-touch-icon" href="images/logo.png">
<title>Redis Command Explorer - DevDunia</title>
<meta name="description" content="Interactive Redis command reference with examples, syntax, and performance tips">
<link rel="icon" type="image/png" href="images/logo.png">
<script src="https://cdn.tailwindcss.com"></script>
<style>
body {
background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
min-height: 100vh;
}
.command-card {
transition: all 0.3s ease;
}
.command-card:hover {
transform: translateY(-2px);
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}
.redis-red {
background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
}
.redis-red-light {
background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}
.command-syntax {
background: #1e293b;
border: 1px solid #334155;
font-family: 'Courier New', monospace;
}
.copy-btn {
transition: all 0.2s ease;
}
.copy-btn:hover {
transform: scale(1.05);
}
.category-active {
background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
color: white;
}
</style>
</head>
<body>
<!-- Sidebar -->
<div id="sidebar-container"></div>
<!-- Main Content -->
<div class="main-content ml-0 lg:ml-64 min-h-screen">
<div class="container mx-auto px-4 py-8">
<!-- Header -->
<div class="text-center mb-8">
<h1 class="text-4xl font-bold text-white mb-4">Redis Command Explorer</h1>
<p class="text-gray-400 text-lg">Interactive Redis command reference with examples and performance tips</p>
</div>
<!-- Search and Filter -->
<div class="bg-slate-800/50 backdrop-blur-lg rounded-xl p-6 border border-slate-700/50 shadow-2xl mb-8">
<div class="flex flex-col lg:flex-row gap-4">
<div class="flex-1">
<input
type="text"
id="command-search"
placeholder="Search Redis commands..."
class="w-full px-4 py-3 bg-slate-700/50 border border-slate-600 rounded-lg text-gray-200 focus:outline-none focus:ring-2 focus:ring-red-500 focus:border-transparent"
>
</div>
<div class="flex flex-wrap gap-2">
<button class="category-btn px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg transition-colors duration-200" data-category="all">
All Commands
</button>
<button class="category-btn px-4 py-2 bg-slate-600 hover:bg-slate-700 text-white rounded-lg transition-colors duration-200" data-category="strings">
Strings
</button>
<button class="category-btn px-4 py-2 bg-slate-600 hover:bg-slate-700 text-white rounded-lg transition-colors duration-200" data-category="lists">
Lists
</button>
<button class="category-btn px-4 py-2 bg-slate-600 hover:bg-slate-700 text-white rounded-lg transition-colors duration-200" data-category="sets">
Sets
</button>
<button class="category-btn px-4 py-2 bg-slate-600 hover:bg-slate-700 text-white rounded-lg transition-colors duration-200" data-category="hashes">
Hashes
</button>
<button class="category-btn px-4 py-2 bg-slate-600 hover:bg-slate-700 text-white rounded-lg transition-colors duration-200" data-category="sorted-sets">
Sorted Sets
</button>
<button class="category-btn px-4 py-2 bg-slate-600 hover:bg-slate-700 text-white rounded-lg transition-colors duration-200" data-category="keys">
Keys
</button>
</div>
</div>
</div>
<!-- Commands Display -->
<div id="commands-container" class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<!-- Commands will be populated here -->
</div>
</div>
</div>
<!-- Include Final Sidebar -->
<div id="sidebar-container"></div>
<script>
// Load final_sidebar.html content
fetch('final_sidebar.html')
.then(response => response.text())
.then(html => {
document.getElementById('sidebar-container').innerHTML = html;
})
.catch(error => {
console.error('Error loading sidebar:', error);
});
</script>
<script>
// Redis Commands Data (ranked by usage frequency - CRUD operations first)
const redisCommands = {
strings: [
{
command: "GET",
syntax: "GET key",
description: "Get the value of a key",
example: "GET mykey",
performance: "O(1)",
useCase: "Retrieve cached data, simple lookups",
usageRank: 1,
frequency: "Very High"
},
{
command: "SET",
syntax: "SET key value [EX seconds] [PX milliseconds] [NX|XX]",
description: "Set the string value of a key",
example: "SET mykey \"Hello World\" EX 3600",
performance: "O(1)",
useCase: "Basic key-value storage, caching, session storage",
usageRank: 2,
frequency: "Very High"
},
{
command: "DEL",
syntax: "DEL key [key ...]",
description: "Delete a key",
example: "DEL mykey",
performance: "O(1) per key",
useCase: "Cleanup, cache invalidation",
usageRank: 3,
frequency: "Very High"
},
{
command: "MGET",
syntax: "MGET key [key ...]",
description: "Get the values of all given keys",
example: "MGET key1 key2 key3",
performance: "O(N)",
useCase: "Batch retrieval, reducing round trips",
usageRank: 4,
frequency: "High"
},
{
command: "MSET",
syntax: "MSET key value [key value ...]",
description: "Set multiple keys to multiple values",
example: "MSET key1 \"Hello\" key2 \"World\"",
performance: "O(N)",
useCase: "Batch operations, bulk data insertion",
usageRank: 5,
frequency: "High"
},
{
command: "EXISTS",
syntax: "EXISTS key [key ...]",
description: "Determine if a key exists",
example: "EXISTS mykey",
performance: "O(1) per key",
useCase: "Validation, conditional operations",
usageRank: 6,
frequency: "High"
},
{
command: "KEYS",
syntax: "KEYS pattern",
description: "Find all keys matching the given pattern",
example: "KEYS user:*",
performance: "O(N)",
useCase: "Debugging, admin operations (avoid in production)",
usageRank: 7,
frequency: "High"
},
{
command: "EXPIRE",
syntax: "EXPIRE key seconds",
description: "Set a key's time to live in seconds",
example: "EXPIRE mykey 3600",
performance: "O(1)",
useCase: "TTL management, cache expiration",
usageRank: 8,
frequency: "Medium"
},
{
command: "TTL",
syntax: "TTL key",
description: "Get the time to live for a key",
example: "TTL mykey",
performance: "O(1)",
useCase: "Monitoring expiration, debugging",
usageRank: 9,
frequency: "Medium"
},
{
command: "INCR",
syntax: "INCR key",
description: "Increment the integer value of a key by one",
example: "INCR counter",
performance: "O(1)",
useCase: "Counters, rate limiting, unique IDs",
usageRank: 10,
frequency: "Medium"
},
{
command: "APPEND",
syntax: "APPEND key value",
description: "Append a value to a key",
example: "APPEND mykey \" World\"",
performance: "O(1)",
useCase: "Logging, building strings incrementally",
usageRank: 11,
frequency: "Low"
}
],
lists: [
{
command: "LPUSH",
syntax: "LPUSH key element [element ...]",
description: "Prepend one or more elements to a list",
example: "LPUSH mylist \"world\" \"hello\"",
performance: "O(1) per element",
useCase: "Stacks, recent items, activity feeds",
usageRank: 11,
frequency: "High"
},
{
command: "RPUSH",
syntax: "RPUSH key element [element ...]",
description: "Append one or more elements to a list",
example: "RPUSH mylist \"item1\" \"item2\"",
performance: "O(1) per element",
useCase: "Queues, FIFO operations, message queues",
usageRank: 12,
frequency: "High"
},
{
command: "LRANGE",
syntax: "LRANGE key start stop",
description: "Get a range of elements from a list",
example: "LRANGE mylist 0 -1",
performance: "O(S+N)",
useCase: "Pagination, retrieving multiple items",
usageRank: 13,
frequency: "Medium"
},
{
command: "LLEN",
syntax: "LLEN key",
description: "Get the length of a list",
example: "LLEN mylist",
performance: "O(1)",
useCase: "Monitoring queue size, validation",
usageRank: 14,
frequency: "Medium"
},
{
command: "LPOP",
syntax: "LPOP key [count]",
description: "Remove and get the first elements in a list",
example: "LPOP mylist",
performance: "O(1) per element",
useCase: "Stack operations, task processing",
usageRank: 15,
frequency: "Medium"
},
{
command: "RPOP",
syntax: "RPOP key [count]",
description: "Remove and get the last elements in a list",
example: "RPOP mylist",
performance: "O(1) per element",
useCase: "Queue operations, LIFO processing",
usageRank: 16,
frequency: "Medium"
}
],
sets: [
{
command: "SADD",
syntax: "SADD key member [member ...]",
description: "Add one or more members to a set",
example: "SADD myset \"member1\" \"member2\"",
performance: "O(1) per member",
useCase: "Unique collections, tags, categories",
usageRank: 17,
frequency: "Medium"
},
{
command: "SMEMBERS",
syntax: "SMEMBERS key",
description: "Get all the members in a set",
example: "SMEMBERS myset",
performance: "O(N)",
useCase: "Retrieving all unique items",
usageRank: 18,
frequency: "Medium"
},
{
command: "SCARD",
syntax: "SCARD key",
description: "Get the number of members in a set",
example: "SCARD myset",
performance: "O(1)",
useCase: "Counting unique items",
usageRank: 19,
frequency: "Medium"
},
{
command: "SREM",
syntax: "SREM key member [member ...]",
description: "Remove one or more members from a set",
example: "SREM myset \"member1\"",
performance: "O(1) per member",
useCase: "Removing items from collections",
usageRank: 20,
frequency: "Low"
},
{
command: "SINTER",
syntax: "SINTER key [key ...]",
description: "Intersect multiple sets",
example: "SINTER set1 set2",
performance: "O(N*M)",
useCase: "Finding common elements, filtering",
usageRank: 21,
frequency: "Low"
},
{
command: "SUNION",
syntax: "SUNION key [key ...]",
description: "Add multiple sets",
example: "SUNION set1 set2",
performance: "O(N)",
useCase: "Combining collections, merging tags",
usageRank: 22,
frequency: "Low"
}
],
hashes: [
{
command: "HGET",
syntax: "HGET key field",
description: "Get the value of a hash field",
example: "HGET user:1000 name",
performance: "O(1)",
useCase: "Retrieving specific object properties",
usageRank: 12,
frequency: "Very High"
},
{
command: "HSET",
syntax: "HSET key field value [field value ...]",
description: "Set the string value of a hash field",
example: "HSET user:1000 name \"John\" age \"30\"",
performance: "O(1) per field",
useCase: "Object storage, user profiles, configurations",
usageRank: 13,
frequency: "Very High"
},
{
command: "HGETALL",
syntax: "HGETALL key",
description: "Get all the fields and values in a hash",
example: "HGETALL user:1000",
performance: "O(N)",
useCase: "Retrieving complete objects",
usageRank: 14,
frequency: "High"
},
{
command: "HKEYS",
syntax: "HKEYS key",
description: "Get all the fields in a hash",
example: "HKEYS user:1000",
performance: "O(N)",
useCase: "Getting object field names",
usageRank: 15,
frequency: "High"
},
{
command: "HDEL",
syntax: "HDEL key field [field ...]",
description: "Delete one or more hash fields",
example: "HDEL user:1000 age",
performance: "O(1) per field",
useCase: "Removing object properties",
usageRank: 16,
frequency: "Medium"
},
{
command: "HINCRBY",
syntax: "HINCRBY key field increment",
description: "Increment the integer value of a hash field",
example: "HINCRBY user:1000 score 10",
performance: "O(1)",
useCase: "Counters within objects, scores",
usageRank: 17,
frequency: "Medium"
}
],
"sorted-sets": [
{
command: "ZADD",
syntax: "ZADD key [NX|XX] [CH] [INCR] score member [score member ...]",
description: "Add one or more members to a sorted set",
example: "ZADD leaderboard 100 \"player1\" 200 \"player2\"",
performance: "O(log N) per member",
useCase: "Leaderboards, rankings, time-series data"
},
{
command: "ZRANGE",
syntax: "ZRANGE key start stop [WITHSCORES]",
description: "Return a range of members in a sorted set",
example: "ZRANGE leaderboard 0 9 WITHSCORES",
performance: "O(log N + M)",
useCase: "Top N queries, pagination"
},
{
command: "ZREVRANGE",
syntax: "ZREVRANGE key start stop [WITHSCORES]",
description: "Return a range of members in a sorted set (reverse)",
example: "ZREVRANGE leaderboard 0 9 WITHSCORES",
performance: "O(log N + M)",
useCase: "Highest scores, recent items"
},
{
command: "ZREM",
syntax: "ZREM key member [member ...]",
description: "Remove one or more members from a sorted set",
example: "ZREM leaderboard \"player1\"",
performance: "O(log N) per member",
useCase: "Removing items from rankings"
},
{
command: "ZCARD",
syntax: "ZCARD key",
description: "Get the number of members in a sorted set",
example: "ZCARD leaderboard",
performance: "O(1)",
useCase: "Counting ranked items"
},
{
command: "ZSCORE",
syntax: "ZSCORE key member",
description: "Get the score associated with the given member",
example: "ZSCORE leaderboard \"player1\"",
performance: "O(1)",
useCase: "Getting specific scores"
}
],
keys: [
{
command: "KEYS",
syntax: "KEYS pattern",
description: "Find all keys matching the given pattern",
example: "KEYS user:*",
performance: "O(N)",
useCase: "Debugging, admin operations (avoid in production)"
},
{
command: "EXISTS",
syntax: "EXISTS key [key ...]",
description: "Determine if a key exists",
example: "EXISTS mykey",
performance: "O(1) per key",
useCase: "Validation, conditional operations"
},
{
command: "DEL",
syntax: "DEL key [key ...]",
description: "Delete a key",
example: "DEL mykey",
performance: "O(1) per key",
useCase: "Cleanup, cache invalidation"
},
{
command: "EXPIRE",
syntax: "EXPIRE key seconds",
description: "Set a key's time to live in seconds",
example: "EXPIRE mykey 3600",
performance: "O(1)",
useCase: "TTL management, cache expiration"
},
{
command: "TTL",
syntax: "TTL key",
description: "Get the time to live for a key",
example: "TTL mykey",
performance: "O(1)",
useCase: "Monitoring expiration, debugging"
},
{
command: "TYPE",
syntax: "TYPE key",
description: "Determine the type stored at key",
example: "TYPE mykey",
performance: "O(1)",
useCase: "Debugging, type validation"
}
]
};
// DOM elements
const searchInput = document.getElementById('command-search');
const commandsContainer = document.getElementById('commands-container');
const categoryButtons = document.querySelectorAll('.category-btn');
let currentCategory = 'all';
let currentSearch = '';
// Initialize
window.addEventListener('load', () => {
displayCommands();
setupEventListeners();
});
function setupEventListeners() {
// Search functionality
searchInput.addEventListener('input', (e) => {
currentSearch = e.target.value.toLowerCase();
displayCommands();
});
// Category filtering
categoryButtons.forEach(btn => {
btn.addEventListener('click', (e) => {
currentCategory = e.target.dataset.category;
updateCategoryButtons();
displayCommands();
});
});
}
function updateCategoryButtons() {
categoryButtons.forEach(btn => {
if (btn.dataset.category === currentCategory) {
btn.classList.add('category-active');
btn.classList.remove('bg-slate-600', 'hover:bg-slate-700');
} else {
btn.classList.remove('category-active');
btn.classList.add('bg-slate-600', 'hover:bg-slate-700');
}
});
}
function displayCommands() {
let commandsToShow = [];
// Filter by category
if (currentCategory === 'all') {
Object.values(redisCommands).flat().forEach(cmd => commandsToShow.push(cmd));
} else {
commandsToShow = redisCommands[currentCategory] || [];
}
// Filter by search
if (currentSearch) {
commandsToShow = commandsToShow.filter(cmd =>
cmd.command.toLowerCase().includes(currentSearch) ||
cmd.description.toLowerCase().includes(currentSearch) ||
cmd.useCase.toLowerCase().includes(currentSearch)
);
}
// Sort by usage rank (most used first)
commandsToShow.sort((a, b) => {
if (currentCategory === 'all') {
// For "all" category, sort by global usage rank
return a.usageRank - b.usageRank;
} else {
// For specific categories, sort by usage rank within that category
return a.usageRank - b.usageRank;
}
});
// Display commands
commandsContainer.innerHTML = '';
commandsToShow.forEach(command => {
const commandCard = createCommandCard(command);
commandsContainer.appendChild(commandCard);
});
// Show message if no results
if (commandsToShow.length === 0) {
commandsContainer.innerHTML = `
<div class="col-span-2 text-center py-12">
<div class="text-gray-400 text-lg">No commands found matching your criteria</div>
<div class="text-gray-500 text-sm mt-2">Try adjusting your search or category filter</div>
</div>
`;
}
}
function createCommandCard(command) {
const card = document.createElement('div');
card.className = 'command-card bg-slate-800/50 backdrop-blur-lg rounded-xl border border-slate-700/50 shadow-2xl p-6';
card.innerHTML = `
<div class="flex items-center justify-between mb-4">
<h3 class="text-xl font-bold text-white">${command.command}</h3>
<div class="flex items-center space-x-2">
<span class="px-2 py-1 bg-red-600 text-xs text-white rounded">Redis</span>
<span class="px-2 py-1 bg-green-600 text-xs text-white rounded">${command.performance}</span>
${command.frequency ? `<span class="px-2 py-1 ${getFrequencyColor(command.frequency)} text-xs text-white rounded">${command.frequency}</span>` : ''}
</div>
</div>
<div class="mb-4">
<div class="flex items-center justify-between mb-2">
<label class="text-sm font-medium text-gray-300">Syntax</label>
<button class="copy-btn px-2 py-1 bg-blue-600 hover:bg-blue-700 text-white text-xs rounded transition-colors duration-200" onclick="copyToClipboard('${command.example}')">
Copy
</button>
</div>
<div class="command-syntax p-3 rounded-lg text-red-400 text-sm font-mono">
${command.syntax}
</div>
</div>
<div class="mb-4">
<label class="text-sm font-medium text-gray-300 mb-2 block">Example</label>
<div class="command-syntax p-3 rounded-lg text-green-400 text-sm font-mono">
${command.example}
</div>
</div>
<div class="mb-4">
<label class="text-sm font-medium text-gray-300 mb-2 block">Description</label>
<p class="text-gray-200 text-sm">${command.description}</p>
</div>
<div class="mb-4">
<label class="text-sm font-medium text-gray-300 mb-2 block">Use Cases</label>
<p class="text-gray-200 text-sm">${command.useCase}</p>
</div>
<div class="flex items-center justify-between">
<div class="flex items-center space-x-2">
<div class="w-2 h-2 bg-red-500 rounded-full"></div>
<span class="text-xs text-gray-400">Redis Command</span>
</div>
<div class="text-xs text-gray-500">
Performance: ${command.performance}
</div>
</div>
`;
return card;
}
function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(() => {
// Show feedback
const btn = event.target;
const originalText = btn.textContent;
btn.textContent = 'Copied!';
btn.classList.add('bg-green-600');
setTimeout(() => {
btn.textContent = originalText;
btn.classList.remove('bg-green-600');
btn.classList.add('bg-blue-600');
}, 1000);
});
}
function getFrequencyColor(frequency) {
switch (frequency) {
case 'Very High':
return 'bg-red-600';
case 'High':
return 'bg-orange-600';
case 'Medium':
return 'bg-yellow-600';
case 'Low':
return 'bg-gray-600';
default:
return 'bg-gray-600';
}
}
// Initialize with all commands
displayCommands();
</script>
</body>
</html>