Documentation ¶
Index ¶
- Variables
- type RedisConf
- type RedisSession
- func (r *RedisSession) AddPrefix(name string) string
- func (r *RedisSession) AddSetMembers(key string, rest ...interface{}) (int, error)
- func (r *RedisSession) Bool(reply interface{}) (bool, error)
- func (r *RedisSession) Close() error
- func (r *RedisSession) CreatePubSubConn() *redis.PubSubConn
- func (r *RedisSession) Decr(key string) (int, error)
- func (r *RedisSession) Del(args ...interface{}) (int, error)
- func (r *RedisSession) DeleteHashSetField(key string, rest ...interface{}) (int, error)
- func (r *RedisSession) Do(cmd string, args ...interface{}) (interface{}, error)
- func (r *RedisSession) Exists(key string) bool
- func (r *RedisSession) Expire(key string, timeout time.Duration) error
- func (r *RedisSession) Get(key string) (string, error)
- func (r *RedisSession) GetHashLength(key string) (int, error)
- func (r *RedisSession) GetHashMultipleSet(key string, rest ...interface{}) ([]interface{}, error)
- func (r *RedisSession) GetHashSetField(key string, field string) (string, error)
- func (r *RedisSession) GetInt(key string) (int, error)
- func (r *RedisSession) GetSetMembers(key string) ([]interface{}, error)
- func (r *RedisSession) HashGetAll(key string) ([]interface{}, error)
- func (r *RedisSession) HashMultipleSet(key string, item map[string]interface{}) error
- func (r *RedisSession) HashSet(key, member string, value interface{}) (int, error)
- func (r *RedisSession) HashSetIfNotExists(key, field string, item interface{}) (bool, error)
- func (r *RedisSession) Incr(key string) (int, error)
- func (r *RedisSession) IncrBy(key string, by int64) (int64, error)
- func (r *RedisSession) Int(reply interface{}) (int, error)
- func (r *RedisSession) Int64(reply interface{}) (int64, error)
- func (r *RedisSession) IsSetMember(key string, value string) (int, error)
- func (r *RedisSession) Keys(key string) ([]interface{}, error)
- func (r *RedisSession) MoveSetMember(source, destination, member string) (int, error)
- func (r *RedisSession) Ping() error
- func (r *RedisSession) Pool() *redis.Pool
- func (r *RedisSession) PopSetMember(key string) (string, error)
- func (r *RedisSession) RandomSetMember(key string) (string, error)
- func (r *RedisSession) RemoveSetMembers(key string, rest ...interface{}) (int, error)
- func (r *RedisSession) Scard(key string) (int, error)
- func (r *RedisSession) Send(cmd string, args ...interface{}) error
- func (r *RedisSession) Set(key, value string) error
- func (r *RedisSession) SetPrefix(name string)
- func (r *RedisSession) Setex(key string, timeout time.Duration, item interface{}) error
- func (r *RedisSession) SortBy(key, sortBy, order string) ([]interface{}, error)
- func (r *RedisSession) SortedSetAddSingle(key, member string, score interface{}) error
- func (r *RedisSession) SortedSetIncrBy(key string, incrBy, item interface{}) (float64, error)
- func (r *RedisSession) SortedSetRangebyScore(key string, rest ...interface{}) ([]interface{}, error)
- func (r *RedisSession) SortedSetRem(key string, members ...interface{}) (int64, error)
- func (r *RedisSession) SortedSetReverseRange(key string, rest ...interface{}) ([]interface{}, error)
- func (r *RedisSession) SortedSetScore(key string, member interface{}) (float64, error)
- func (r *RedisSession) SortedSetsUnion(destination string, keys []string, weights []interface{}, aggregate string) (int64, error)
- func (r *RedisSession) String(reply interface{}) (string, error)
- func (r *RedisSession) TTL(key string) (time.Duration, error)
- func (r *RedisSession) Values(reply interface{}) ([]interface{}, error)
- type SingletonSession
Constants ¶
This section is empty.
Variables ¶
var ( ErrNil = redis.ErrNil ErrTTLNotSet = errors.New("ttl is not set") ErrKeyNotExist = errors.New("key does not exist") ErrDestinationNotSet = errors.New("destination is not set") ErrKeysNotSet = errors.New("keys are not set") )
var ( NegativeInf = "-inf" PositiveInf = "+inf" )
Functions ¶
This section is empty.
Types ¶
type RedisSession ¶
type RedisSession struct {
// contains filtered or unexported fields
}
RedisSession holds the internal redis pool and the prefix for command/key namespacing among diff services/workers.
func NewRedisSession ¶
func NewRedisSession(conf *RedisConf, options ...redis.DialOption) (*RedisSession, error)
NewRedisSession creates a new Redis Pool with optional Redis Dial configurations.
func (*RedisSession) AddPrefix ¶
func (r *RedisSession) AddPrefix(name string) string
func (*RedisSession) AddSetMembers ¶
func (r *RedisSession) AddSetMembers(key string, rest ...interface{}) (int, error)
AddSetMembers adds given elements to the set stored at key. Given elements that are already included in set are ignored. Returns successfully added key count and error state
func (*RedisSession) Bool ¶
func (r *RedisSession) Bool(reply interface{}) (bool, error)
Bool converts the given value to boolean
func (*RedisSession) Close ¶
func (r *RedisSession) Close() error
Close closes the connection pool for redis
func (*RedisSession) CreatePubSubConn ¶
func (r *RedisSession) CreatePubSubConn() *redis.PubSubConn
CreatePubSubConn wraps a Conn with convenience methods for subscribers.
func (*RedisSession) Decr ¶
func (r *RedisSession) Decr(key string) (int, error)
Decr decrements 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
func (*RedisSession) Del ¶
func (r *RedisSession) Del(args ...interface{}) (int, error)
Del is used to remove the specified keys. Key is ignored if it does not exist. It returns the number of keys that were removed. Example usage: redis.Del("counter", "arslan:name")
func (*RedisSession) DeleteHashSetField ¶
func (r *RedisSession) DeleteHashSetField(key string, rest ...interface{}) (int, error)
DeleteHashSetField deletes a given field from hash set and returns number of deleted fields count
func (*RedisSession) Do ¶
func (r *RedisSession) Do(cmd string, args ...interface{}) (interface{}, error)
Do is a wrapper around redigo's redis.Do method that executes any redis command. Do does not support prefix support. Example usage: redis.Do("INCR", "counter").
func (*RedisSession) Exists ¶
func (r *RedisSession) Exists(key string) bool
Exists returns true if key exists or false if not.
func (*RedisSession) Expire ¶
func (r *RedisSession) Expire(key string, timeout time.Duration) error
Expire sets a timeout on a key. After the timeout has expired, the key will automatically be deleted. Calling Expire on a key that has already expire set will update the expire value.
func (*RedisSession) Get ¶
func (r *RedisSession) Get(key string) (string, error)
Get is used to get the value of key. If the key does not exist an empty string is returned. Usage: redis.Get("arslan")
func (*RedisSession) GetHashLength ¶
func (r *RedisSession) GetHashLength(key string) (int, error)
GetHashLength returns the item count of a hash set.
func (*RedisSession) GetHashMultipleSet ¶
func (r *RedisSession) GetHashMultipleSet(key string, rest ...interface{}) ([]interface{}, error)
GetHashMultipleSet returns values of the hashset at stored key with requested field order Usage: GetHashMultipleSet("canthefason", "name", "age", "birthDate")
func (*RedisSession) GetHashSetField ¶
func (r *RedisSession) GetHashSetField(key string, field string) (string, error)
GetHashSetField returns value of the given field of the hash set
func (*RedisSession) GetInt ¶
func (r *RedisSession) GetInt(key string) (int, error)
GetInt is used the value of key as an integer. If the key does not exist or the stored value is a non-integer, zero is returned. Example usage: redis.GetInt("counter")
func (*RedisSession) GetSetMembers ¶
func (r *RedisSession) GetSetMembers(key string) ([]interface{}, error)
GetSetMembers returns all members included in the set at key Returns members array and error state
func (*RedisSession) HashGetAll ¶
func (r *RedisSession) HashGetAll(key string) ([]interface{}, error)
HashGetAll returns all of the fields of a hash value Usage: HashGetAll(key)
func (*RedisSession) HashMultipleSet ¶
func (r *RedisSession) HashMultipleSet(key string, item map[string]interface{}) error
HashMultipleSet sets multiple hashset elements stored at key with given field values. Returns error state of this operation
func (*RedisSession) HashSet ¶
func (r *RedisSession) HashSet(key, member string, value interface{}) (int, error)
HashSet sets a single element at key with given field and value. Returns error state of this operation
func (*RedisSession) HashSetIfNotExists ¶
func (r *RedisSession) HashSetIfNotExists(key, field string, item interface{}) (bool, error)
HashSetIfNotExists adds the item to given field, when the field does not exist. Returns the result of set operation
func (*RedisSession) Incr ¶
func (r *RedisSession) Incr(key string) (int, 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
func (*RedisSession) IncrBy ¶
func (r *RedisSession) IncrBy(key string, by int64) (int64, error)
Incrby increments the number stored at key by given number. 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
func (*RedisSession) Int ¶
func (r *RedisSession) Int(reply interface{}) (int, error)
Int converts the given value to integer
func (*RedisSession) Int64 ¶
func (r *RedisSession) Int64(reply interface{}) (int64, error)
Int64 converts the given value to 64 bit integer
func (*RedisSession) IsSetMember ¶
func (r *RedisSession) IsSetMember(key string, value string) (int, error)
IsSetMember checks existence of a member set
func (*RedisSession) Keys ¶
func (r *RedisSession) Keys(key string) ([]interface{}, error)
Keys returns all keys with given pattern WARNING: Redis Doc says: "Don't use KEYS in your regular application code."
func (*RedisSession) MoveSetMember ¶
func (r *RedisSession) MoveSetMember(source, destination, member string) (int, error)
SetMoveMember 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.
func (*RedisSession) Ping ¶
func (r *RedisSession) Ping() error
Ping pings the redis server to check if it is alive or not If the server is not alive will return a proper error
func (*RedisSession) Pool ¶
func (r *RedisSession) Pool() *redis.Pool
Pool Returns the connection pool for redis
func (*RedisSession) PopSetMember ¶
func (r *RedisSession) PopSetMember(key string) (string, error)
PopSetMember removes and returns a random element from the set stored at key
func (*RedisSession) RandomSetMember ¶
func (r *RedisSession) RandomSetMember(key string) (string, error)
RandomSetMember returns random from set, but not removes unline PopSetMember
func (*RedisSession) RemoveSetMembers ¶
func (r *RedisSession) RemoveSetMembers(key string, rest ...interface{}) (int, error)
RemoveSetMembers removes given elements from the set stored at key Returns successfully removed key count and error state
func (*RedisSession) Scard ¶
func (r *RedisSession) Scard(key string) (int, error)
Scard gets the member count of a Set with given key
func (*RedisSession) Send ¶
func (r *RedisSession) Send(cmd string, args ...interface{}) error
Send is a wrapper around redigo's redis.Send method that writes the command to the client's output buffer.
func (*RedisSession) Set ¶
func (r *RedisSession) Set(key, value string) error
Set is used to hold the string value. If key already holds a value, it is overwritten, regardless of its type. A return of nil means successfull. Example usage: redis.Set("arslan:name", "fatih")
func (*RedisSession) SetPrefix ¶
func (r *RedisSession) SetPrefix(name string)
SetPrefix is used to add a prefix to all keys to be used. It is useful for creating namespaces for each different application
func (*RedisSession) Setex ¶
func (r *RedisSession) Setex(key string, timeout time.Duration, item interface{}) error
Set 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 is invalid.
func (*RedisSession) SortBy ¶
func (r *RedisSession) SortBy(key, sortBy, order string) ([]interface{}, error)
SortBy sorts elements stored at key with given weight and order(ASC|DESC)
i.e. Suppose we have elements stored at key as object_1, object_2 and object_3 and their weight is relatively stored at object_1:weight, object_2:weight, object_3:weight When we give sortBy parameter as *:weight, it gets all weight values and sorts the objects at given key with specified order.
func (*RedisSession) SortedSetAddSingle ¶
func (r *RedisSession) SortedSetAddSingle(key, member string, score interface{}) error
SortedSetAdds adds updates the element score, and as a side effect, its position on the sorted set.
func (*RedisSession) SortedSetIncrBy ¶
func (r *RedisSession) SortedSetIncrBy(key string, incrBy, item interface{}) (float64, error)
SortedSetIncrBy increments the value of a member in a sorted set
This function tries to return last floating value of the item, if it fails to parse reply to float64, returns parsing error along with Reply it self
func (*RedisSession) SortedSetRangebyScore ¶
func (r *RedisSession) SortedSetRangebyScore(key string, rest ...interface{}) ([]interface{}, error)
SortedSetRangebyScore key min max returns all the elements in the sorted set at key with a score between min and max.
func (*RedisSession) SortedSetRem ¶
func (r *RedisSession) SortedSetRem(key string, members ...interface{}) (int64, error)
SortedSetRem removes a member from a sorted set. If no member, an error is returned.
func (*RedisSession) SortedSetReverseRange ¶
func (r *RedisSession) SortedSetReverseRange(key string, rest ...interface{}) ([]interface{}, error)
ZREVRANGE key start stop [WITHSCORES] 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.
func (*RedisSession) SortedSetScore ¶
func (r *RedisSession) SortedSetScore(key string, member interface{}) (float64, error)
SortedSetScore returns score of a member in a sorted set. If no member, an error is returned.
func (*RedisSession) SortedSetsUnion ¶
func (r *RedisSession) SortedSetsUnion(destination string, keys []string, weights []interface{}, aggregate string) (int64, error)
SortedSetsUnion creates a combined set from given list of sorted set keys.
func (*RedisSession) String ¶
func (r *RedisSession) String(reply interface{}) (string, error)
String converts the given value to string
func (*RedisSession) TTL ¶
func (r *RedisSession) TTL(key string) (time.Duration, error)
TTL returns remaining TTL value of the given key. An error is returned when TTL is not existed or key is not found
func (*RedisSession) Values ¶
func (r *RedisSession) Values(reply interface{}) ([]interface{}, error)
Values is a helper that converts an array command reply to a []interface{}. If err is not equal to nil, then Values returns nil, err. Otherwise, Values converts the reply as follows: Reply type Result array reply, nil nil nil, ErrNil other nil, error
type SingletonSession ¶
type SingletonSession struct { Session *RedisSession Err error // contains filtered or unexported fields }
SingletonSession handles connection pool for Redis
func (*SingletonSession) Close ¶
func (r *SingletonSession) Close()
Close clears the connection to redis
func (*SingletonSession) Connect ¶
func (r *SingletonSession) Connect() (*RedisSession, error)
Connect connects to Redis and holds the Session and Err object in the SingletonSession struct