trait KeyCommands extends AnyRef
This trait implements key commands.
- Self Type
- KeyCommands with NonBlockingConnection
- Alphabetic
- By Inheritance
- KeyCommands
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def del(keys: String*): Future[Long]
Deletes one or multiple keys.
Deletes one or multiple keys.
- keys
key(s) to delete
- returns
the number of keys that were deleted
- Since
1.0.0
- Note
a key is ignored if it does not exist
- def dump(key: String): Future[Option[Array[Byte]]]
Returns a serialized version of the value stored at the specified key.
Returns a serialized version of the value stored at the specified key.
- key
key to dump
- returns
the serialized value or
None
if the key does not exist
- Since
2.6.0
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def exists(key: String): Future[Boolean]
Determines if a key exists.
Determines if a key exists.
- key
key to check for existence
- returns
true if the key exists, false otherwise
- Since
1.0.0
- def expire(key: String, ttlSeconds: Int): Future[Boolean]
Sets a key's time to live in seconds.
Sets a key's time to live in seconds.
- key
key to expire
- ttlSeconds
time-to-live in seconds
- returns
true if the ttl was set, false if key does not exist or the timeout could not be set
- Since
1.0.0
- def expireAt(key: String, timestamp: Long): Future[Boolean]
Sets the expiration for a key as a UNIX timestamp.
Sets the expiration for a key as a UNIX timestamp.
- key
key to expire
- timestamp
UNIX timestamp at which the key should expire
- returns
true if the ttl was set, false if key does not exist or the timeout could not be set
- Since
1.2.0
- def finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def keys(pattern: String): Future[Set[String]]
Finds all keys matching the given pattern.
Finds all keys matching the given pattern.
- pattern
pattern to search for
- returns
the matched keys, or the empty set if no keys match the given pattern
- Since
1.0.0
- def migrate(key: String, host: String, port: Int = 6379, database: Int = 0, timeout: FiniteDuration = 2 seconds, copy: Boolean = false, replace: Boolean = false): Future[Unit]
Atomically transfers a key from a Redis instance to another one.
Atomically transfers a key from a Redis instance to another one.
- key
key to transfer
- host
destination host
- port
destination port
- database
destination database
- timeout
timeout duration, up to milliseconds precision
- copy
if true, do not remove the key from the local instance
- replace
if true, replace existing key on the remote instance
- Since
2.6.0
- Exceptions thrown
[[scredis.exceptions.RedisErrorResponseException]]
if an error occurs
- def move(key: String, database: Int): Future[Boolean]
Moves a key to another database.
Moves a key to another database.
- key
key to move
- database
destination database
- returns
true if key was moved, false otherwise
- Since
1.0.0
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def objectEncoding(key: String): Future[Option[String]]
Returns the kind of internal representation used in order to store the value associated with a key.
Returns the kind of internal representation used in order to store the value associated with a key.
- key
the key
- returns
the object encoding or
None
if the key does not exist
- Since
2.2.3
- Note
Objects can be encoded in different ways: Strings can be encoded as
raw
orint
Lists can be encoded asziplist
orlinkedlist
Sets can be encoded asintset
orhashtable
Hashes can be encoded aszipmap
orhashtable
SortedSets can be encoded asziplist
orskiplist
- def objectIdleTime(key: String): Future[Option[Long]]
Returns the number of seconds since the object stored at the specified key is idle (not requested by read or write operations).
Returns the number of seconds since the object stored at the specified key is idle (not requested by read or write operations).
- key
the key
- returns
the number of seconds since the object is idle or
None
if the key does not exist
- Since
2.2.3
- Note
While the value is returned in seconds the actual resolution of this timer is 10 seconds, but may vary in future implementations.
- def objectRefCount(key: String): Future[Option[Long]]
Returns the number of references of the value associated with the specified key.
Returns the number of references of the value associated with the specified key.
- key
the key
- returns
the number of references or
None
if the key does not exist
- Since
2.2.3
- def pExpire(key: String, ttlMillis: Long): Future[Boolean]
Sets a key's time to live in milliseconds.
Sets a key's time to live in milliseconds.
- key
key to expire
- ttlMillis
time-to-live in milliseconds
- returns
true if the ttl was set, false if key does not exist or the timeout could not be set
- Since
2.6.0
- def pExpireAt(key: String, timestampMillis: Long): Future[Boolean]
Sets the expiration for a key as a UNIX timestamp specified in milliseconds.
Sets the expiration for a key as a UNIX timestamp specified in milliseconds.
- key
key to expire
- timestampMillis
UNIX milliseconds-timestamp at which the key should expire
- returns
true if the ttl was set, false if key does not exist or the timeout could not be set
- Since
2.6.0
- def pTtl(key: String): Future[Either[Boolean, Long]]
Gets the time to live for a key in milliseconds.
Gets the time to live for a key in milliseconds.
result match { case Left(false) => // key does not exist case Left(true) => // key exists but has no associated expire case Right(ttl) => }
- key
the target key
- returns
Right(ttl)
where ttl is the time-to-live in milliseconds for specified key,Left(false)
if key does not exist orLeft(true)
if key exists but has no associated expire
- Since
2.6.0
- Note
For
Redis
version <= 2.8.x,Left(false)
will be returned when the key does not exists and when it exists but has no associated expire (Redis
returns the same error code for both cases). In other words, you can simply check the followingresult match { case Left(_) => case Right(ttl) => }
- def persist(key: String): Future[Boolean]
Removes the expiration from a key.
Removes the expiration from a key.
- key
key to persist
- returns
true if key was persisted, false if key does not exist or does not have an associated timeout
- Since
2.2.0
- def randomKey(): Future[Option[String]]
Returns a random key from the keyspace.
Returns a random key from the keyspace.
- returns
the random key or
None
when the database is empty associated timeout
- Since
1.0.0
- def rename(key: String, newKey: String): Future[Unit]
Renames a key.
Renames a key.
- key
source key
- newKey
destination key
- Since
1.0.0
- Exceptions thrown
[[scredis.exceptions.RedisErrorResponseException]]
if the source and destination keys are the same, or when key does not exist- Note
if newKey already exists, it is overwritten
- def renameNX(key: String, newKey: String): Future[Boolean]
Renames a key, only if the new key does not exist.
Renames a key, only if the new key does not exist.
- key
source key
- newKey
destination key
- returns
true if key was renamed to newKey, false if newKey already exists
- Since
1.0.0
- Exceptions thrown
[[scredis.exceptions.RedisErrorResponseException]]
if the source and destination keys are the same, or when key does not exist
- def restore[W](key: String, serializedValue: W, ttlOpt: Option[FiniteDuration] = None)(implicit arg0: Writer[W]): Future[Unit]
Creates a key using the provided serialized value, previously obtained using DUMP.
Creates a key using the provided serialized value, previously obtained using DUMP.
- key
destination key
- serializedValue
serialized value, previously obtained using DUMP
- ttlOpt
optional time-to-live duration of newly created key (expire)
- Since
2.6.0
- Exceptions thrown
[[scredis.exceptions.RedisErrorResponseException]]
if the value could not be restored
- def scan(cursor: Long, matchOpt: Option[String] = None, countOpt: Option[Int] = None): Future[(Long, Set[String])]
Incrementally iterates the set of keys in the currently selected Redis database.
Incrementally iterates the set of keys in the currently selected Redis database.
- cursor
the offset
- matchOpt
when defined, the command only returns elements matching the pattern
- countOpt
when defined, provides a hint of how many elements should be returned
- returns
a pair containing the next cursor as its first element and the set of keys as its second element
- Since
2.8.0
- def sort[R](key: String, byOpt: Option[String] = None, limitOpt: Option[(Long, Long)] = None, get: Iterable[String] = Nil, desc: Boolean = false, alpha: Boolean = false)(implicit arg0: Reader[R]): Future[List[Option[R]]]
Sorts the elements of a list, set or sorted set.
Sorts the elements of a list, set or sorted set.
- key
key of list, set or sorted set to be sorted
- byOpt
optional pattern for sorting by external values, can also be "nosort" if the sorting operation should be skipped (useful when only sorting to retrieve objects with get). The * gets replaced by the values of the elements in the collection
- limitOpt
optional pair of numbers (offset, count) where offset specified the number of elements to skip and count specifies the number of elements to return starting from offset
- get
list of patterns for retrieving objects stored in external keys. The * gets replaced by the values of the elements in the collection
- desc
indicates whether elements should be sorted descendingly
- alpha
indicates whether elements should be sorted lexicographically
- returns
the sorted list of elements, or the empty list if the key does not exist
- Since
1.0.0
- Exceptions thrown
[[scredis.exceptions.RedisErrorResponseException]]
whenever an error occurs
- def sortAndStore(key: String, targetKey: String, byOpt: Option[String] = None, limitOpt: Option[(Long, Long)] = None, get: Iterable[String] = Nil, desc: Boolean = false, alpha: Boolean = false): Future[Long]
Sorts the elements of a list, set or sorted set and then store the result.
Sorts the elements of a list, set or sorted set and then store the result.
- key
key of list, set or sorted set to be sorted
- targetKey
key of list, set or sorted set to be sorted
- byOpt
optional pattern for sorting by external values, can also be "nosort" if the sorting operation should be skipped (useful when only sorting to retrieve objects with get). The * gets replaced by the values of the elements in the collection
- limitOpt
optional pair of numbers (offset, count) where offset specified the number of elements to skip and count specifies the number of elements to return starting from offset
- get
list of patterns for retrieving objects stored in external keys. The * gets replaced by the values of the elements in the collection
- desc
indicates whether elements should be sorted descendingly
- alpha
indicates whether elements should be sorted lexicographically
- returns
the number of elements in the newly stored sorted collection
- Since
1.0.0
- Exceptions thrown
[[scredis.exceptions.RedisErrorResponseException]]
whenever an error occurs
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def ttl(key: String): Future[Either[Boolean, Int]]
Gets the time to live for a key in seconds.
Gets the time to live for a key in seconds.
result match { case Left(false) => // key does not exist case Left(true) => // key exists but has no associated expire case Right(ttl) => }
- key
the target key
- returns
Right(ttl)
where ttl is the time-to-live in seconds for specified key,Left(false)
if key does not exist orLeft(true)
if key exists but has no associated expire
- Since
1.0.0
- Note
For
Redis
version <= 2.8.x,Left(false)
will be returned when the key does not exists and when it exists but has no associated expire (Redis
returns the same error code for both cases). In other words, you can simply check the followingresult match { case Left(_) => case Right(ttl) => }
- def type(key: String): Future[Option[Type]]
Determine the type stored at key.
Determine the type stored at key.
- key
key for which the type should be returned
- returns
type of key, or
None
if key does not exist
- Since
1.0.0
- Note
This method needs to be called as follows:
client.`type`(key)
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()