License
Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
Redis database client implementation.
A redis client with connection pooling.
ConnectionPool!RedisConnection m_connectionsstring m_authPasswordstring m_versionlong m_selectedDB6379 defaultPortvoid 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.RedisDatabase getDatabase(long index)Returns a handle to the given database.RedisSubscriber createSubscriber()Creates a RedisSubscriber instance for launching a pubsub listenervoid auth(string password)Authenticate to the servervoid ping()Ping the servervoid quit()Close the connectionT getConfig(T)(string parameter) if(isValidRedisValueReturn!T)Get the value of a configuration parametervoid setConfig(T)(string parameter, T value) if(isValidRedisValueType!T)Set a configuration parameter to the given valuevoid configResetStat()Reset the stats returned by INFOvoid deleteAll()Deletes all keys from all databases.string info()Get information and statistics about the serverlong lastSave()Get the UNIX time stamp of the last successful save to diskvoid save()Synchronously save the dataset to diskvoid shutdown()Synchronously save the dataset to disk and then shut down the servervoid slaveOf(string host, ushort port)Make the server a slave of another instance, or promote it as masterT request(T = void, ARGS...)(string command, scope ARGS args)T requestDB(T, ARGS...)(long db, string command, scope ARGS args)this(string host = "127.0.0.1", ushort port = defaultPort)Accesses the contents of a Redis database
void deleteAll()Deletes all keys of the database.long del(scope string[] keys...)Delete a keybool exists(string key)Determine if a key existsbool expire(string key, long seconds)Set a key's time to live in secondsbool 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 timestampRedisReply!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 databasebool persist(string key)Remove the expiration from a keystring randomKey()Return a random key from the keyspacevoid rename(string key, string newkey)Rename a keybool renameNX(string key, string newkey)Rename a key, only if the new key does not existlong ttl(string key)Get the time to live for a keylong pttl(string key)Get the time to live for a key in millisecondsstring 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 keylong decr(string key, long value = 1)Decrement the integer value of a key by oneT get(T = string)(string key) if(isValidRedisValueReturn!T)Get the value of a keybool getBit(string key, long offset)Returns the bit value at offset in the string value stored at keyT getRange(T = string)(string key, long start, long end) if(isValidRedisValueReturn!T)Get a substring of the string stored at a keyT getSet(T = string, U)(string key, U value) if(isValidRedisValueReturn!T && isValidRedisValueType!U)Set the string value of a key and return its old valuelong incr(string key, long value = 1)Increment the integer value of a keylong incr(string key, double value)Increment the real number value of a keyRedisReply!T mget(T = string)(string[] keys) if(isValidRedisValueType!T)Get the values of all the given keysvoid mset(ARGS...)(ARGS args)Set multiple keys to multiple valuesbool msetNX(ARGS...)(ARGS args)Set multiple keys to multiple values, only if none of the keys existvoid set(T)(string key, T value) if(isValidRedisValueType!T)Set the string value of a keybool setNX(T)(string key, T value) if(isValidRedisValueType!T)Set the value of a key, only if the key does not existbool setXX(T)(string key, T value) if(isValidRedisValueType!T)Set the value of a key, only if the key already existsbool 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 keyvoid setEX(T)(string key, long seconds, T value) if(isValidRedisValueType!T)Set the value and expiration of a keylong setRange(T)(string key, long offset, T value) if(isValidRedisValueType!T)Overwrite part of a string at key starting at the specified offsetlong strlen(string key)Get the length of the value stored in a keylong hdel(string key, scope string[] fields...)Delete one or more hash fieldsbool hexists(string key, string field)Determine if a hash field existsvoid hset(T)(string key, string field, T value) if(isValidRedisValueType!T)Set multiple hash fields to multiple valuesbool hsetNX(T)(string key, string field, T value) if(isValidRedisValueType!T)Set the value of a hash field, only if the field does not existT 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 hashlong hincr(string key, string field, long value = 1)Increment the integer value of a hash fieldlong hincr(string key, string field, double value)Increment the real number value of a hash fieldRedisReply!T hkeys(T = string)(string key) if(isValidRedisValueType!T)Get all the fields in a hashlong hlen(string key)Get the number of fields in a hashRedisReply!T hmget(T = string)(string key, scope string[] fields...) if(isValidRedisValueType!T)Get the values of all the given hash fieldsvoid hmset(ARGS...)(string key, ARGS args)Set multiple hash fields to multiple valuesRedisReply!T hvals(T = string)(string key) if(isValidRedisValueType!T)Get all the values in a hashT lindex(T = string)(string key, long index) if(isValidRedisValueReturn!T)Get an element from a list by its indexlong 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 keylong 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 existslong 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 maxdouble 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 inclusivelyRedisReply!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 channelRedisReply!T pubsub(T = string)(string subcommand, scope string[] args...) if(isValidRedisValueType!T)Inspect the state of the Pub/Sub subsystemlong dbSize()Return the number of keys in the selected databaseRedisReply!T eval(T = string, ARGS...)(string lua_code, scope string[] keys, scope ARGS args) if(isValidRedisValueType!T)Execute a Lua script server sideRedisReply!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 serverstring[2] getMinMaxArgs(string RNG)(double min, double max)this(RedisClient client, long index)A redis subscription listener
RedisClient m_clientLockedConnection!RedisConnection m_lockedConnectionbool[string] m_subscriptionsstring[] m_pendingSubscriptionsbool m_listeningbool m_stopTask m_listenerTask m_listenerHelperTask m_waiterTask m_stopWaiterInterruptibleRecursiveTaskMutex m_mutexInterruptibleTaskMutex m_connMutexbool hasSubscription(string channel) constvoid bstop(){Stop listening and yield until the operation is complete.void stop(){Stop listening asynchroneouslybool hasNewSubscriptionIn(scope string[] args)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.void init(){this(RedisClient client)ActionRange interface to a single Redis reply.
void popFront()Pops the current element of the replyTN next(TN : E[], E)()Legacy property for hasNext/next based iterationvoid drop()void readData()void clearData()void initialize()void readBulk(string sizeLn)this(RedisConnection conn)this(string message, string file = __FILE__, size_t line = __LINE__, Exception next = null)long refCountubyte[] databool hasDatabool multibool initializedbool frontIsNulllong lengthlong indexubyte[128] dataBufferstring m_hostushort m_portTCPConnection m_connstring m_passwordlong m_selectedDBRedisReplyContext m_replyContextvoid setAuth(string password)void setDB(long index)long countArgs(ARGS...)(scope ARGS args)void writeArgs(R, ARGS...)(R dst, scope ARGS args) if (isOutputRange!(R, char))long formattedLength(ARG)(scope ARG arg)this(string host, ushort port)RedisClient connectRedis(string host, ushort port = RedisClient.defaultPort)Returns a RedisClient that can be used to communicate to the specified database server.RedisDatabase connectRedisDB(URL url)Returns a Redis database connection instance corresponding to the given URL.RedisReply!T _request_reply(T = ubyte[], ARGS...)(RedisConnection conn, string command, scope ARGS args)T _request(T, ARGS...)(LockedConnection!RedisConnection conn, string command, scope ARGS args)