Last active
August 23, 2022 10:43
-
-
Save BuonOmo/a41091db874201275f32f61cf7878909 to your computer and use it in GitHub Desktop.
Filter REDIS commands by ACL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>REDIS Commands By ACL Category</title> | |
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css"> | |
<style> | |
body { | |
grid-template-columns: 1fr min(70rem,90%) 1fr; | |
} | |
.picked { | |
filter: brightness(1.4); | |
} | |
.flex { | |
display: flex; | |
flex-wrap: wrap; | |
justify-content: space-evenly; | |
} | |
.grid { | |
display: grid; | |
grid-template-columns: repeat(auto-fit,minmax(17rem,1fr)); | |
} | |
article { | |
position: relative; | |
width: 17rem; | |
font-size: 1rem; | |
} | |
article:hover { | |
background: var(--accent); | |
color: var(--bg); | |
} | |
article > h1 { | |
font-size: inherit; | |
font-weight: 500; | |
margin: 0; | |
margin-bottom: 0.375rem; | |
} | |
article > p { | |
font-size: inherit; | |
opacity: 0.7; | |
margin: 0; | |
} | |
article > a { | |
position: absolute; | |
outline-width: 0; | |
top: 0; | |
right: 0; | |
bottom: 0; | |
left: 0; | |
} | |
</style> | |
</head> | |
<body> | |
<script type="importmap"> | |
{ | |
"imports": { | |
"vue": "https://unpkg.com/vue@3/dist/vue.esm-browser.js" | |
} | |
} | |
</script> | |
<div id="app" style="display: none"> | |
<div class="flex"> | |
<button | |
v-for="acl in acls" | |
@click="pick(acl, $event)" | |
:class="{ picked: picked.has(acl) }" | |
>{{ acl }}</button> | |
</div> | |
<div class="grid"> | |
<article v-for="cmd in filteredCommands"> | |
<h1>{{ cmd.name }}</h1> | |
<p>{{ cmd.summary }}</p> | |
<a :href="linkFor(cmd)"></a> | |
</li> | |
</ul> | |
</div> | |
<script type="module"> | |
import { createApp } from 'vue' | |
const includesAll = (HaystackSet, needleSet) => { | |
for (let elem of HaystackSet) { | |
if (!needleSet.has(elem)) { | |
return false | |
} | |
} | |
return true | |
} | |
const main = async function() { | |
let commandsJson | |
try { | |
const resp = await fetch("https://raw.githubusercontent.com/redis/redis-doc/master/commands.json") | |
commandsJson = await resp.json() | |
} catch (error) { | |
app.innerHTML = "Sorry, something went wrong while getting access to redis-doc." | |
return | |
} | |
app.style = '' | |
createApp({ | |
data() { | |
return { | |
commands: Object. | |
entries(commandsJson). | |
map(([name, cmd]) => ({ name, summary: cmd.summary, acls: new Set(cmd.acl_categories) })), | |
picked: new Set() | |
} | |
}, | |
methods: { | |
pick(acl, event) { | |
if (this.picked.has(acl)) | |
this.picked.delete(acl) | |
else | |
this.picked.add(acl) | |
event.target.blur() | |
}, | |
linkFor(cmd) { | |
return `https://redis.io/commands/${cmd.name.replace(" ", "-").toLowerCase()}/` | |
} | |
}, | |
computed: { | |
acls() { | |
return Array.from(new Set(this.commands.flatMap(cmd => Array.from(cmd.acls)))).sort() | |
}, | |
filteredCommands() { | |
return this.commands. | |
filter(cmd => this.picked.size === 0 || includesAll(this.picked, cmd.acls)) | |
} | |
} | |
}).mount('#app') | |
} | |
main() | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gitcdn.xyz/cdn/BuonOmo/a41091db874201275f32f61cf7878909/raw/d725f599018d8b157f71123adde3e25d2fd41cbe/redis-command-by-acl.html