Package

com.avsystem.commons

redis

Permalink

package redis

Visibility
  1. Public
  2. All

Type Members

  1. abstract class AbstractRedisApi[Self[K0, H0, V0] <: AbstractRedisApi[Self, K0, H0, V0], K, H, V] extends ApiSubset

    Permalink
  2. abstract class AbstractRedisCommand[A] extends RedisCommand[A]

    Permalink
  3. trait ApiSubset extends AnyRef

    Permalink
  4. case class ClusterState(mapping: IndexedSeq[(SlotRange, RedisNodeClient)], masters: commons.BMap[NodeAddress, RedisNodeClient], nonClustered: commons.Opt[RedisNodeClient] = Opt.Empty) extends Product with Serializable

    Permalink

    Current cluster state known by RedisClusterClient.

    Current cluster state known by RedisClusterClient.

    mapping

    mapping between slot ranges and node clients that serve them, sorted by slot ranges

    masters

    direct mapping between master addresses and node clients

    nonClustered

    non-empty if there's actually only one, non-clustered Redis node - see fallbackToSingleNode

  5. final class CollectionBatch[A, C] extends RedisBatch[C] with RawCommandPacks

    Permalink
  6. final class CommandEncoder extends AnyVal

    Permalink
  7. trait ConnectionCommand extends RawCommand

    Permalink
  8. trait FlatMapper[A, B, -L, -R] extends AnyRef

    Permalink

    Typeclass that steers flat-mapping of RedisBatches and RedisOps with each other.

    Typeclass that steers flat-mapping of RedisBatches and RedisOps with each other. It could be defined simpler as:

    trait FlatMapper[-L[_],-R[_]] {
      def flatMap[A,B](left: L[A])(rightFun: A => R[B]): RedisOp[B]
    }

    but unfortunately IntelliJ Scala plugin (3.0.7.31) does not understand that well (in flatMap callsites)

  9. trait HasFlatMap[L[_]] extends AnyRef

    Permalink
  10. trait ImmediateBatch[+A] extends RedisBatch[A] with RawCommandPacks

    Permalink
  11. trait LowPriorityRedisDataCodecs extends AnyRef

    Permalink
  12. final case class NodeAddress(ip: String = NodeAddress.DefaultIP, port: Int = NodeAddress.DefaultPort) extends Product with Serializable

    Permalink
  13. trait NodeCommand extends RawCommand

    Permalink
  14. trait OperationCommand extends RawCommand

    Permalink
  15. trait RawCommand extends RawCommandPack with RawCommands with ReplyPreprocessor

    Permalink
  16. trait RawCommandPack extends RawCommandPacks

    Permalink

    Represents a sequence of commands that is always executed atomically, using a single network call on a single Redis connection.

  17. trait RawCommandPacks extends AnyRef

    Permalink

    One or more RawCommandPacks.

    One or more RawCommandPacks. Conceptually pretty much the same as Traversable[RawCommandPack]] but more lightweight.

  18. trait RawCommands extends AnyRef

    Permalink

    One or more raw Redis commands.

    One or more raw Redis commands. More lightweight than regular Scala collection (avoids wrapping in case of single element).

  19. trait RecoverableApiSubset extends ApiSubset

    Permalink
  20. case class Redirection(address: NodeAddress, slot: Int, ask: Boolean) extends Product with Serializable

    Permalink
  21. trait RedisAsyncApi extends RedisExecutedApi

    Permalink
  22. trait RedisBatch[+A] extends AnyRef

    Permalink

    Represents a Redis command or a set of commands sent to Redis as a single batch (usually in a single network message).

    Represents a Redis command or a set of commands sent to Redis as a single batch (usually in a single network message). RedisBatch yields a result of type A which is decoded from responses to commands from this batch. Execution of a batch may also fail for various reasons. Therefore, RedisBatch contains API that allows to recover from failures, e.g. RedisBatch.tried.

    RedisBatches may be combined with each other to form bigger batches. The simpliest primitive for combining batches is RedisBatch.map2 operation while the most convenient way is by using RedisBatch.sequence operation which is powered by Sequencer typeclass.

    RedisBatch can be turned into a RedisOp or executed by RedisExecutor (e.g. one of Redis client implementations).

    A

    result yield by this batch

  23. trait RedisBatchApi extends ApiSubset

    Permalink
  24. abstract class RedisBinaryCommand extends AbstractRedisCommand[ByteString]

    Permalink
  25. trait RedisBlockingApi extends RedisExecutedApi

    Permalink
  26. abstract class RedisBooleanCommand extends AbstractRedisCommand[Boolean]

    Permalink
  27. final class RedisClusterClient extends RedisKeyedExecutor with Closeable

    Permalink

    Redis client implementation for Redis Cluster deployments.

    Redis client implementation for Redis Cluster deployments. Internally, it uses single RedisNodeClient instance for every known master in the cluster plus a separate connection for monitoring of every known master. RedisNodeClient instances are dynamically created and destroyed as the cluster changes its state.

    The cluster client is only able to execute commands or transactions containing keys which determine which master should be contacted. However, it's possible to gain access to RedisNodeClient instances that RedisClusterClient internally uses to connect to every master (see ClusterState and masterClient).

    RedisClusterClient can directly execute only RedisBatches. It automatically distributes every batch over multiple cluster masters and handles cluster redirections if necessary. See executeBatch for more details.

    RedisClusterClient cannot directly execute RedisOps (e.g. WATCH-MULTI-EXEC transactions). You must manually access node client for appropriate master through currentState and execute the operation using it. However, be aware that you must manually handle cluster redirections and cluster state changes while doing so.

  28. trait RedisCommand[+A] extends SinglePackBatch[A] with RawCommand

    Permalink
  29. trait RedisConnectionApi extends RedisOperationApi with ConnectionClusterApi with ConnectionConnectionApi with ConnectionServerApi with ConnectionScriptingApi with BlockingListsApi

    Permalink
  30. final class RedisConnectionClient extends RedisConnectionExecutor with Closeable

    Permalink

    Redis client that uses a single, non-reconnectable connection.

    Redis client that uses a single, non-reconnectable connection. This is the most "raw" client implementation and the only one capable of directly executing connection state changing commands like AUTH, CLIENT SETNAME, WATCH, etc.

    However, note that connection-setup commands like AUTH may also be specified in ConnectionConfig (which may also be specified for connections used by RedisNodeClient and RedisClusterClient).

    This type of client should only be used when requiring capability of manual handling of connection state. If you simply need a single-connection, reconnectable client, use RedisNodeClient with connection pool size configured to 1.

  31. trait RedisConnectionExecutor extends RedisNodeExecutor

    Permalink

    Marker subtype of RedisExecutor which guarantees ability to execute all commands implemented by the driver, including the ones that change or access connection state.

  32. case class RedisDataCodec[T](read: (ByteString) ⇒ T, write: (T) ⇒ ByteString) extends Product with Serializable

    Permalink

    Typeclass which expresses that values of some type are serializable to binary form (ByteString) and deserializable from it in order to use them as keys, hash keys and values in Redis commands.

    Typeclass which expresses that values of some type are serializable to binary form (ByteString) and deserializable from it in order to use them as keys, hash keys and values in Redis commands.

    By default, RedisDataCodec is provided for simple types like String, ByteString, Array[Byte], Boolean, Char, all primitive numeric types and NamedEnums (which have NamedEnumCompanion).

    Also, all types which have an instance of GenCodec automatically have an instance of RedisDataCodec.

  33. abstract class RedisDataCommand[A] extends AbstractRedisCommand[A]

    Permalink
  34. abstract class RedisDataSeqCommand[A] extends AbstractRedisCommand[Seq[A]]

    Permalink
  35. abstract class RedisDataSetCommand[A] extends AbstractRedisCommand[commons.BSet[A]]

    Permalink
  36. abstract class RedisDoubleCommand extends AbstractRedisCommand[Double]

    Permalink
  37. abstract class RedisEnumCommand[E <: NamedEnum] extends AbstractRedisCommand[E]

    Permalink
  38. trait RedisExecutedApi extends RecoverableApiSubset

    Permalink
  39. trait RedisExecutor extends AnyRef

    Permalink

    Base trait for Redis clients with ability to execute RedisBatches.

  40. abstract class RedisIntCommand extends AbstractRedisCommand[Int]

    Permalink
  41. trait RedisKeyedApi extends KeyedKeysApi with StringsApi with KeyedClusterApi with GeoApi with KeyedScriptingApi with HashesApi with SortedSetsApi with ListsApi with SetsApi with HyperLogLogApi

    Permalink
  42. trait RedisKeyedExecutor extends RedisExecutor

    Permalink

    Marker subtype of RedisExecutor which guarantees ability to execute Redis commands which contain keys.

  43. abstract class RedisLongCommand extends AbstractRedisCommand[Long]

    Permalink
  44. trait RedisNodeApi extends RedisKeyedApi with NodeKeysApi with NodeServerApi with NodeClusterApi with NodeConnectionApi with NodeScriptingApi

    Permalink
  45. final class RedisNodeClient extends RedisNodeExecutor with Closeable

    Permalink

    Redis client implementation for a single Redis node using a connection pool.

    Redis client implementation for a single Redis node using a connection pool. Connection pool size is constant and batches and operations are distributed over connections using round-robin scheme. Connections are automatically reconnected upon failure (possibly with an appropriate delay, see NodeConfig for details).

  46. trait RedisNodeExecutor extends RedisKeyedExecutor with RedisOpExecutor

    Permalink

    Marker subtype of RedisExecutor which guarantees ability to execute commands which do NOT access or change state of a single Redis connection (e.g.

    Marker subtype of RedisExecutor which guarantees ability to execute commands which do NOT access or change state of a single Redis connection (e.g. CLIENT SETNAME).

  47. abstract class RedisNothingCommand extends AbstractRedisCommand[Nothing]

    Permalink
  48. sealed trait RedisOp[+A] extends AnyRef

    Permalink

    Represents a sequence of Redis operations executed using a single Redis connection.

    Represents a sequence of Redis operations executed using a single Redis connection. Any operation may depend on the result of some previous operation (therefore, flatMap is available). RedisOp is guaranteed to be executed fully and exclusively on a single Redis connection (no other concurrent commands can be executed on that connection during execution of RedisOp). Because of that, RedisOps may execute WATCH and UNWATCH commands.

    In fact, the primary purpose of RedisOp is to allow execution of Redis transactions with optimistic locking. For this purpose, RedisOp may be created by flat-mapping RedisBatches.

    For example, below is an implementation of Redis transaction which fetches a value of some key (as Int) multiplies it by 3 and saves it back to Redis. During this operation, the key being modified is watched so that saving fails with OptimisticLockException if some other client concurrently modifies that key.

    val api = RedisApi.Batches.StringTyped.valueType[Int]
    import api._
    val transactionOp: RedisOp[Unit] = for {
      // we're sending WATCH and GET commands in a single batch
      value <- watch("number") *> get("number").map(_.getOrElse(1))
      // SET command is wrapped in MULTI-EXEC block
      _ <- set("number", value * 3).transaction
    } yield ()

    RedisOp can be passed for execution to RedisOpExecutor (implemented by e.g. RedisNodeClient).

  49. trait RedisOpExecutor extends AnyRef

    Permalink

    Base trait for Redis clients with ability to execute RedisOps.

  50. trait RedisOperationApi extends RedisNodeApi with TransactionApi

    Permalink
  51. abstract class RedisOptCommand[T] extends AbstractRedisCommand[commons.Opt[T]]

    Permalink
  52. abstract class RedisOptDataCommand[A] extends AbstractRedisCommand[commons.Opt[A]]

    Permalink
  53. abstract class RedisOptDataSeqCommand[A] extends AbstractRedisCommand[Seq[commons.Opt[A]]]

    Permalink
  54. abstract class RedisOptDoubleCommand extends AbstractRedisCommand[commons.Opt[Double]]

    Permalink
  55. abstract class RedisOptLongCommand extends AbstractRedisCommand[commons.Opt[Long]]

    Permalink
  56. abstract class RedisOptSeqCommand[T] extends AbstractRedisCommand[commons.Opt[Seq[T]]]

    Permalink
  57. abstract class RedisOptStringCommand extends AbstractRedisCommand[commons.Opt[String]]

    Permalink
  58. abstract class RedisPositiveLongCommand extends AbstractRedisCommand[commons.Opt[Long]]

    Permalink
  59. trait RedisRawApi extends ApiSubset

    Permalink
  60. abstract class RedisRawCommand extends AbstractRedisCommand[ValidRedisMsg]

    Permalink
  61. trait RedisRecoverableConnectionApi extends RedisRecoverableNodeApi with RedisConnectionApi

    Permalink
  62. trait RedisRecoverableKeyedApi extends RedisKeyedApi with RecoverableKeyedScriptingApi

    Permalink
  63. trait RedisRecoverableNodeApi extends RedisRecoverableKeyedApi with RedisNodeApi

    Permalink
  64. abstract class RedisScanCommand[T] extends AbstractRedisCommand[(Cursor, Seq[T])]

    Permalink
  65. abstract class RedisSeqCommand[T] extends AbstractRedisCommand[Seq[T]]

    Permalink
  66. abstract class RedisSimpleStringCommand extends AbstractRedisCommand[String]

    Permalink
  67. abstract class RedisUnitCommand extends AbstractRedisCommand[Unit]

    Permalink
  68. trait ReplyPreprocessor extends AnyRef

    Permalink

    Something that translates incoming RedisMsg messages and emits a single RedisReply.

    Something that translates incoming RedisMsg messages and emits a single RedisReply. For example, it may handle transactions by extracting actual responses for every command from the EXEC response and returning them in a TransactionReply (see Transaction).

  69. trait Sequencer[Ops, Res] extends AnyRef

    Permalink

    Typeclass for easy merging ("sequencing") of multiple RedisBatch instances into one.

    Typeclass for easy merging ("sequencing") of multiple RedisBatch instances into one. This is done in order to guarantee that some set of operations is sent to Redis as a single batch (most likely single network message).

    The parameter Ops represents batches that will be sequenced into one. It may be a collection, a tuple or any other "collection-like" type for which type class instance is provided.

    Res is the type of result of the batch created by "sequencing". This type is automatically inferred from the Ops type. For example, if Ops is (RedisBatch[Int], RedisBatch[String]) (tuple) then Res will be (Int, String). If Ops is List[RedisBatch[Int]] then Res will be List[Int].

    Nesting is also possible. For example, if Ops is (List[RedisBatch[Int]], RedisBatch[String]) then Res will be (List[Int], String).

    In order to perform "sequencing", simply call sequence on your collection of batches, e.g.

    import RedisApi.Batches.StringTyped._
    
    val tupleBatch: RedisBatch[(Long, Opt[String])] = (incr("key1"), get("key2")).sequence
    val listBatch: RedisBatch[List[Long]] = List("key1", "key2").map(key => incr(key)).sequence
    Annotations
    @implicitNotFound( ... )
  70. trait SinglePackBatch[+A] extends RedisBatch[A] with RawCommandPack

    Permalink
  71. final class Transaction[+A] extends SinglePackBatch[A]

    Permalink
  72. trait TupleSequencers extends AnyRef

    Permalink
  73. trait UnsafeCommand extends RawCommand

    Permalink
  74. trait WatchState extends AnyRef

    Permalink

Value Members

  1. object ApiSubset

    Permalink
  2. object ClusterState extends Serializable

    Permalink
  3. object CommandEncoder

    Permalink
  4. object FlatMapper

    Permalink
  5. object Gen

    Permalink
  6. object HasFlatMap

    Permalink
  7. object Hash

    Permalink

    Implementation of key hashing function used in Redis Cluster, as specified in Redis Cluster Specification

  8. object NodeAddress extends Serializable

    Permalink
  9. object RawCommand

    Permalink
  10. object RedirectionError

    Permalink
  11. object RedirectionException

    Permalink
  12. object RedirectionReply

    Permalink
  13. object RedisApi

    Permalink

    Object which contains implementations of various variants of Redis API that this driver provides.

    Object which contains implementations of various variants of Redis API that this driver provides. Each variant implements a set of methods corresponding directly to Redis commands, e.g. get method represents Redis GET command.

    API variants may differ from each other in several independent aspects:

    The most important one is the result type returned by every method corresponding to a Redis command:

    Async and Blocking API variants additionally come in three different "levels", each one exposing different subset of Redis commands. This reflects the fact that not every RedisExecutor (client implementation) supports every command (e.g. you can't execute unkeyed commands using RedisClusterClient).

    • Variants from RedisApi.Keyed include only commands with keys (so that they can be executed on Redis Cluster)
    • Variants from RedisApi.Node include only commands which don't access connection state
    • Variants from RedisApi.Connection include all commands supported by the driver

    Every API variant may also use different types to represent Redis keys, hash keys and values. You can define your own API variants for arbitrary combination of key, hash key and value types as long as there is an instance of RedisDataCodec for every of these types.

    For example, if you keep only numeric values on a Redis Cluster installation, you might define an API variant like this one:

    class NumericKeyedAsyncApi(executor: RedisKeyedExecutor, config: ExecutionConfig = ExecutionConfig.Default)
      extends RedisApi.Keyed.Async[String,String,Long](executor, config)

    API variants which use only Strings (textual) or only ByteStrings (binary) are already implemented by the driver, e.g. RedisApi.Keyed.Async.StringTyped, RedisApi.Batches.BinaryTyped.

    Note that RedisDataCodec is automatically provided for many simple types and also all types which have a GenCodec. This effectively gives you a complete serialization framework for keys, hash keys and values stored in Redis.

    Note that chosen key, hash key and value types can be adjusted "on the fly" with a convenient syntax. For example, if you need to use some case class as a value type in a single, specific place, you can do it without defining a completely separate API variant. For example:

    case class Person(name: String, birthYear: Int)
    object Person {
      implicit val codec: GenCodec[Person] = GenCodec.materialize[Person]
    }
    
    import scala.concurrent.duration._
    implicit val system: ActorSystem = ActorSystem()
    
    val api = RedisApi.Keyed.Blocking.StringTyped(new RedisClusterClient)
    
    // normally, we're just using String-typed API
    api.set("key", "value")
    
    // but in one specific place, we might want to use Person as the value
    // Person has an instance of GenCodec, so it will be automatically serialized to binary format
    api.valueType[Person].set("binaryDataKey", Person("Fred", 1990))
  14. object RedisBatch extends HasFlatMap[RedisBatch]

    Permalink
  15. object RedisDataCodec extends LowPriorityRedisDataCodecs with Serializable

    Permalink
  16. object RedisOp extends HasFlatMap[RedisOp]

    Permalink
  17. object Sequencer extends TupleSequencers

    Permalink
  18. object TupleSequencers

    Permalink
  19. package actor

    Permalink
  20. package commands

    Permalink
  21. package config

    Permalink
  22. package exception

    Permalink
  23. package protocol

    Permalink
  24. package util

    Permalink

Ungrouped