In-process server mode
Right now, it seems there are two options:
- In-process mode, which requires using methods on
redka.DB. - Standalone mode, which lets you use a standard Redis client.
For an application I'm working on, I'd like to use Redka so there's a built-in Redis available that people can potentially swap out for their own Redis deployment. However, to not make that super complicated code-wise I'd want the in-process one to also start a server. Unfortunately the server package lives in internal and there doesn't seem to be any other way for me to access it.
Could a Server become an exporter thing others can also use?
Do you want to run your own application as a Redka server?
Something like this in your main.go:
func main() {
db, err := redka.Open("file:/data.db?vfs=memdb", nil)
// ...
srv := redka.NewServer("tcp", "6379", db)
srv.Start()
// ...
}
It's more that I want a Redka server to be running as part of my application.
I want to use Redis for some basic queueing and other things. For small deployments, a separate Redis instance isn't necessary so I'd like to avoid people having to deploy one. As a consequence, I want to start up a Redka server as part of my application:
func main() {
db, err := redka.Open("file:/data.db?vfs=memdb", nil)
srv := redka.NewServer("tcp", "6379", db)
go func() {
srv.Start()
}()
// use regular redis-go to access Redka
}
Sorry, I don't follow. In this case, how will people be able to swap Redka for Redis if starting the Redka server is hardcoded into your application?
The idea would be to have this configuration based. If someone defines something like redis: internal in the configuration file, the application will spawn its own Redka server, tied to the lifetime of the application. If they specify something like redis: ip:port it'll refrain from doing so and instead directly connect to that instance.
I see, thanks. So in any case, you're just going to work through redis-go as if it were a Redis instance. Clever!
I wasn't planning on exporting the server, but your scenario is legitimate. I'll think about it.
Would you mind sharing a link to your application? It's an interesting use case.
I'm afraid I don't have anything to share just yet. I was prototyping this yesterday and ran into it. I raised the issue to see if you'd be open to exposing it publicly, or if I'd have to wrap it up myself.
But I might have something to show next week!
This is like how nats server can also do in process using configuration.
here is an example: https://github.com/upspeak/upspeak/blob/main/app/nats.go#L43C23-L43C33
It might be useful as inspiration.
Implemented in v0.6.0, see the server example.