Skip to main content

Connection API

Purely functional interface for the Connection API.

Usage

import cats.effect.*
import dev.profunktor.valkey4cats.Valkey
import dev.profunktor.valkey4cats.effect.Log

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

Valkey[IO].utf8("valkey://localhost:6379").use { valkey =>
for
// PING
pong <- valkey.ping
_ <- IO.println(s"PING: ${pong.toOption}") // Some("PONG")

// PING with message
echo <- valkey.ping("hello")
_ <- IO.println(s"PING hello: ${echo.toOption}") // Some("hello")

// ECHO
echoed <- valkey.echo("test message")
_ <- IO.println(s"ECHO: ${echoed.toOption}")

// CLIENT ID
clientId <- valkey.clientId
_ <- IO.println(s"Client ID: ${clientId.toOption}")

// SELECT (switch database)
_ <- valkey.select(1)
_ <- valkey.select(0)
yield ()
}

Available commands

CommandMethodReturn type
PINGpingF[ValkeyResponse[String]]
PING (msg)ping(message)F[ValkeyResponse[V]]
ECHOecho(message)F[ValkeyResponse[V]]
CLIENT IDclientIdF[ValkeyResponse[Long]]
CLIENT GETNAMEclientGetNameF[ValkeyResponse[Option[String]]]
SELECTselect(index)F[ValkeyResponse[Unit]]