vibe.db.redis.redis

Redis database client implementation.

Types 8

A redis client with connection pooling.

Fields
ConnectionPool!RedisConnection m_connections
string m_authPassword
string m_version
long m_selectedDB
6379 defaultPort
Methods
void releaseUnusedConnections() @safeRelease all connections that are not in use. Call before exiting the program to avoid relying on the GC to clean up the sockets.
string redisVersion() @propertyReturns Redis version
RedisDatabase getDatabase(long index)Returns a handle to the given database.
RedisSubscriber createSubscriber()Creates a RedisSubscriber instance for launching a pubsub listener
void auth(string password)Authenticate to the server
T echo(T, U)(U data) if(isValidRedisValueReturn!T && isValidRedisValueType!U)Echo the given string
void ping()Ping the server
void quit()Close the connection
T getConfig(T)(string parameter) if(isValidRedisValueReturn!T)Get the value of a configuration parameter
void setConfig(T)(string parameter, T value) if(isValidRedisValueType!T)Set a configuration parameter to the given value
void configResetStat()Reset the stats returned by INFO
void deleteAll()Deletes all keys from all databases.
string info()Get information and statistics about the server
long lastSave()Get the UNIX time stamp of the last successful save to disk
void save()Synchronously save the dataset to disk
void shutdown()Synchronously save the dataset to disk and then shut down the server
void slaveOf(string host, ushort port)Make the server a slave of another instance, or promote it as master
private T request(T = void, ARGS...)(string command, scope ARGS args)
private T requestDB(T, ARGS...)(long db, string command, scope ARGS args)
Constructors
this(string host = "127.0.0.1", ushort port = defaultPort)

Accesses the contents of a Redis database

Fields
RedisClient m_client
long m_index
Methods
inout(RedisClient) client() @property inoutThe Redis client with which the database is accessed.
long index() @property constIndex of the database.
void deleteAll()Deletes all keys of the database.
long del(scope string[] keys...)Delete a key
bool exists(string key)Determine if a key exists
bool expire(string key, long seconds)Set a key's time to live in seconds
bool expire(string key, Duration timeout)Set a key's time to live with D notation. E.g. 5.minutes for 60 * 5 seconds.
bool expireAt(string key, long timestamp)Set the expiration for a key as a UNIX timestamp
RedisReply!T keys(T = string)(string pattern) if(isValidRedisValueType!T)Find all keys matching the given glob-style pattern (Supported wildcards: *, ?, [ABC])
bool move(string key, long db)Move a key to another database
bool persist(string key)Remove the expiration from a key
string randomKey()Return a random key from the keyspace
void rename(string key, string newkey)Rename a key
bool renameNX(string key, string newkey)Rename a key, only if the new key does not exist
long ttl(string key)Get the time to live for a key
long pttl(string key)Get the time to live for a key in milliseconds
string type(string key)Determine the type stored at key (string, list, set, zset and hash.)
long append(T)(string key, T suffix) if(isValidRedisValueType!T)Append a value to a key
long decr(string key, long value = 1)Decrement the integer value of a key by one
T get(T = string)(string key) if(isValidRedisValueReturn!T)Get the value of a key
bool getBit(string key, long offset)Returns the bit value at offset in the string value stored at key
T getRange(T = string)(string key, long start, long end) if(isValidRedisValueReturn!T)Get a substring of the string stored at a key
T getSet(T = string, U)(string key, U value) if(isValidRedisValueReturn!T && isValidRedisValueType!U)Set the string value of a key and return its old value
long incr(string key, long value = 1)Increment the integer value of a key
long incr(string key, double value)Increment the real number value of a key
RedisReply!T mget(T = string)(string[] keys) if(isValidRedisValueType!T)Get the values of all the given keys
void mset(ARGS...)(ARGS args)Set multiple keys to multiple values
bool msetNX(ARGS...)(ARGS args)Set multiple keys to multiple values, only if none of the keys exist
void set(T)(string key, T value) if(isValidRedisValueType!T)Set the string value of a key
bool setNX(T)(string key, T value) if(isValidRedisValueType!T)Set the value of a key, only if the key does not exist
bool setXX(T)(string key, T value) if(isValidRedisValueType!T)Set the value of a key, only if the key already exists
bool setNX(T)(string key, T value, Duration expire_time) if(isValidRedisValueType!T)Set the value of a key, only if the key does not exist, and also set the specified expire time using D notation, e.g. 5.minutes for 5 minutes.
bool setXX(T)(string key, T value, Duration expire_time) if(isValidRedisValueType!T)Set the value of a key, only if the key already exists, and also set the specified expire time using D notation, e.g. 5.minutes for 5 minutes.
bool setBit(string key, long offset, bool value)Sets or clears the bit at offset in the string value stored at key
void setEX(T)(string key, long seconds, T value) if(isValidRedisValueType!T)Set the value and expiration of a key
long setRange(T)(string key, long offset, T value) if(isValidRedisValueType!T)Overwrite part of a string at key starting at the specified offset
long strlen(string key)Get the length of the value stored in a key
long hdel(string key, scope string[] fields...)Delete one or more hash fields
bool hexists(string key, string field)Determine if a hash field exists
void hset(T)(string key, string field, T value) if(isValidRedisValueType!T)Set multiple hash fields to multiple values
bool hsetNX(T)(string key, string field, T value) if(isValidRedisValueType!T)Set the value of a hash field, only if the field does not exist
T hget(T = string)(string key, string field) if(isValidRedisValueReturn!T)Get the value of a hash field.
RedisReply!T hgetAll(T = string)(string key) if(isValidRedisValueType!T)Get all the fields and values in a hash
long hincr(string key, string field, long value = 1)Increment the integer value of a hash field
long hincr(string key, string field, double value)Increment the real number value of a hash field
RedisReply!T hkeys(T = string)(string key) if(isValidRedisValueType!T)Get all the fields in a hash
long hlen(string key)Get the number of fields in a hash
RedisReply!T hmget(T = string)(string key, scope string[] fields...) if(isValidRedisValueType!T)Get the values of all the given hash fields
void hmset(ARGS...)(string key, ARGS args)Set multiple hash fields to multiple values
RedisReply!T hvals(T = string)(string key) if(isValidRedisValueType!T)Get all the values in a hash
T lindex(T = string)(string key, long index) if(isValidRedisValueReturn!T)Get an element from a list by its index
long linsertBefore(T1, T2)(string key, T1 pivot, T2 value) if(isValidRedisValueType!T1 && isValidRedisValueType!T2)Insert value in the list stored at key before the reference value pivot.
long linsertAfter(T1, T2)(string key, T1 pivot, T2 value) if(isValidRedisValueType!T1 && isValidRedisValueType!T2)Insert value in the list stored at key after the reference value pivot.
long llen(string key)Returns the length of the list stored at key. If key does not exist, it is interpreted as an empty list and 0 is returned.
long lpush(ARGS...)(string key, ARGS args)Insert all the specified values at the head of the list stored at key.
long lpushX(T)(string key, T value) if(isValidRedisValueType!T)Inserts value at the head of the list stored at key, only if key already exists and holds a list.
long rpush(ARGS...)(string key, ARGS args)Insert all the specified values at the tail of the list stored at key.
long rpushX(T)(string key, T value) if(isValidRedisValueType!T)Inserts value at the tail of the list stored at key, only if key already exists and holds a list.
RedisReply!T lrange(T = string)(string key, long start, long stop)Returns the specified elements of the list stored at key.
long lrem(T)(string key, long count, T value) if(isValidRedisValueType!T)Removes the first count occurrences of elements equal to value from the list stored at key.
void lset(T)(string key, long index, T value) if(isValidRedisValueType!T)Sets the list element at index to value.
void ltrim(string key, long start, long stop)Trim an existing list so that it will contain only the specified range of elements specified. Equivalent to range = range[start .. stop+1]
T rpop(T = string)(string key) if(isValidRedisValueReturn!T)Removes and returns the last element of the list stored at key.
T lpop(T = string)(string key) if(isValidRedisValueReturn!T)Removes and returns the first element of the list stored at key.
Nullable!(Tuple!(string, T)) blpop(T = string)(string key, long seconds) if(isValidRedisValueReturn!T)BLPOP is a blocking list pop primitive. It is the blocking version of LPOP because it blocks the connection when there are no elements to pop from any of the given lists.
T rpoplpush(T = string)(string key, string destination) if(isValidRedisValueReturn!T)Atomically returns and removes the last element (tail) of the list stored at source, and pushes the element at the first element (head) of the list stored at destination.
long sadd(ARGS...)(string key, ARGS args)Add the specified members to the set stored at key. Specified members that are already a member of this set are ignored. If key does not exist, a new set is created before adding the specified memb...
long scard(string key)Returns the set cardinality (number of elements) of the set stored at key.
RedisReply!T sdiff(T = string)(scope string[] keys...) if(isValidRedisValueType!T)Returns the members of the set resulting from the difference between the first set and all the successive sets.
long sdiffStore(string destination, scope string[] keys...)This command is equal to SDIFF, but instead of returning the resulting set, it is stored in destination. If destination already exists, it is overwritten.
RedisReply!T sinter(T = string)(string[] keys) if(isValidRedisValueType!T)Returns the members of the set resulting from the intersection of all the given sets.
long sinterStore(string destination, scope string[] keys...)This command is equal to SINTER, but instead of returning the resulting set, it is stored in destination. If destination already exists, it is overwritten.
bool sisMember(T)(string key, T member) if(isValidRedisValueType!T)Returns if member is a member of the set stored at key.
RedisReply!T smembers(T = string)(string key) if(isValidRedisValueType!T)Returns all the members of the set value stored at key.
bool smove(T)(string source, string destination, T member) if(isValidRedisValueType!T)Move member from the set at source to the set at destination. This operation is atomic. In every given moment the element will appear to be a member of source or destination for other clients.
T spop(T = string)(string key) if(isValidRedisValueReturn!T)Removes and returns a random element from the set value stored at key.
T srandMember(T = string)(string key) if(isValidRedisValueReturn!T)Returns a random element from the set stored at key.
RedisReply!T srandMember(T = string)(string key, long count) if(isValidRedisValueReturn!T)returns count random elements from the set stored at key
long srem(ARGS...)(string key, ARGS args)Remove the specified members from the set stored at key.
RedisReply!T sunion(T = string)(scope string[] keys...) if(isValidRedisValueType!T)Returns the members of the set resulting from the union of all the given sets.
long sunionStore(scope string[] keys...)This command is equal to SUNION, but instead of returning the resulting set, it is stored in destination.
long zadd(ARGS...)(string key, ARGS args)Add one or more members to a sorted set, or update its score if it already exists
long zcard(string key)Returns the sorted set cardinality (number of elements) of the sorted set stored at key.
long zcount(string RNG = "[]")(string key, double min, double max)Returns the number of elements in the sorted set at key with a score between min and max
double zincrby(T)(string key, double value, T member) if (isValidRedisValueType!T)Increments the score of member in the sorted set stored at key by increment.
RedisReply!T zrange(T = string)(string key, long start, long end, bool with_scores = false) if(isValidRedisValueType!T)Returns the specified range of elements in the sorted set stored at key.
long zlexCount(string key, string min = "-", string max = "+")
RedisReply!T zrangeByLex(T = string)(string key, string min = "-", string max = "+", long offset = 0, long count = - 1) if(isValidRedisValueType!T)When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command returns all the elements in the sorted set at key with a value betwe...
RedisReply!T zrangeByScore(T = string, string RNG = "[]")(string key, double start, double end, bool with_scores = false) if(isValidRedisValueType!T)Returns all the elements in the sorted set at key with a score between start and end inclusively
RedisReply!T zrangeByScore(T = string, string RNG = "[]")(string key, double start, double end, long offset, long count, bool with_scores = false) if(isValidRedisValueType!T)Computes an internal list of elements in the sorted set at key with a score between start and end inclusively, and returns a range subselection similar to results[offset .. offset+count]
long zrank(T)(string key, T member) if (isValidRedisValueType!T)Returns the rank of member in the sorted set stored at key, with the scores ordered from low to high.
long zrem(ARGS...)(string key, ARGS members)Removes the specified members from the sorted set stored at key.
long zremRangeByRank(string key, long start, long stop)Removes all elements in the sorted set stored at key with rank between start and stop.
long zremRangeByScore(string RNG = "[]")(string key, double min, double max)Removes all elements in the sorted set stored at key with a score between min and max (inclusive).
RedisReply!T zrevRange(T = string)(string key, long start, long end, bool with_scores = false) if(isValidRedisValueType!T)Returns the specified range of elements in the sorted set stored at key.
RedisReply!T zrevRangeByScore(T = string, string RNG = "[]")(string key, double min, double max, bool with_scores = false) if(isValidRedisValueType!T)Returns all the elements in the sorted set at key with a score between max and min (including elements with score equal to max or min).
RedisReply!T zrevRangeByScore(T = string, string RNG = "[]")(string key, double min, double max, long offset, long count, bool with_scores = false) if(isValidRedisValueType!T)Computes an internal list of elements in the sorted set at key with a score between max and min, and returns a window of elements selected in a way equivalent to results[offset .. offset + count]
long zrevRank(T)(string key, T member) if (isValidRedisValueType!T)Returns the rank of member in the sorted set stored at key, with the scores ordered from high to low.
RedisReply!T zscore(T = string, U)(string key, U member) if(isValidRedisValueType!T && isValidRedisValueType!U)Returns the score of member in the sorted set at key.
long pfadd(ARGS...)(string key, ARGS args)Adds one or more Keys to a HyperLogLog data structure .
long pfcount(scope string[] keys...)Returns the approximated cardinality computed by the HyperLogLog data structure stored at the specified key.
void pfmerge(ARGS...)(string destkey, ARGS args)Merge multiple HyperLogLog values into a new one.
long publish(string channel, string message)Publishes a message to all clients subscribed at the channel
RedisReply!T pubsub(T = string)(string subcommand, scope string[] args...) if(isValidRedisValueType!T)Inspect the state of the Pub/Sub subsystem
long dbSize()Return the number of keys in the selected database
RedisReply!T eval(T = string, ARGS...)(string lua_code, scope string[] keys, scope ARGS args) if(isValidRedisValueType!T)Execute a Lua script server side
RedisReply!T evalSHA(T = string, ARGS...)(string sha, scope string[] keys, scope ARGS args) if(isValidRedisValueType!T)Evaluates a script cached on the server side by its SHA1 digest. Scripts are cached on the server side using the scriptLoad function.
string scriptLoad(string lua_code)Load a script into the scripts cache, without executing it. Run it using evalSHA.
T request(T = void, ARGS...)(string command, scope ARGS args)Run the specified command and arguments in the Redis database server
private string[2] getMinMaxArgs(string RNG)(double min, double max)
Constructors
this(RedisClient client, long index)

A redis subscription listener

Fields
RedisClient m_client
LockedConnection!RedisConnection m_lockedConnection
bool[string] m_subscriptions
string[] m_pendingSubscriptions
bool m_listening
bool m_stop
Task m_listener
Task m_listenerHelper
Task m_waiter
Task m_stopWaiter
InterruptibleRecursiveTaskMutex m_mutex
InterruptibleTaskMutex m_connMutex
Methods
bool isListening() @property const
string[] subscriptions() @property constGet a list of channels with active subscriptions
bool hasSubscription(string channel) const
private void waitForStop() scope
void bstop(){Stop listening and yield until the operation is complete.
void stop(){Stop listening asynchroneously
private bool hasNewSubscriptionIn(scope string[] args)
private bool anySubscribed(scope string[] args)
void subscribe(scope string[] args...)Completes the subscription for a listener to start receiving pubsub messages on the corresponding channel(s). Returns instantly if already subscribed. If a connection error is thrown here, it stops...
void unsubscribe(scope string[] args...)Unsubscribes from the channel(s) specified, returns immediately if none is currently being listened. If a connection error is thrown here, it stops the listener.
void psubscribe(scope string[] args...)Same as subscribe, but uses glob patterns, and does not return instantly if the subscriptions are already registered. throws Exception if the pattern does not yield a new subscription.
void punsubscribe(scope string[] args...)Same as unsubscribe, but uses glob patterns, and does not return instantly if the subscriptions are not registered. throws Exception if the pattern does not yield a new unsubscription.
private void inTask(scope void delegate() @safe impl) @trusted
private void init(){
void blisten(void delegate(string, string) @safe onMessage, Duration timeout = 0.seconds)
Task listen(void delegate(string, string) @safe nothrow callback, Duration timeout = 0.seconds)Waits for messages and calls the callback with the channel and the message as arguments. The timeout is passed over to the listener, which closes after the period of inactivity. Use 0.seconds timeo...
Constructors
Destructors
Nested Templates
Action
structRedisReply(T = ubyte[])

Range interface to a single Redis reply.

Fields
uint m_magic
LockedConnection!RedisConnection m_lockedConnection
Methods
bool empty() @property const
T front() @propertyReturns the current element of the reply.
bool frontIsNull() @property const
void popFront()Pops the current element of the reply
bool hasNext() @property constLegacy property for hasNext/next based iteration
TN next(TN : E[], E)()Legacy property for hasNext/next based iteration
void drop()
private void readData()
private void clearData()
private void lockedConnection(ref LockedConnection!RedisConnection conn) @property
private void initialize()
private void readBulk(string sizeLn)
Constructors
Destructors
classRedisProtocolException : Exception
Constructors
this(string message, string file = __FILE__, size_t line = __LINE__, Exception next = null)
private structRedisReplyContext
Fields
long refCount
ubyte[] data
bool hasData
bool multi
bool initialized
bool frontIsNull
long length
long index
ubyte[128] dataBuffer
private classRedisConnection
Fields
string m_host
ushort m_port
TCPConnection m_conn
string m_password
long m_selectedDB
RedisReplyContext m_replyContext
Methods
TCPConnection conn() @property nothrow
void conn(TCPConnection conn) @property nothrow
void setAuth(string password)
void setDB(long index)
private long countArgs(ARGS...)(scope ARGS args)
private void writeArgs(R, ARGS...)(R dst, scope ARGS args) if (isOutputRange!(R, char))
private long formattedLength(ARG)(scope ARG arg)
Constructors
this(string host, ushort port)

Functions 7

fnRedisClient connectRedis(string host, ushort port = RedisClient.defaultPort)Returns a RedisClient that can be used to communicate to the specified database server.
fnRedisDatabase connectRedisDB(URL url)Returns a Redis database connection instance corresponding to the given URL.
private fnRedisReply!T getReply(T = ubyte)(RedisConnection conn)
private fnvoid _request_void(ARGS...)(RedisConnection conn, string command, scope ARGS args)
private fnRedisReply!T _request_reply(T = ubyte[], ARGS...)(RedisConnection conn, string command, scope ARGS args)
private fnT _request(T, ARGS...)(LockedConnection!RedisConnection conn, string command, scope ARGS args)
private fnT convertToType(T)(ubyte[] data)

Templates 3

tmplisValidRedisValueReturn(T)
tmplisValidRedisValueType(T)
tmpltypeFormatString(T)