Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Redis renderer #934

Closed
kaihendry started this conversation in Ideas
Feb 5, 2025 · 2 comments · 3 replies
Discussion options

I'm curious if anyone has written a Redis renderer, since I have configuration not unlike https://docs.konghq.com/hub/kong-inc/rate-limiting/configuration/ and currently Redis keys are maintained manually by operations and can cause operational issues.

You must be logged in to vote

Replies: 2 comments 3 replies

Comment options

This is an interesting problem space! Pkl can only produce textual output, but there are a couple it may be able to help:

  • Shell command generation - a simple technique here might be to have Pkl produce a shell script that runs redis-cli commands. A custom renderer of this kind is easy to build in-language. You would run it like pkl eval <module> | bash.
  • Language binding library - using the Java/Kotlin library, pkl-swift, or pkl-go write a program where the Pkl module is evaluated into types in the target language. The program would use this result and a Redis client library to write the values.
You must be logged in to vote
2 replies
Comment options

Do you have an example of how to produce said shell script please?

Comment options

Sure, it's fairly straightforward. Using your pkl-redis repo as the basis:

module Control
hidden baseCommand: String = "redis-cli" // could be "docker exec redis redis-cli"
hidden dbNum: UInt = 0
rl: Controller;
cb: Controller;
class Controller {
 toggle: Running = "OFF";
}
typealias Running = "ON"|"OFF"|"SHADOW"
/// Flatten an object structure down to "key:path"="value" pairs
function walkKV(val: Map|Mapping|Dynamic|Typed): Mapping<String, Any> = new {
 for (k, v in val.toMap()) {
 when (v is Map|Mapping|Dynamic|Typed) {
 for (k2, v2 in walkKV(v)) {
 ["\(k):\(k2)"] = v2
 }
 } else {
 // not clear how List|Listing should be handled here, pretend they don't exist
 [k] = v
 }
 }
}
output {
 text = new Listing {
 "#!/bin/bash"
 for (k, v in walkKV(module)) {
 "\(baseCommand) -n \(dbNum) SET \(k) '\(v)'"
 }
 }.join("\n")
}

Then to run it

pkl eval config.pkl | bash
Comment options

Did I get the idea of the "Language binding library" over at https://github.com/kaihendry/pkl-redis ?

You must be logged in to vote
1 reply
Comment options

In general, yeah! My original thought was to directly use go-redis or similar for tighter integration instead of printing out the shell commands to run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /