debasishg / scala-redis

A scala library for connecting to a redis server, or a cluster of redis nodes using consistent hashing on the client side.
1.02k stars 219 forks source link

Unusable SET implementation #198

Open salokanto opened 7 years ago

salokanto commented 7 years ago

SET arguments, as per Redis documentation, are:

SET key value [EX seconds] [PX milliseconds] [NX|XX]

This means that NX or XX is optional, but current the implementation forces you to pick either:

  def set(key: Any, value: Any, onlyIfExists: Boolean, time: SecondsOrMillis): Boolean = {
    val nxxx = if (onlyIfExists) "XX" else "NX"
    val expx = time match {
      case Seconds(v) => List("EX", v)
      case Millis(v) => List("PX", v)
    }
    send("SET", List(key, value, nxxx) ++ expx)(asBoolean)
  }

Users typically want the default behavior (overwrite if exists), which is neither NX nor XX.

And while at it, it would be nicer to use scala.concurrent.duration.Duration instead of the custom-made one (SecondsOrMillis).