redis

package module
v2.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 21 Imported by: 43

README

redis

GoFrame gredis.Adapter implements using go-redis.

Installation

go get -u github.com/gogf/gf/contrib/nosql/redis/v2

Commonly imported at top of main.go:

package main

import (
	_ "github.com/gogf/gf/contrib/nosql/redis/v2"

	// Other imported packages.
)

func main() {
	// Main logics.
}

Documentation

Overview

Package redis provides gredis.Adapter implements using go-redis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn manages the connection operations.

func (*Conn) Close

func (c *Conn) Close(ctx context.Context) (err error)

Close closes current PubSub or puts the connection back to connection pool.

func (*Conn) Do

func (c *Conn) Do(ctx context.Context, command string, args ...interface{}) (reply *gvar.Var, err error)

Do send a command to the server and returns the received reply. It uses json.Marshal for struct/slice/map type values before committing them to redis.

func (*Conn) PSubscribe

func (c *Conn) PSubscribe(ctx context.Context, pattern string, patterns ...string) ([]*gredis.Subscription, error)

PSubscribe subscribes the client to the given patterns.

Supported glob-style patterns: - h?llo subscribes to hello, hallo and hxllo - h*llo subscribes to hllo and heeeello - h[ae]llo subscribes to hello and hallo, but not hillo

Use \ to escape special characters if you want to match them verbatim.

https://redis.io/commands/psubscribe/

func (*Conn) Receive

func (c *Conn) Receive(ctx context.Context) (*gvar.Var, error)

Receive receives a single reply as gvar.Var from the Redis server.

func (*Conn) ReceiveMessage

func (c *Conn) ReceiveMessage(ctx context.Context) (*gredis.Message, error)

ReceiveMessage receives a single message of subscription from the Redis server.

func (*Conn) Subscribe

func (c *Conn) Subscribe(ctx context.Context, channel string, channels ...string) ([]*gredis.Subscription, error)

Subscribe subscribes the client to the specified channels.

https://redis.io/commands/subscribe/

type GroupGeneric

type GroupGeneric struct {
	Operation gredis.AdapterOperation
}

GroupGeneric provides generic functions of redis.

func (GroupGeneric) Copy

func (r GroupGeneric) Copy(ctx context.Context, source, destination string, option ...gredis.CopyOption) (int64, error)

Copy copies the value stored at the source key to the destination key.

By default, the destination key is created in the logical database used by the connection. The DB option allows specifying an alternative logical database index for the destination key.

The command returns an error when the destination key already exists.

It returns: - 1 if source was copied. - 0 if source was not copied.

https://redis.io/commands/copy/

func (GroupGeneric) DBSize

func (r GroupGeneric) DBSize(ctx context.Context) (int64, error)

DBSize return the number of keys in the currently-selected database.

https://redis.io/commands/dbsize/

func (GroupGeneric) Del

func (r GroupGeneric) Del(ctx context.Context, keys ...string) (int64, error)

Del removes the specified keys. a key is ignored if it does not exist.

It returns the number of keys that were removed.

https://redis.io/commands/del/

func (GroupGeneric) Exists

func (r GroupGeneric) Exists(ctx context.Context, keys ...string) (int64, error)

Exists returns if key exists. The user should be aware that if the same existing key is mentioned in the arguments multiple times, it will be counted multiple times.

It returns the number of keys that exist from those specified as arguments.

https://redis.io/commands/exists/

func (GroupGeneric) Expire

func (r GroupGeneric) Expire(ctx context.Context, key string, seconds int64, option ...gredis.ExpireOption) (int64, error)

Expire sets a timeout on key. After the timeout has expired, the key will automatically be deleted.

It returns: - 1 if the timeout was set. - 0 if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.

https://redis.io/commands/expire/

func (GroupGeneric) ExpireAt

func (r GroupGeneric) ExpireAt(ctx context.Context, key string, time time.Time, option ...gredis.ExpireOption) (int64, error)

ExpireAt has the same effect and semantic as EXPIRE, but instead of specifying the number of seconds representing the TTL (time to live), it takes an absolute Unix timestamp (seconds since January 1, 1970). A timestamp in the past will delete the key immediately.

It returns: - 1 if the timeout was set. - 0 if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.

https://redis.io/commands/expireat/

func (GroupGeneric) ExpireTime

func (r GroupGeneric) ExpireTime(ctx context.Context, key string) (*gvar.Var, error)

ExpireTime returns the absolute time at which the given key will expire.

It returns: - -1 if the key exists but has no associated expiration time. - -2 if the key does not exist.

https://redis.io/commands/expiretime/

func (GroupGeneric) FlushAll

func (r GroupGeneric) FlushAll(ctx context.Context, option ...gredis.FlushOp) error

FlushAll delete all the keys of all the existing databases, not just the currently selected one. This command never fails. By default, FlushAll will synchronously flush all the databases.

It is possible to use one of the following modifiers to dictate the flushing mode explicitly: ASYNC: flushes the databases asynchronously SYNC: flushes the databases synchronously

Note: an asynchronous FlushAll command only deletes keys that were present at the time the command was invoked. Keys created during an asynchronous flush will be unaffected.

https://redis.io/commands/flushall/

func (GroupGeneric) FlushDB

func (r GroupGeneric) FlushDB(ctx context.Context, option ...gredis.FlushOp) error

FlushDB delete all the keys of the currently selected DB. This command never fails.

https://redis.io/commands/flushdb/

func (GroupGeneric) Keys

func (r GroupGeneric) Keys(ctx context.Context, pattern string) ([]string, error)

Keys return all keys matching pattern.

While the time complexity for this operation is O(N), the constant times are fairly low. For example, Redis running on an entry level laptop can scan a 1 million key database in 40 milliseconds.

https://redis.io/commands/keys/

func (GroupGeneric) Move

func (r GroupGeneric) Move(ctx context.Context, key string, db int) (int64, error)

Move moves key from the currently selected database (see SELECT) to the specified destination database. When key already exists in the destination database, or it does not exist in the source database, it does nothing. It is possible to use MOVE as a locking primitive because of this.

It returns: - 1 if key was moved. - 0 if key was not moved.

https://redis.io/commands/move/

func (GroupGeneric) PExpire

func (r GroupGeneric) PExpire(ctx context.Context, key string, milliseconds int64, option ...gredis.ExpireOption) (int64, error)

PExpire works exactly like EXPIRE but the time to live of the key is specified in milliseconds instead of seconds.

It returns: - 1 if the timeout was set. - 0 if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.

https://redis.io/commands/pexpire/

func (GroupGeneric) PExpireAt

func (r GroupGeneric) PExpireAt(ctx context.Context, key string, time time.Time, option ...gredis.ExpireOption) (int64, error)

PExpireAt has the same effect and semantic as ExpireAt, but the Unix time at which the key will expire is specified in milliseconds instead of seconds.

https://redis.io/commands/pexpireat/

func (GroupGeneric) PExpireTime

func (r GroupGeneric) PExpireTime(ctx context.Context, key string) (*gvar.Var, error)

PExpireTime returns the expiration time of given `key`.

It returns: - -1 if the key exists but has no associated expiration time. - -2 if the key does not exist.

https://redis.io/commands/pexpiretime/

func (GroupGeneric) PTTL

func (r GroupGeneric) PTTL(ctx context.Context, key string) (int64, error)

PTTL like TTL this command returns the remaining time to live of a key that has an expired set, with the sole difference that TTL returns the amount of remaining time in seconds while PTTL returns it in milliseconds.

In Redis 2.6 or older the command returns -1 if the key does not exist or if the key exist but has no associated expire.

It returns TTL in milliseconds, or a negative value in order to signal an error (see the description above).

https://redis.io/commands/pttl/

func (GroupGeneric) Persist

func (r GroupGeneric) Persist(ctx context.Context, key string) (int64, error)

Persist removes the existing timeout on key, turning the key from volatile (a key with an expire set) to persistent (a key that will never expire as no timeout is associated).

It returns: - 1 if the timeout was removed. - 0 if key does not exist or does not have an associated timeout.

https://redis.io/commands/persist/

func (GroupGeneric) RandomKey

func (r GroupGeneric) RandomKey(ctx context.Context) (string, error)

RandomKey return a random key from the currently selected database.

It returns the random key, or nil when the database is empty.

https://redis.io/commands/randomkey/

func (GroupGeneric) Rename

func (r GroupGeneric) Rename(ctx context.Context, key, newKey string) error

Rename renames key to newKey. It returns an error when key does not exist. If newKey already exists it is overwritten, when this happens RENAME executes an implicit DEL operation, so if the deleted key contains a very big value it may cause high latency even if RENAME itself is usually a constant-time operation.

In Cluster mode, both key and newKey must be in the same hash slot, meaning that in practice only keys that have the same hashtag can be reliably renamed in cluster.

https://redis.io/commands/rename/

func (GroupGeneric) RenameNX

func (r GroupGeneric) RenameNX(ctx context.Context, key, newKey string) (int64, error)

RenameNX renames key to newKey if newKey does not yet exist. It returns an error when key does not exist. In Cluster mode, both key and newKey must be in the same hash slot, meaning that in practice only keys that have the same hashtag can be reliably renamed in cluster.

It returns: - 1 if key was renamed to newKey. - 0 if newKey already exists.

https://redis.io/commands/renamenx/

func (GroupGeneric) TTL

func (r GroupGeneric) TTL(ctx context.Context, key string) (int64, error)

TTL returns the remaining time to live of a key that has a timeout. This introspection capability allows a Redis client to check how many seconds a given key will continue to be part of the dataset. In Redis 2.6 or older the command returns -1 if the key does not exist or if the key exist but has no associated expire.

Starting with Redis 2.8 the return value in case of error changed:

The command returns -2 if the key does not exist. The command returns -1 if the key exists but has no associated expire. See also the PTTL command that returns the same information with milliseconds resolution (Only available in Redis 2.6 or greater).

It returns TTL in seconds, or a negative value in order to signal an error (see the description above).

https://redis.io/commands/ttl/

func (GroupGeneric) Type

func (r GroupGeneric) Type(ctx context.Context, key string) (string, error)

Type returns the string representation of the type of the value stored at key. The different types that can be returned are: string, list, set, zset, hash and stream.

It returns type of key, or none when key does not exist.

https://redis.io/commands/type/

func (r GroupGeneric) Unlink(ctx context.Context, keys ...string) (int64, error)

Unlink is very similar to DEL: it removes the specified keys. Just like DEL a key is ignored if it does not exist. However, the command performs the actual memory reclaiming in a different thread, so it is not blocking, while DEL is. This is where the command name comes from: the command just unlinks the keys from the keyspace. The actual removal will happen later asynchronously.

It returns the number of keys that were unlinked.

https://redis.io/commands/unlink/

type GroupHash

type GroupHash struct {
	Operation gredis.AdapterOperation
}

GroupHash is the redis group object for hash operations.

func (GroupHash) HDel

func (r GroupHash) HDel(ctx context.Context, key string, fields ...string) (int64, error)

HDel removes the specified fields from the hash stored at key. Specified fields that do not exist within this hash are ignored. If key does not exist, it is treated as an empty hash and this command returns 0.

It returns the number of fields that were removed from the hash, not including specified but non-existing fields.

https://redis.io/commands/hdel/

func (GroupHash) HExists

func (r GroupHash) HExists(ctx context.Context, key, field string) (int64, error)

HExists returns if field is an existing field in the hash stored at key.

It returns: - 1 if the hash contains field. - 0 if the hash does not contain field, or key does not exist.

https://redis.io/commands/hexists/

func (GroupHash) HGet

func (r GroupHash) HGet(ctx context.Context, key, field string) (*gvar.Var, error)

HGet returns the value associated with field in the hash stored at key.

It returns the value associated with field, or nil when field is not present in the hash or key does not exist.

https://redis.io/commands/hget/

func (GroupHash) HGetAll

func (r GroupHash) HGetAll(ctx context.Context, key string) (*gvar.Var, error)

HGetAll returns all fields and values of the hash stored at key. In the returned value, every field name is followed by its value, so the length of the reply is twice the size of the hash.

https://redis.io/commands/hgetall/

func (GroupHash) HIncrBy

func (r GroupHash) HIncrBy(ctx context.Context, key, field string, increment int64) (int64, error)

HIncrBy increments the number stored at field in the hash stored at key by increment. If key does not exist, a new key holding a hash is created. If field does not exist the value is set to 0 before the operation is performed.

The range of values supported by HIncrBy is limited to 64-bit signed integers.

https://redis.io/commands/hincrby/

func (GroupHash) HIncrByFloat

func (r GroupHash) HIncrByFloat(ctx context.Context, key, field string, increment float64) (float64, error)

HIncrByFloat increments the specified field of a hash stored at key, and representing a floating point number, by the specified increment. If the increment value is negative, the result is to have the hash field value decremented instead of incremented. If the field does not exist, it is set to 0 before performing the operation. An error is returned if one of the following conditions occur:

The field contains a value of the wrong type (not a string). The current field content or the specified increment are not parsable as a double precision floating point number. The exact behavior of this command is identical to the one of the HIncrByFloat command, please refer to the documentation of HIncrByFloat for further information.

It returns the value of field after the increment.

https://redis.io/commands/hincrbyfloat/

func (GroupHash) HKeys

func (r GroupHash) HKeys(ctx context.Context, key string) ([]string, error)

HKeys returns all field names in the hash stored at key.

https://redis.io/commands/hkeys/

func (GroupHash) HLen

func (r GroupHash) HLen(ctx context.Context, key string) (int64, error)

HLen returns the number of fields contained in the hash stored at key.

https://redis.io/commands/hlen/

func (GroupHash) HMGet

func (r GroupHash) HMGet(ctx context.Context, key string, fields ...string) (gvar.Vars, error)

HMGet return the values associated with the specified fields in the hash stored at key. For every field that does not exist in the hash, a nil value is returned. Because non-existing keys are treated as empty hashes, running HMGet against a non-existing key will return a list of nil values.

https://redis.io/commands/hmget/

func (GroupHash) HMSet

func (r GroupHash) HMSet(ctx context.Context, key string, fields map[string]interface{}) error

HMSet sets the specified fields to their respective values in the hash stored at key. This command overwrites any specified fields already existing in the hash. If key does not exist, a new key holding a hash is created.

https://redis.io/commands/hmset/

func (GroupHash) HSet

func (r GroupHash) HSet(ctx context.Context, key string, fields map[string]interface{}) (int64, error)

HSet sets field in the hash stored at key to value. If key does not exist, a new key holding a hash is created. If field already exists in the hash, it is overwritten.

It returns the number of fields that were added.

https://redis.io/commands/hset/

func (GroupHash) HSetNX

func (r GroupHash) HSetNX(ctx context.Context, key, field string, value interface{}) (int64, error)

HSetNX sets field in the hash stored at key to value, only if field does not yet exist. If key does not exist, a new key holding a hash is created. If field already exists, this operation has no effect.

It returns: - 1 if field is a new field in the hash and value was set. - 0 if field already exists in the hash and no operation was performed.

https://redis.io/commands/hsetnx/

func (GroupHash) HStrLen

func (r GroupHash) HStrLen(ctx context.Context, key, field string) (int64, error)

HStrLen Returns the string length of the value associated with field in the hash stored at key. If the key or the field do not exist, 0 is returned.

It returns the string length of the value associated with field, or zero when field is not present in the hash or key does not exist at all.

https://redis.io/commands/hstrlen/

func (GroupHash) HVals

func (r GroupHash) HVals(ctx context.Context, key string) (gvar.Vars, error)

HVals return all values in the hash stored at key.

https://redis.io/commands/hvals/

type GroupList

type GroupList struct {
	Operation gredis.AdapterOperation
}

GroupList is the redis group list object.

func (GroupList) BLPop

func (r GroupList) BLPop(ctx context.Context, timeout int64, keys ...string) (gvar.Vars, error)

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. An element is popped from the head of the first list that is non-empty, with the given keys being checked in the order that they are given.

The timeout argument is interpreted as a double value specifying the maximum number of seconds to block. A timeout of zero can be used to block indefinitely.

https://redis.io/commands/blpop/

func (GroupList) BRPop

func (r GroupList) BRPop(ctx context.Context, timeout int64, keys ...string) (gvar.Vars, error)

BRPop is a blocking list pop primitive. It is the blocking version of RPop because it blocks the connection when there are no elements to pop from any of the given lists. An element is popped from the tail of the first list that is non-empty, with the given keys being checked in the order that they are given.

The timeout argument is interpreted as a double value specifying the maximum number of seconds to block. A timeout of zero can be used to block indefinitely.

https://redis.io/commands/brpop/

func (GroupList) BRPopLPush

func (r GroupList) BRPopLPush(ctx context.Context, source, destination string, timeout int64) (*gvar.Var, error)

BRPopLPush is the blocking variant of RPopLPush. When source contains elements, this command behaves exactly like RPopLPush. When used inside a MULTI/EXEC block, this command behaves exactly like RPopLPush. When source is empty, Redis will block the connection until another // client pushes to it or until timeout is reached. A timeout of zero can be used to block indefinitely.

It returns the element being popped from source and pushed to destination. If timeout is reached, a Null reply is returned.

https://redis.io/commands/brpoplpush/

func (GroupList) LIndex

func (r GroupList) LIndex(ctx context.Context, key string, index int64) (*gvar.Var, error)

LIndex return the element at index in the list stored at key. Returns the element at index in the list stored at key. The index is zero-based, so 0 means the first element, 1 the second element and so on. Negative indices can be used to designate elements starting at the tail of the list. Here, -1 means the last element, -2 means the penultimate and so forth. When the value at key is not a list, an error is returned.

It returns the requested element, or nil when index is out of range.

https://redis.io/commands/lindex

func (GroupList) LInsert

func (r GroupList) LInsert(ctx context.Context, key string, op gredis.LInsertOp, pivot, value interface{}) (int64, error)

LInsert inserts element in the list stored at key either before or after the reference value pivot. When key does not exist, it is considered an empty list and no operation is performed. An error is returned when key exists but does not hold a list value.

It returns the length of the list after the insert operation, or -1 when the value pivot was not found.

https://redis.io/commands/linsert/

func (GroupList) LLen

func (r GroupList) LLen(ctx context.Context, key string) (int64, error)

LLen returns the length of the list stored at 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. An error is returned when the value stored at key is not a list.

https://redis.io/commands/llen

func (GroupList) LPop

func (r GroupList) LPop(ctx context.Context, key string, count ...int) (*gvar.Var, error)

LPop remove and returns the first element of the list stored at key. Removes and returns the first elements of the list stored at key.

Starting with Redis version 6.2.0: Added the count argument.

By default, the command pops a single element from the beginning of the list. When provided with the optional count argument, the reply will consist of up to count elements, depending on the list's length.

Return When called without the count argument: Bulk string reply: the value of the first element, or nil when key does not exist.

When called with the count argument: Array reply: list of popped elements, or nil when key does not exist.

https://redis.io/commands/lpop

func (GroupList) LPush

func (r GroupList) LPush(ctx context.Context, key string, values ...interface{}) (int64, error)

LPush inserts all the specified values at the head of the list stored at key Insert all the specified values at the head of the list stored at key. If key does not exist, it is created as empty list before performing the push operations. When key holds a value that is not a list, an error is returned.

It returns the length of the list after the push operations.

https://redis.io/commands/lpush/

func (GroupList) LPushX

func (r GroupList) LPushX(ctx context.Context, key string, element interface{}, elements ...interface{}) (int64, error)

LPushX insert value at the head of the list stored at key, only if key exists and holds a list. Inserts specified values at the head of the list stored at key, only if key already exists and holds a list. In contrary to LPush, no operation will be performed when key does not yet exist. Return Integer reply: the length of the list after the push operation.

It returns the length of the list after the push operations.

https://redis.io/commands/lpushx

func (GroupList) LRange

func (r GroupList) LRange(ctx context.Context, key string, start, stop int64) (gvar.Vars, error)

LRange returns the specified elements of the list stored at key. The offsets start and stop are zero-based indexes, with 0 being the first element of the list (the head of the list), 1 being the next element and so on.

These offsets can also be negative numbers indicating offsets starting at the end of the list. For example, -1 is the last element of the list, -2 the penultimate, and so on.

https://redis.io/commands/lrange/

func (GroupList) LRem

func (r GroupList) LRem(ctx context.Context, key string, count int64, value interface{}) (int64, error)

LRem removes the first count occurrences of elements equal to value from the list stored at key.

It returns the number of removed elements.

https://redis.io/commands/lrem/

func (GroupList) LSet

func (r GroupList) LSet(ctx context.Context, key string, index int64, value interface{}) (*gvar.Var, error)

LSet sets the list element at index to element. For more information on the index argument, see LIndex. An error is returned for out of range indexes.

https://redis.io/commands/lset/

func (GroupList) LTrim

func (r GroupList) LTrim(ctx context.Context, key string, start, stop int64) error

LTrim trims an existing list so that it will contain only the specified range of elements specified. Both start and stop are zero-based indexes, where 0 is the first element of the list (the head), 1 the next element and so on.

https://redis.io/commands/ltrim/

func (GroupList) RPop

func (r GroupList) RPop(ctx context.Context, key string, count ...int) (*gvar.Var, error)

RPop remove and returns the last element of the list stored at key. Removes and returns the last elements of the list stored at key.

Starting with Redis version 6.2.0: Added the count argument.

By default, the command pops a single element from the end of the list. When provided with the optional count argument, the reply will consist of up to count elements, depending on the list's length.

It returns:

  • When called without the count argument: the value of the last element, or nil when key does not exist.
  • When called with the count argument: list of popped elements, or nil when key does not exist.

https://redis.io/commands/rpop

func (GroupList) RPopLPush

func (r GroupList) RPopLPush(ctx context.Context, source, destination string) (*gvar.Var, error)

RPopLPush remove the last element in list source, appends it to the front of list destination and returns it.

https://redis.io/commands/rpoplpush/

func (GroupList) RPush

func (r GroupList) RPush(ctx context.Context, key string, values ...interface{}) (int64, error)

RPush inserts all the specified values at the tail of the list stored at key. Insert all the specified values at the tail of the list stored at key. If key does not exist, it is created as empty list before performing the push operation.

When key holds a value that is not a list, an error is returned. It is possible to push multiple elements using a single command call just specifying multiple arguments at the end of the command. Elements are inserted one after the other to the tail of the list, from the leftmost element to the rightmost element. So for instance the command RPush mylist a b c will result into a list containing a as first element, b as second element and c as third element.

It returns the length of the list after the push operation.

https://redis.io/commands/rpush

func (GroupList) RPushX

func (r GroupList) RPushX(ctx context.Context, key string, value interface{}) (int64, error)

RPushX inserts value at the tail of the list stored at key, only if key exists and holds a list. Inserts specified values at the tail of the list stored at key, only if key already exists and holds a list.

In contrary to RPush, no operation will be performed when key does not yet exist.

It returns the length of the list after the push operation.

https://redis.io/commands/rpushx

type GroupPubSub

type GroupPubSub struct {
	Operation gredis.AdapterOperation
}

GroupPubSub provides pub/sub functions for redis.

func (GroupPubSub) PSubscribe

func (r GroupPubSub) PSubscribe(
	ctx context.Context, pattern string, patterns ...string,
) (gredis.Conn, []*gredis.Subscription, error)

PSubscribe subscribes the client to the given patterns.

Supported glob-style patterns: - h?llo subscribes to hello, hallo and hxllo - h*llo subscribes to hllo and heeeello - h[ae]llo subscribes to hello and hallo, but not hillo

Use \ to escape special characters if you want to match them verbatim.

https://redis.io/commands/psubscribe/

func (GroupPubSub) Publish

func (r GroupPubSub) Publish(ctx context.Context, channel string, message interface{}) (int64, error)

Publish posts a message to the given channel.

In a Redis Cluster clients can publish to every node. The cluster makes sure that published messages are forwarded as needed, so clients can subscribe to any channel by connecting to any one of the nodes.

It returns the number of clients that received the message. Note that in a Redis Cluster, only clients that are connected to the same node as the publishing client are included in the count.

https://redis.io/commands/publish/

func (GroupPubSub) Subscribe

func (r GroupPubSub) Subscribe(
	ctx context.Context, channel string, channels ...string,
) (gredis.Conn, []*gredis.Subscription, error)

Subscribe subscribes the client to the specified channels.

https://redis.io/commands/subscribe/

type GroupScript

type GroupScript struct {
	Operation gredis.AdapterOperation
}

GroupScript provides script functions for redis.

func (GroupScript) Eval

func (r GroupScript) Eval(ctx context.Context, script string, numKeys int64, keys []string, args []interface{}) (*gvar.Var, error)

Eval invokes the execution of a server-side Lua script.

https://redis.io/commands/eval/

func (GroupScript) EvalSha

func (r GroupScript) EvalSha(ctx context.Context, sha1 string, numKeys int64, keys []string, args []interface{}) (*gvar.Var, error)

EvalSha evaluates a script from the server's cache by its SHA1 digest.

The server caches scripts by using the SCRIPT LOAD command. The command is otherwise identical to EVAL.

https://redis.io/commands/evalsha/

func (GroupScript) ScriptExists

func (r GroupScript) ScriptExists(ctx context.Context, sha1 string, sha1s ...string) (map[string]bool, error)

ScriptExists returns information about the existence of the scripts in the script cache.

It returns an array of integers that correspond to the specified SHA1 digest arguments. For every corresponding SHA1 digest of a script that actually exists in the script cache, a 1 is returned, otherwise 0 is returned.

https://redis.io/commands/script-exists/

func (GroupScript) ScriptFlush

func (r GroupScript) ScriptFlush(ctx context.Context, option ...gredis.ScriptFlushOption) error

ScriptFlush flush the Lua scripts cache.

https://redis.io/commands/script-flush/

func (GroupScript) ScriptKill

func (r GroupScript) ScriptKill(ctx context.Context) error

ScriptKill kills the currently executing EVAL script, assuming no write operation was yet performed by the script.

https://redis.io/commands/script-kill/

func (GroupScript) ScriptLoad

func (r GroupScript) ScriptLoad(ctx context.Context, script string) (string, error)

ScriptLoad loads a script into the scripts cache, without executing it.

It returns the SHA1 digest of the script added into the script cache.

https://redis.io/commands/script-load/

type GroupSet

type GroupSet struct {
	Operation gredis.AdapterOperation
}

GroupSet provides set functions for redis.

func (GroupSet) SAdd

func (r GroupSet) SAdd(ctx context.Context, key string, member interface{}, members ...interface{}) (int64, error)

SAdd adds 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 members.

An error is returned when the value stored at key is not a set.

It returns the number of elements that were added to the set, not including all the elements already present in the set.

https://redis.io/commands/sadd/

func (GroupSet) SCard

func (r GroupSet) SCard(ctx context.Context, key string) (int64, error)

SCard returns the set cardinality (number of elements) of the set stored at key.

It returns the cardinality (number of elements) of the set, or 0 if key does not exist.

https://redis.io/commands/scard/

func (GroupSet) SDiff

func (r GroupSet) SDiff(ctx context.Context, key string, keys ...string) (gvar.Vars, error)

SDiff returns the members of the set resulting from the difference between the first set and all the successive sets.

It returns list with members of the resulting set.

https://redis.io/commands/sdiff/

func (GroupSet) SDiffStore

func (r GroupSet) SDiffStore(ctx context.Context, destination string, key string, keys ...string) (int64, error)

SDiffStore is equal to SDiff, but instead of returning the resulting set, it is stored in destination.

If destination already exists, it is overwritten.

It returns the number of elements in the resulting set.

https://redis.io/commands/sdiffstore/

func (GroupSet) SInter

func (r GroupSet) SInter(ctx context.Context, key string, keys ...string) (gvar.Vars, error)

SInter returns the members of the set resulting from the intersection of all the given sets.

It returns list with members of the resulting set.

https://redis.io/commands/sinter/

func (GroupSet) SInterStore

func (r GroupSet) SInterStore(ctx context.Context, destination string, key string, keys ...string) (int64, error)

SInterStore is equal to SInter, but instead of returning the resulting set, it is stored in destination.

If destination already exists, it is overwritten.

It returns the number of elements in the resulting set.

https://redis.io/commands/sinterstore/

func (GroupSet) SIsMember

func (r GroupSet) SIsMember(ctx context.Context, key string, member interface{}) (int64, error)

SIsMember returns if member is a member of the set stored at key.

It returns: - 1 if the element is a member of the set. - 0 if the element is not a member of the set, or if key does not exist.

https://redis.io/commands/sismember/

func (GroupSet) SMIsMember

func (r GroupSet) SMIsMember(ctx context.Context, key, member interface{}, members ...interface{}) ([]int, error)

SMIsMember returns whether each member is a member of the set stored at key.

For every member, 1 is returned if the value is a member of the set, or 0 if the element is not a member of the set or if key does not exist.

It returns list representing the membership of the given elements, in the same order as they are requested.

https://redis.io/commands/smismember/

func (GroupSet) SMembers

func (r GroupSet) SMembers(ctx context.Context, key string) (gvar.Vars, error)

SMembers returns all the members of the set value stored at key. This has the same effect as running SINTER with one argument key.

It returns all elements of the set.

https://redis.io/commands/smembers/

func (GroupSet) SMove

func (r GroupSet) SMove(ctx context.Context, source, destination string, member interface{}) (int64, error)

SMove moves 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. If the source set does not exist or does not contain the specified element, no operation is performed and 0 is returned. Otherwise, the element is removed from the source set and added to the destination set. When the specified element already exists in the destination set, it is only removed from the source set.

An error is returned if source or destination does not hold a set value.

It returns: - 1 if the element is moved. - 0 if the element is not a member of source and no operation was performed.

https://redis.io/commands/smove/

func (GroupSet) SPop

func (r GroupSet) SPop(ctx context.Context, key string, count ...int) (*gvar.Var, error)

SPop removes and returns one or more random members from the set value store at key.

This operation is similar to SRandMember, that returns one or more random elements from a set but does not remove it. By default, the command pops a single member from the set. When provided with the optional count argument, the reply will consist of up to count members, depending on the set's cardinality.

It returns:

  • When called without the count argument: Bulk string reply: the removed member, or nil when key does not exist.
  • When called with the count argument: Array reply: the removed members, or an empty array when key does not exist.

https://redis.io/commands/spop/

func (GroupSet) SRandMember

func (r GroupSet) SRandMember(ctx context.Context, key string, count ...int) (*gvar.Var, error)

SRandMember called with just the key argument, return a random element from the set value stored at key. If the provided count argument is positive, return an array of distinct elements. The array's length is either count or the set's cardinality (SCard), whichever is lower. If called with a negative count, the behavior changes and the command is allowed to return the same element multiple times. In this case, the number of returned elements is the absolute value of the specified count.

It returns:

  • Bulk string reply: without the additional count argument, the command returns a Bulk Reply with the randomly selected element, or nil when key does not exist.
  • Array reply: when the additional count argument is passed, the command returns an array of elements, or an empty array when key does not exist.

https://redis.io/commands/srandmember/

func (GroupSet) SRem

func (r GroupSet) SRem(ctx context.Context, key string, member interface{}, members ...interface{}) (int64, error)

SRem removes the specified members from the set stored at key. Specified members that are not a member of this set are ignored. If key does not exist, it is treated as an empty set and this command returns 0.

An error is returned when the value stored at key is not a set.

It returns the number of members that were removed from the set, not including non existing members.

https://redis.io/commands/srem/

func (GroupSet) SUnion

func (r GroupSet) SUnion(ctx context.Context, key string, keys ...string) (gvar.Vars, error)

SUnion returns the members of the set resulting from the union of all the given sets.

It returns list with members of the resulting set.

https://redis.io/commands/sunion/

func (GroupSet) SUnionStore

func (r GroupSet) SUnionStore(ctx context.Context, destination, key string, keys ...string) (int64, error)

SUnionStore is equal to SUnion, but instead of returning the resulting set, it is stored in destination.

If destination already exists, it is overwritten.

It returns the number of elements in the resulting set.

https://redis.io/commands/sunionstore/

type GroupSortedSet

type GroupSortedSet struct {
	Operation gredis.AdapterOperation
}

GroupSortedSet provides sorted set functions for redis.

func (GroupSortedSet) ZAdd

func (r GroupSortedSet) ZAdd(
	ctx context.Context, key string, option *gredis.ZAddOption, member gredis.ZAddMember, members ...gredis.ZAddMember,
) (*gvar.Var, error)

ZAdd adds all the specified members with the specified scores to the sorted set stored at key. It is possible to specify multiple score / member pairs. If a specified member is already a member of the sorted set, the score is updated and the element reinserted at the right position to ensure the correct ordering.

If key does not exist, a new sorted set with the specified members as sole members is created, like if the sorted set was empty. If the key exists but does not hold a sorted set, an error is returned.

The score values should be the string representation of a double precision floating point number. +inf and -inf values are valid values as well.

It returns: - When used without optional arguments, the number of elements added to the sorted set (excluding score updates). - If the CH option is specified, the number of elements that were changed (added or updated).

If the INCR option is specified, the return value will be Bulk string reply:

  • The new score of member (a double precision floating point number) represented as string, or nil if the operation was aborted (when called with either the XX or the NX option).

https://redis.io/commands/zadd/

func (GroupSortedSet) ZCard

func (r GroupSortedSet) ZCard(ctx context.Context, key string) (int64, error)

ZCard returns the sorted set cardinality (number of elements) of the sorted set stored at key.

It returns the cardinality (number of elements) of the sorted set, or 0 if key does not exist.

https://redis.io/commands/zcard/

func (GroupSortedSet) ZCount

func (r GroupSortedSet) ZCount(ctx context.Context, key string, min, max string) (int64, error)

ZCount returns the number of elements in the sorted set at key with a score between min and max.

The min and max arguments have the same semantic as described for ZRangeByScore.

Note: the command has a complexity of just O(log(N)) because it uses elements ranks (see ZRANK) to get an idea of the range. Because of this there is no need to do a work proportional to the size of the range.

It returns the number of elements in the specified score range.

https://redis.io/commands/zcount/

func (GroupSortedSet) ZIncrBy

func (r GroupSortedSet) ZIncrBy(ctx context.Context, key string, increment float64, member interface{}) (float64, error)

ZIncrBy increments the score of member in the sorted set stored at key by increment. If member does not exist in the sorted set, it is added with increment as its score (as if its previous score was 0.0). If key does not exist, a new sorted set with the specified member as its sole member is created.

An error is returned when key exists but does not hold a sorted set.

The score value should be the string representation of a numeric value, and accepts double precision floating point numbers. It is possible to provide a negative value to decrement the score.

It returns the new score of member (a double precision floating point number).

https://redis.io/commands/zincrby/

func (GroupSortedSet) ZLexCount

func (r GroupSortedSet) ZLexCount(ctx context.Context, key, min, max string) (int64, error)

ZLexCount all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command returns the number of elements in the sorted set at key with a value between min and max.

The min and max arguments have the same meaning as described for ZRangeByLex.

Note: the command has a complexity of just O(log(N)) because it uses elements ranks (see ZRank) to get an idea of the range. Because of this there is no need to do a work proportional to the size of the range.

It returns the number of elements in the specified score range.

https://redis.io/commands/zlexcount/

func (GroupSortedSet) ZRange

func (r GroupSortedSet) ZRange(ctx context.Context, key string, start, stop int64, option ...gredis.ZRangeOption) (gvar.Vars, error)

ZRange return the specified range of elements in the sorted set stored at <key>.

ZRange can perform different types of range queries: by index (rank), by the score, or by lexicographical order.

https://redis.io/commands/zrange/

func (GroupSortedSet) ZRank

func (r GroupSortedSet) ZRank(ctx context.Context, key string, member interface{}) (int64, error)

ZRank returns the rank of member in the sorted set stored at key, with the scores ordered from low to high. The rank (or index) is 0-based, which means that the member with the lowest score has rank 0.

Use ZRevRank to get the rank of an element with the scores ordered from high to low.

It returns: - If member exists in the sorted set, Integer reply: the rank of member. - If member does not exist in the sorted set or key does not exist, Bulk string reply: nil.

https://redis.io/commands/zrank/

func (GroupSortedSet) ZRem

func (r GroupSortedSet) ZRem(ctx context.Context, key string, member interface{}, members ...interface{}) (int64, error)

ZRem remove the specified members from the sorted set stored at key. Non-existing members are ignored.

An error is returned when key exists and does not hold a sorted set.

It returns the number of members removed from the sorted set, not including non existing members.

https://redis.io/commands/zrem/

func (GroupSortedSet) ZRemRangeByLex

func (r GroupSortedSet) ZRemRangeByLex(ctx context.Context, key string, min, max string) (int64, error)

ZRemRangeByLex removes all elements in the sorted set stored at key between the lexicographical range specified by min and max.

The meaning of min and max are the same of the ZRangeByLex command. Similarly, this command actually removes the same elements that ZRangeByLex would return if called with the same min and max arguments.

It returns the number of elements removed.

https://redis.io/commands/zremrangebylex/

func (GroupSortedSet) ZRemRangeByRank

func (r GroupSortedSet) ZRemRangeByRank(ctx context.Context, key string, start, stop int64) (int64, error)

ZRemRangeByRank removes all elements in the sorted set stored at key with rank between start and stop. Both start and stop are 0 -based indexes with 0 being the element with the lowest score.

These indexes can be negative numbers, where they indicate offsets starting at the element with the highest score. For example: -1 is the element with the highest score, -2 the element with the second-highest score and so forth.

It returns the number of elements removed.

https://redis.io/commands/zremrangebyrank/

func (GroupSortedSet) ZRemRangeByScore

func (r GroupSortedSet) ZRemRangeByScore(ctx context.Context, key string, min, max string) (int64, error)

ZRemRangeByScore removes all elements in the sorted set stored at key with a score between min and max (inclusive).

It returns the number of elements removed.

https://redis.io/commands/zremrangebyscore/

func (GroupSortedSet) ZRevRange

func (r GroupSortedSet) ZRevRange(ctx context.Context, key string, start, stop int64, option ...gredis.ZRevRangeOption) (*gvar.Var, error)

ZRevRange returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the highest to the lowest score. Descending lexicographical order is used for elements with equal score.

Apart from the reversed ordering, ZRevRange is similar to ZRange.

It returns list of elements in the specified range (optionally with their scores).

https://redis.io/commands/zrevrange/

func (GroupSortedSet) ZRevRank

func (r GroupSortedSet) ZRevRank(ctx context.Context, key string, member interface{}) (int64, error)

ZRevRank returns the rank of member in the sorted set stored at key, with the scores ordered from high to low. The rank (or index) is 0-based, which means that the member with the highest score has rank 0.

Use ZRank to get the rank of an element with the scores ordered from low to high.

It returns: - If member exists in the sorted set, Integer reply: the rank of member. - If member does not exist in the sorted set or key does not exist, Bulk string reply: nil.

https://redis.io/commands/zrevrank/

func (GroupSortedSet) ZScore

func (r GroupSortedSet) ZScore(ctx context.Context, key string, member interface{}) (float64, error)

ZScore Returns the score of member in the sorted set at key.

If member does not exist in the sorted set, or key does not exist, nil is returned.

It returns the score of member (a double precision floating point number), represented as string.

https://redis.io/commands/zscore/

type GroupString

type GroupString struct {
	Operation gredis.AdapterOperation
}

GroupString is the function group manager for string operations.

func (GroupString) Append

func (r GroupString) Append(ctx context.Context, key string, value string) (int64, error)

Append appends the value at the end of the string, if key already exists and is a string. If key does not exist it is created and set as an empty string, so APPEND will be similar to SET in this special case.

https://redis.io/commands/append/

func (GroupString) Decr

func (r GroupString) Decr(ctx context.Context, key string) (int64, error)

Decr decrements the number stored at key by one.

https://redis.io/commands/decr/

func (GroupString) DecrBy

func (r GroupString) DecrBy(ctx context.Context, key string, decrement int64) (int64, error)

DecrBy decrements the number stored at key by decrement.

https://redis.io/commands/decrby/

func (GroupString) Get

func (r GroupString) Get(ctx context.Context, key string) (*gvar.Var, error)

Get the value of key. If the key does not exist the special value nil is returned. An error is returned if the value stored at key is not a string, because GET only handles string values.

https://redis.io/commands/get/

func (GroupString) GetDel

func (r GroupString) GetDel(ctx context.Context, key string) (*gvar.Var, error)

GetDel gets the value of key and delete the key. This command is similar to GET, except for the fact that it also deletes the key on success (if and only if the key's value type is a string).

https://redis.io/commands/getdel/

func (GroupString) GetEX

func (r GroupString) GetEX(ctx context.Context, key string, option ...gredis.GetEXOption) (*gvar.Var, error)

GetEX is similar to GET, but is a write command with additional options.

https://redis.io/commands/getex/

func (GroupString) GetRange

func (r GroupString) GetRange(ctx context.Context, key string, start, end int64) (string, error)

GetRange returns the substring of the string value stored at key, determined by the offsets start and end (both are inclusive). Negative offsets can be used in order to provide an offset starting from the end of the string. So -1 means the last character, -2 the penultimate and so forth.

The function handles out of range requests by limiting the resulting range to the actual length of the string.

https://redis.io/commands/getrange/

func (GroupString) GetSet

func (r GroupString) GetSet(ctx context.Context, key string, value interface{}) (*gvar.Var, error)

GetSet atomically sets key to value and returns the old value stored at key. Returns an error when key exists but does not hold a string value. Any previous time to live associated with the key is discarded on successful SET operation.

https://redis.io/commands/getset/

func (GroupString) Incr

func (r GroupString) Incr(ctx context.Context, key string) (int64, error)

Incr increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. This operation is limited to 64 bits signed integers.

https://redis.io/commands/incr/

func (GroupString) IncrBy

func (r GroupString) IncrBy(ctx context.Context, key string, increment int64) (int64, error)

IncrBy increments the number stored at key by increment. If the key does not exist, it is set to 0 before performing the operation.

An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. This operation is limited to 64 bits signed integers.

https://redis.io/commands/incrby/

func (GroupString) IncrByFloat

func (r GroupString) IncrByFloat(ctx context.Context, key string, increment float64) (float64, error)

IncrByFloat increments the string representing a floating point number stored at key by the specified increment.

https://redis.io/commands/incrbyfloat/

func (GroupString) MGet

func (r GroupString) MGet(ctx context.Context, keys ...string) (map[string]*gvar.Var, error)

MGet returns the values of all specified keys.

https://redis.io/commands/mget/

func (GroupString) MSet

func (r GroupString) MSet(ctx context.Context, keyValueMap map[string]interface{}) error

MSet sets the given keys to their respective values. MSet replaces existing values with new values, just as regular SET. See MSetNX if you don't want to overwrite existing values.

MSet is atomic, so all given keys are set at once. It is not possible for clients to see that some keys were updated while others are unchanged.

https://redis.io/commands/mset/

func (GroupString) MSetNX

func (r GroupString) MSetNX(ctx context.Context, keyValueMap map[string]interface{}) (bool, error)

MSetNX sets the given keys to their respective values.

It returns: true: if the all the keys were set. false: if no key was set (at least one key already existed).

func (GroupString) Set

func (r GroupString) Set(ctx context.Context, key string, value interface{}, option ...gredis.SetOption) (*gvar.Var, error)

Set key to hold the string value. If key already holds a value, it is overwritten, regardless of its type. Any previous time to live associated with the key is discarded on successful SET operation.

https://redis.io/commands/set/

func (GroupString) SetEX

func (r GroupString) SetEX(ctx context.Context, key string, value interface{}, ttlInSeconds int64) error

SetEX sets key to hold the string value and set key to timeout after a given number of seconds. This command is equivalent to executing the following commands:

SET myKey value
EXPIRE myKey seconds

SetEX is atomic, and can be reproduced by using the previous two commands inside an MULTI / EXEC block. It is provided as a faster alternative to the given sequence of operations, because this operation is very common when Redis is used as a cache.

An error is returned when seconds invalid.

https://redis.io/commands/setex/

func (GroupString) SetNX

func (r GroupString) SetNX(ctx context.Context, key string, value interface{}) (bool, error)

SetNX sets key to hold string value if key does not exist. In that case, it is equal to SET. When key already holds a value, no operation is performed. SetNX is short for "SET if Not exists".

It returns: true: if the all the keys were set. false: if no key was set (at least one key already existed).

https://redis.io/commands/setnx/

func (GroupString) SetRange

func (r GroupString) SetRange(ctx context.Context, key string, offset int64, value string) (int64, error)

SetRange overwrites part of the string stored at key, starting at the specified offset, for the entire length of value. If the offset is larger than the current length of the string at key, the string is padded with zero-bytes to make offset fit. Non-existing keys are considered as empty strings, so this command will make sure it holds a string large enough to be able to set value at offset.

It returns the length of the string after it was modified by the command.

https://redis.io/commands/setrange/

func (GroupString) StrLen

func (r GroupString) StrLen(ctx context.Context, key string) (int64, error)

StrLen returns the length of the string value stored at key. An error is returned when key holds a non-string value.

It returns the length of the string at key, or 0 when key does not exist.

https://redis.io/commands/strlen/

type Redis

type Redis struct {
	gredis.AdapterOperation
	// contains filtered or unexported fields
}

Redis is an implement of Adapter using go-redis.

func New

func New(config *gredis.Config) *Redis

New creates and returns a redis adapter using go-redis.

func (*Redis) Close

func (r *Redis) Close(ctx context.Context) (err error)

Close closes the redis connection pool, which will release all connections reserved by this pool. It is commonly not necessary to call Close manually.

func (*Redis) Conn

func (r *Redis) Conn(ctx context.Context) (gredis.Conn, error)

Conn retrieves and returns a connection object for continuous operations. Note that you should call Close function manually if you do not use this connection any further.

func (*Redis) Do

func (r *Redis) Do(ctx context.Context, command string, args ...interface{}) (*gvar.Var, error)

Do send a command to the server and returns the received reply. It uses json.Marshal for struct/slice/map type values before committing them to redis.

func (*Redis) GroupGeneric

func (r *Redis) GroupGeneric() gredis.IGroupGeneric

GroupGeneric creates and returns GroupGeneric.

func (*Redis) GroupHash

func (r *Redis) GroupHash() gredis.IGroupHash

GroupHash creates and returns a redis group object for hash operations.

func (*Redis) GroupList

func (r *Redis) GroupList() gredis.IGroupList

GroupList creates and returns a redis group object for list operations.

func (*Redis) GroupPubSub

func (r *Redis) GroupPubSub() gredis.IGroupPubSub

GroupPubSub creates and returns GroupPubSub.

func (*Redis) GroupScript

func (r *Redis) GroupScript() gredis.IGroupScript

GroupScript creates and returns GroupScript.

func (*Redis) GroupSet

func (r *Redis) GroupSet() gredis.IGroupSet

GroupSet creates and returns GroupSet.

func (*Redis) GroupSortedSet

func (r *Redis) GroupSortedSet() gredis.IGroupSortedSet

GroupSortedSet creates and returns GroupSortedSet.

func (*Redis) GroupString

func (r *Redis) GroupString() gredis.IGroupString

GroupString is the redis group object for string operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL