installers.base.redis #
Redis Installer
A modular Redis installer that works across multiple platforms (Ubuntu, Debian, Alpine, Arch, macOS, containers).
Features
- Cross-platform support (systemd and non-systemd systems)
- Automatic package installation via package managers
- Configurable data directory, port, and IP address
- Smart startup (uses systemctl when available, falls back to direct start)
- No circular dependencies (works without Redis being pre-installed)
Quick Start
Simple Installation
import incubaid.herolib.installers.base.redis
// Create configuration
config := redis.RedisInstall{
port: 6379
datadir: '/var/lib/redis'
ipaddr: 'localhost'
}
// Install and start Redis
redis.redis_install(config)!
// Check if running
if redis.check(config) {
println('Redis is running!')
}
Using Individual Functions
import incubaid.herolib.installers.base.redis
config := redis.RedisInstall{
port: 6379
datadir: '/var/lib/redis'
ipaddr: 'localhost'
}
// Install package only (doesn't start)
redis.redis_install(config)!
// Start Redis
redis.start(config)!
// Stop Redis
redis.stop()!
// Restart Redis
redis.restart(config)!
// Check if running
is_running := redis.check(config)
Configuration Options
pub struct RedisInstall {
pub mut:
name string = 'default' // Instance name
port int = 6379 // Redis port
datadir string = '/var/lib/redis' // Data directory
ipaddr string = 'localhost' // Bind address (space-separated for multiple)
}
Platform Support
| Platform | Package Manager | Startup Method |
|---|---|---|
| Ubuntu/Debian | apt (redis-server) | systemctl |
| Alpine | apk (redis) | direct start |
| Arch | pacman (redis) | systemctl |
| Fedora | dnf (redis) | systemctl |
| macOS | brew (redis) | direct start |
| Containers | varies | direct start |
Using with Factory (Advanced)
For applications that need Redis state management:
import incubaid.herolib.installers.base.redis
// Create and store in factory
mut installer := redis.new(name: 'myredis')!
// Install and start
installer.install(reset: false)!
installer.start()!
// Check status
if installer.running()! {
println('Redis is running')
}
// Stop
installer.stop()!
Example Script
See examples/installers/base/redis.vsh for a complete working example.
Notes
- Default data directory is
/var/lib/redis(standard location) - On systemd systems, uses the package's systemd service
- On non-systemd systems, starts Redis directly with
--daemonize yes - Automatically handles permissions for the Redis user
- Config file location:
/etc/redis/redis.conf(Linux) or${datadir}/redis.conf(macOS)
Constants #
const version = '7.0.0'
fn check #
fn check(args RedisInstall) bool
Check if Redis is running
fn delete #
fn delete(args ArgsGet) !
fn exists #
fn exists(args ArgsGet) !bool
does the config exists?
fn get #
fn get(args ArgsGet) !&RedisInstall
fn heroscript_loads #
fn heroscript_loads(heroscript string) !RedisInstall
///////////NORMALLY NO NEED TO TOUCH
fn list #
fn list(args ArgsList) ![]&RedisInstall
if fromdb set: load from filesystem, and not from mem, will also reset what is in mem
fn new #
fn new(args ArgsGet) !&RedisInstall
fn play #
fn play(mut plbook PlayBook) !
fn redis_install #
fn redis_install(args RedisInstall) !
Install and start Redis with the given configuration This is the main entry point for installing Redis without using the factory
fn restart #
fn restart(args RedisInstall) !
Restart Redis
fn set #
fn set(o RedisInstall) !
register the config for the future
fn start #
fn start(args RedisInstall) !
Start Redis with the given configuration Writes config file, kills any existing processes, and starts Redis
fn stop #
fn stop() !
Stop Redis
fn switch #
fn switch(name string)
switch instance to be used for redis
struct ArgsGet #
struct ArgsGet {
pub mut:
name string = 'default'
fromdb bool // will load from filesystem
create bool // default will not create if not exist
}
///////FACTORY
struct ArgsList #
struct ArgsList {
pub mut:
fromdb bool // will load from filesystem
}
struct InstallArgs #
struct InstallArgs {
pub mut:
reset bool
}
struct RedisInstall #
struct RedisInstall {
pub mut:
name string = 'default'
port int = 6379
datadir string = '/var/lib/redis'
ipaddr string = 'localhost' // can be more than 1, space separated
}
THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
fn (RedisInstall) destroy #
fn (mut self RedisInstall) destroy() !
fn (RedisInstall) install #
fn (mut self RedisInstall) install(args InstallArgs) !
fn (RedisInstall) install_start #
fn (mut self RedisInstall) install_start(args InstallArgs) !
fn (RedisInstall) reload #
fn (mut self RedisInstall) reload() !
load from disk and make sure is properly intialized
fn (RedisInstall) restart #
fn (mut self RedisInstall) restart() !
fn (RedisInstall) running #
fn (mut self RedisInstall) running() !bool
fn (RedisInstall) start #
fn (mut self RedisInstall) start() !
fn (RedisInstall) stop #
fn (mut self RedisInstall) stop() !