Skip to content

Configuration file templating

ᴀɴᴛᴏɴ ɴᴏᴠᴏᴊɪʟᴏᴠ edited this page Jan 26, 2024 · 9 revisions

Variables

  • {{.ID}} ɪɴᴛ — Instance ID
  • {{.Port}} ɪɴᴛ — Instance port
  • {{.MetaFile}} sᴛʀɪɴɢ — Path to meta file
  • {{.ConfigFile}} sᴛʀɪɴɢ — Path to configuration file
  • {{.PidFile}} sᴛʀɪɴɢ — Path to PID file
  • {{.LogDir}} sᴛʀɪɴɢ — Path to directory with logs
  • {{.LogFile}} sᴛʀɪɴɢ — Path to log file
  • {{.DataDir}} sᴛʀɪɴɢ — Path to directory with data
  • {{.IsSaveDisabled}} ʙᴏᴏʟ — Disabled saves flag
  • {{.IsReplica}} ʙᴏᴏʟ — Replica instance flag
  • {{.IsSecure}} ʙᴏᴏʟ — Secure instance flag
  • {{.MasterHost}} sᴛʀɪɴɢ — Redis master host
  • {{.MasterPort}} ɪɴᴛ — Redis master port
  • {{.AdminPasswordHash}} sᴛʀɪɴɢ — Password hash for admin user (used for RDS)
  • {{.SyncPasswordHash}} sᴛʀɪɴɢ — Password hash for sync user (used for syncing with replica)
  • {{.SentinelPasswordHash}} sᴛʀɪɴɢ — Password hash for sentinel user (used for syncing by Sentinel)
  • {{.ServicePasswordHash}} sᴛʀɪɴɢ — Password hash for default user for secure instances
  • {{.Redis.String}} sᴛʀɪɴɢ — Redis version
  • {{.Redis.Major}} ɪɴᴛ — Redis major version
  • {{.Redis.Minor}} ɪɴᴛ — Redis minor version
  • {{.Redis.Patch}} ɪɴᴛ — Redis patch
  • {{.RDS.HasReplication}} ʙᴏᴏʟ — RDS replication flag
  • {{.RDS.IsMaster}} ʙᴏᴏʟ — RDS node master flag
  • {{.RDS.IsMinion}} ʙᴏᴏʟ — RDS node minion flag
  • {{.RDS.IsSentinel}} ʙᴏᴏʟ — RDS node sentinel flag
  • {{.RDS.IsFailoverStandby}} ʙᴏᴏʟ — RDS failover method standby flag
  • {{.RDS.IsFailoverSentinel}} ʙᴏᴏʟ — RDS failover method sentinel flag

Functions

  • {{.RedisVersionLess "A.B.C"}} ʙᴏᴏʟ — Redis version is less than given version
  • {{.RedisVersionGreater "A.B.C"}} ʙᴏᴏʟ — Redis version is greater than given version
  • {{.RedisVersionEquals "A.B.C"}} ʙᴏᴏʟ — Redis version is equal to given version
  • {{.HasTag "TAG"}} ʙᴏᴏʟ — Tag check
  • {{.Storage "key"}} sᴛʀɪɴɢ — Value from instance custom data storage

Examples

User custom save preferences for instances with tag test:

{{if .IsSaveDisabled}}
save ""
{{else}}
{{.HasTag "test"}}
save 3600 1
{{else}}
save 900 1 300 10 60 10000
{{end}}
{{end}}

Disable saves on master node if standby failover mode is used:

{{if or .IsSaveDisabled}}
save ""
{{else}}
{{if and .RDS.IsFailoverStandby .RDS.IsMaster}}
save ""
{{else}}
save 900 1 300 10 60 10000
{{end}}
{{end}}

Allow to use KEYS command on instances with tag allow-keys:

{{if .IsSecure}}
user default on ~* &* +@all -@admin -@dangerous +INFO +CLIENT #{{.ServicePasswordHash}}
{{else}}
{{if .HasTag "allow-keys"}}
user default on nopass ~* &* +@all -@admin -@dangerous +INFO +CLIENT +KEYS
{{else}}
user default on nopass ~* &* +@all -@admin -@dangerous +INFO +CLIENT
{{end}}
{{end}}

More info about templating syntax can be found here.

Clone this wiki locally