Skip to main content

Server API

Purely functional interface for the Server API.

Usage

import cats.effect.*
import dev.profunktor.valkey4cats.Valkey
import dev.profunktor.valkey4cats.effect.Log
import dev.profunktor.valkey4cats.model.ValkeyResponse.{Ok, Err}
import dev.profunktor.valkey4cats.arguments.{FlushMode, InfoSection}

given Log[IO] = Log.Stdout.instance[IO]

Valkey[IO].utf8("valkey://localhost:6379").use { valkey =>
for
// INFO - get server information
info <- valkey.info
_ <- info match
case Ok(infoStr) => IO.println(s"Server info length: ${infoStr.length}")
case Err(e) => IO.println(s"Error: ${e.message}")

// INFO with specific sections
memInfo <- valkey.info(Set(InfoSection.Memory))
_ <- IO.println(s"Memory info: ${memInfo.toOption.map(_.take(100))}")

// TIME - server time
time <- valkey.time
_ <- IO.println(s"Server time: ${time.toOption.map(_.unixSeconds)}s")

// DBSIZE
dbSize <- valkey.dbSize
_ <- IO.println(s"DB size: ${dbSize.toOption} keys")

// CONFIG GET / SET
config <- valkey.configGet(Set("maxmemory", "timeout"))
_ <- IO.println(s"Config: ${config.toOption}")
_ <- valkey.configSet(Map("timeout" -> "300"))

// LOLWUT
art <- valkey.lolwut
_ <- IO.println(s"LOLWUT: ${art.toOption.map(_.take(50))}...")
yield ()
}

Available commands

CommandMethodReturn type
INFOinfoF[ValkeyResponse[String]]
INFO (sections)info(sections)F[ValkeyResponse[String]]
CONFIG REWRITEconfigRewriteF[ValkeyResponse[Unit]]
CONFIG RESETSTATconfigResetStatF[ValkeyResponse[Unit]]
CONFIG GETconfigGet(parameters)F[ValkeyResponse[Map[String, String]]]
CONFIG SETconfigSet(parameters)F[ValkeyResponse[Unit]]
TIMEtimeF[ValkeyResponse[ServerTime]]
LASTSAVElastSaveF[ValkeyResponse[Long]]
FLUSHALLflushAllF[ValkeyResponse[Unit]]
FLUSHALL (mode)flushAll(mode)F[ValkeyResponse[Unit]]
FLUSHDBflushDBF[ValkeyResponse[Unit]]
FLUSHDB (mode)flushDB(mode)F[ValkeyResponse[Unit]]
LOLWUTlolwutF[ValkeyResponse[String]]
DBSIZEdbSizeF[ValkeyResponse[Long]]