package redis
- Alphabetic
- Public
- All
Type Members
- abstract class AbstractRedisApi[S <: RedisSerialization] extends ApiSubset
- abstract class AbstractRedisCommand[A] extends RedisCommand[A]
- trait ApiSubset extends AnyRef
-
case class
ClusterState(mapping: IndexedSeq[(SlotRange, RedisNodeClient)], masters: commons.BMap[NodeAddress, RedisNodeClient], nonClustered: commons.Opt[RedisNodeClient] = Opt.Empty) extends Product with Serializable
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
- final class CollectionBatch[A, C] extends RedisBatch[C] with RawCommandPacks
- final class CommandEncoder extends AnyVal
- trait ConnectionCommand extends RawCommand
- abstract class ExecutedApis extends AnyRef
-
trait
FlatMapper[A, B, -L, -R] extends AnyRef
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) - trait HasFlatMap[L[_]] extends AnyRef
- trait ImmediateBatch[+A] extends RedisBatch[A] with RawCommandPacks
- trait LowPriorityRedisDataCodecs extends AnyRef
- sealed trait LowPriorityRedisRecordCodecs extends AnyRef
- final case class NodeAddress(ip: String = NodeAddress.DefaultIP, port: Int = NodeAddress.DefaultPort) extends Product with Serializable
- trait NodeCommand extends RawCommand
- trait OperationCommand extends RawCommand
- trait RawCommand extends RawCommandPack with RawCommands with ReplyPreprocessor
-
trait
RawCommandPack extends RawCommandPacks
Represents a sequence of commands that is always executed atomically, using a single network call on a single Redis connection.
Represents a sequence of commands that is always executed atomically, using a single network call on a single Redis connection. RawCommandPack is effectively either a single command or a transaction, optionally preceded by the
ASKING
special command. -
trait
RawCommandPacks extends AnyRef
One or more RawCommandPacks.
One or more RawCommandPacks. Conceptually pretty much the same as
Traversable[RawCommandPack]]
but more lightweight. -
trait
RawCommands extends AnyRef
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).
- trait RecoverableApiSubset extends ApiSubset
- case class Redirection(address: NodeAddress, slot: Int, ask: Boolean) extends Product with Serializable
- trait RedisAsyncApi extends RedisExecutedApi
-
trait
RedisBatch[+A] extends AnyRef
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
- trait RedisBatchApi extends ApiSubset
- abstract class RedisBinaryCommand extends AbstractRedisCommand[ByteString]
- trait RedisBlockingApi extends RedisExecutedApi
- abstract class RedisBooleanCommand extends AbstractRedisCommand[Boolean]
-
final
class
RedisClusterClient extends RedisKeyedExecutor with Closeable
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. - trait RedisCommand[+A] extends SinglePackBatch[A] with RawCommand
- trait RedisConnectionApi extends RedisOperationApi with ConnectionClusterApi with ConnectionConnectionApi with ConnectionServerApi with ConnectionScriptingApi
-
final
class
RedisConnectionClient extends RedisConnectionExecutor with Closeable
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.
-
trait
RedisConnectionExecutor extends RedisNodeExecutor
Marker subtype of RedisExecutor which guarantees ability to execute all commands implemented by the driver, including the ones that change or access connection state.
-
case class
RedisDataCodec[T](read: (ByteString) ⇒ T, write: (T) ⇒ ByteString) extends Product with Serializable
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 likeString
,ByteString
,Array[Byte]
,Boolean
,Char
, all primitive numeric types andNamedEnum
s (which haveNamedEnumCompanion
).Also, all types which have an instance of
GenCodec
automatically have an instance of RedisDataCodec. - abstract class RedisDataCommand[A] extends AbstractRedisCommand[A]
- class RedisDataInput extends InputAndSimpleInput
- final class RedisDataOutput extends OutputAndSimpleOutput
- abstract class RedisDataSeqCommand[A] extends AbstractRedisCommand[Seq[A]]
- abstract class RedisDataSetCommand[A] extends AbstractRedisCommand[commons.BSet[A]]
- abstract class RedisDoubleCommand extends AbstractRedisCommand[Double]
- abstract class RedisEnumCommand[E <: NamedEnum] extends AbstractRedisCommand[E]
- trait RedisExecutedApi extends RecoverableApiSubset
-
trait
RedisExecutor extends AnyRef
Base trait for Redis clients with ability to execute RedisBatches.
- class RedisFieldDataInput extends RedisDataInput with FieldInput
- abstract class RedisIntCommand extends AbstractRedisCommand[Int]
- trait RedisKeyedApi extends KeyedKeysApi with StringsApi with KeyedClusterApi with GeoApi with KeyedScriptingApi with HashesApi with SortedSetsApi with ListsApi with SetsApi with HyperLogLogApi with StreamsApi
-
trait
RedisKeyedExecutor extends RedisExecutor
Marker subtype of RedisExecutor which guarantees ability to execute Redis commands which contain keys.
- abstract class RedisLongCommand extends AbstractRedisCommand[Long]
- trait RedisNodeApi extends RedisKeyedApi with NodeKeysApi with NodeServerApi with NodeClusterApi with NodeConnectionApi with NodeScriptingApi
-
final
class
RedisNodeClient extends RedisNodeExecutor with Closeable
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).
-
trait
RedisNodeExecutor extends RedisKeyedExecutor with RedisOpExecutor
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
). - abstract class RedisNothingCommand extends AbstractRedisCommand[Nothing]
-
sealed
trait
RedisOp[+A] extends AnyRef
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 executeWATCH
andUNWATCH
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).
-
trait
RedisOpExecutor extends AnyRef
Base trait for Redis clients with ability to execute RedisOps.
- trait RedisOperationApi extends RedisNodeApi with TransactionApi
- abstract class RedisOptCommand[T] extends AbstractRedisCommand[commons.Opt[T]]
- abstract class RedisOptDataCommand[A] extends AbstractRedisCommand[commons.Opt[A]]
- abstract class RedisOptDataSeqCommand[A] extends AbstractRedisCommand[Seq[commons.Opt[A]]]
- abstract class RedisOptDoubleCommand extends AbstractRedisCommand[commons.Opt[Double]]
- abstract class RedisOptLongCommand extends AbstractRedisCommand[commons.Opt[Long]]
- abstract class RedisOptSeqCommand[T] extends AbstractRedisCommand[commons.Opt[Seq[T]]]
- abstract class RedisOptStringCommand extends AbstractRedisCommand[commons.Opt[String]]
- abstract class RedisPositiveLongCommand extends AbstractRedisCommand[commons.Opt[Long]]
- trait RedisRawApi extends ApiSubset
- abstract class RedisRawCommand extends AbstractRedisCommand[ValidRedisMsg]
-
case class
RedisRecordCodec[T](read: (IndexedSeq[BulkStringMsg]) ⇒ T, write: (T) ⇒ IndexedSeq[BulkStringMsg]) extends Product with Serializable
- Annotations
- @implicitNotFound( ... )
- class RedisRecordInput extends ObjectInput
- class RedisRecordOutput extends ObjectOutput
- trait RedisRecoverableConnectionApi extends RedisRecoverableNodeApi with RedisConnectionApi
- trait RedisRecoverableKeyedApi extends RedisKeyedApi with RecoverableKeyedScriptingApi
- trait RedisRecoverableNodeApi extends RedisRecoverableKeyedApi with RedisNodeApi
- abstract class RedisScanCommand[T] extends AbstractRedisCommand[(Cursor, Seq[T])]
- abstract class RedisSeqCommand[T] extends AbstractRedisCommand[Seq[T]]
-
trait
RedisSerialization extends AnyRef
Encapsulates types that Redis commands may be parameterized with and provides serialization for these types.
- abstract class RedisSimpleStringCommand extends AbstractRedisCommand[String]
- abstract class RedisUnitCommand extends AbstractRedisCommand[Unit]
-
trait
ReplyPreprocessor extends AnyRef
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). -
trait
Sequencer[Ops, Res] extends AnyRef
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 theOps
type. For example, ifOps
is(RedisBatch[Int], RedisBatch[String])
(tuple) thenRes
will be(Int, String)
. IfOps
isList[RedisBatch[Int]]
thenRes
will beList[Int]
.Nesting is also possible. For example, if
Ops
is(List[RedisBatch[Int]], RedisBatch[String])
thenRes
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( ... )
- trait SinglePackBatch[+A] extends RedisBatch[A] with RawCommandPack
- final class Transaction[+A] extends SinglePackBatch[A]
- trait TupleSequencers extends AnyRef
- trait UnsafeCommand extends RawCommand
- trait WatchState extends AnyRef
Value Members
- object ApiSubset
- object ClusterState extends Serializable
- object CommandEncoder
- object FlatMapper
- object Gen
- object HasFlatMap
-
object
Hash
Implementation of key hashing function used in Redis Cluster, as specified in Redis Cluster Specification
- object NodeAddress extends Serializable
- object RawCommand
- object RawCommandPacks
- object RedirectionError
- object RedirectionException
- object RedirectionReply
-
object
RedisApi
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:
- RedisApi.Raw - type returned for each command-method is RawCommand. Probably the only reason to use this API variant is to pass a RawCommand to commandGetkeys
- RedisApi.Batches - type returned for each command-method is RedisBatch. Batch can then be combined with other batches to form larger batches, become a part of RedisOp or simply get executed by RedisExecutor (e.g. one of Redis client implementations).
- RedisApi.Keyed.Async, RedisApi.Node.Async and RedisApi.Connection.Async variants are the ones that
actually execute commands by sending them to Redis. Because of that, they take an appropriate RedisExecutor
as constructor argument. Execution of commands is asynchronous and results are returned as
Future
s. - RedisApi.Keyed.Blocking, RedisApi.Node.Blocking and RedisApi.Connection.Blocking are similar
to their
Async
counterparts but execution is blocking and results are returned as unwrapped values.
Async
andBlocking
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. Also, it is possible to customize
Record
type which is used primarily for entries in Redis Stream API.Record
type requires RedisRecordCodec instance.Key, field, value and record types and their serialization typeclass instances are enapsulated by RedisSerialization instances. API variants are then parameterized with them.
API variants which use only
String
s (textual) or onlyByteString
s (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))
- object RedisBatch extends HasFlatMap[RedisBatch]
- object RedisDataCodec extends LowPriorityRedisDataCodecs with Serializable
- object RedisDataInput
- object RedisDataOutput
- object RedisDataUtils
- object RedisOp extends HasFlatMap[RedisOp]
- object RedisRecordCodec extends LowPriorityRedisRecordCodecs with Serializable
- object RedisSerialization
- object Sequencer extends TupleSequencers
- object TryagainReply
- object TupleSequencers