redis

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BIT

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

BIT defines redis BIT operations

func (*BIT) BitCount

func (b *BIT) BitCount(key string, offsetFrom int64, offsetTo int64) (valCount int64, err error)

BitCount counts the number of set bits (population counting of bits that are 1) in a string,

offsetFrom = evaluate bitcount begin at offsetFrom position offsetTo = evaluate bitcount until offsetTo position

func (*BIT) BitField

func (b *BIT) BitField(key string, args ...interface{}) (valBits []int64, err error)

BitField treats redis string as array of bits See detail at https://redis.io/commands/bitfield

Supported Sub Commands:

GET <type> <offset> -- returns the specified bit field
SET <type> <offset> <value> -- sets the specified bit field and returns its old value
INCRBY <type> <offset> <increment> -- increments or decrements (if negative) the specified bit field and returns the new value

Notes:

i = if integer type, i can be preceeded to indicate signed integer, such as i5 = signed integer 5
u = if integer type, u can be preceeded to indicate unsigned integer, such as u5 = unsigned integer 5
# = if offset is preceeded with #, the specified offset is multiplied by the type width, such as #0 = 0, #1 = 8 when type if 8-bit byte

func (*BIT) BitOp

func (b *BIT) BitOp(keyDest string, bitOpType redisbitop.RedisBitop, keySource ...string) error

BitOpAnd performs bitwise operation between multiple keys (containing string value), stores the result in the destination key, if operation failed, error is returned, if success, nil is returned

Supported:

And, Or, XOr, Not

func (*BIT) BitPos

func (b *BIT) BitPos(key string, bitValue int64, startPosition ...int64) (valPosition int64, err error)

BitPos returns the position of the first bit set to 1 or 0 (as requested via input query) in a string, position of bit is returned from left to right, first byte most significant bit is 0 on left most, second byte most significant bit is at position 8 (after the first byte right most bit 7), and so on

bitValue = 1 or 0 startPosition = bit pos start from this bit offset position

func (*BIT) GetBit

func (b *BIT) GetBit(key string, offset int64) (val int, err error)

GetBit will return the bit value (1 or 0) at offset position of the value for the key in redis If key is not found or offset is greater than key's value, then blank string is assumed and bit 0 is returned

func (*BIT) SetBit

func (b *BIT) SetBit(key string, offset int64, bitValue bool) error

SetBit will set or clear (1 or 0) the bit at offset in the string value stored by the key in redis, If the key doesn't exist, a new key with the key defined is created, The string holding bit value will grow as needed when offset exceeds the string, grown value defaults with bit 0

bit range = left 0 -> right 8 = byte

type GEO

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

GEO defines redis GEO operations

func (*GEO) GeoAdd

func (g *GEO) GeoAdd(key string, geoLocation *redis.GeoLocation) error

GeoAdd will add geospatial info (lat, lon, name) to the specified key, data is stored into the key as a sorted set, supports later query by radius with GeoRadius or GeoRadiusByMember commands

valid longitude = -180 to 180 degrees valid latitude = -85.05112878 to 85.05112878 degrees

Use ZREM to remove Geo Key (since there is no GEODEL Command)

func (*GEO) GeoDist

func (g *GEO) GeoDist(key string, member1 string, member2 string, unit redisradiusunit.RedisRadiusUnit) (valDist float64, notFound bool, err error)

GeoDist returns the distance between two members in the geospatial index represented by the sorted set

unit = m (meters), km (kilometers), mi (miles), ft (feet)

func (*GEO) GeoHash

func (g *GEO) GeoHash(key string, member ...string) (geoHashSlice []string, notFound bool, err error)

GeoHash returns valid GeoHash string representing the position of one or more elements in a sorted set (added by GeoAdd) This function returns a STANDARD GEOHASH as described on geohash.org site

func (*GEO) GeoPos

func (g *GEO) GeoPos(key string, member ...string) (*redis.GeoPosCmd, error)

GeoPos returns the position (longitude and latitude) of all the specified members of the geospatial index represented by the sorted set at key

func (*GEO) GeoRadius

func (g *GEO) GeoRadius(key string, longitude float64, latitude float64, query *redis.GeoRadiusQuery) (*redis.GeoLocationCmd, error)

GeoRadius returns the members of a sorted set populated with geospatial information using GeoAdd, which are within the borders of the area specified with the center location and the maximum distance from the center (the radius)

radius = units are: m (meters), km (kilometers), mi (miles), ft (feet) withDist = return the distance of returned items from the specified center (using same unit as units specified in the radius) withCoord = return the longitude and latitude coordinates of the matching items

asc = sort returned items from the nearest to the farthest, relative to the center desc = sort returned items from the farthest to the nearest, relative to the center

count = optional limit of return items; default is return all items found, use count to limit the list

store = store the items in a sorted set populated with their geospatial information storeDist = store the items in a sorted set populated with their distance from the center as a floating point number, in the same unit specified in the radius

func (*GEO) GeoRadiusByMember

func (g *GEO) GeoRadiusByMember(key string, member string, query *redis.GeoRadiusQuery) (*redis.GeoLocationCmd, error)

GeoRadiusByMember is same as GeoRadius, except instead of taking as the center of the area to query (long lat), this takes the name of a member already existing inside the geospatial index represented by the sorted set

The position of the specified member is used as the center of the query

radius = units are: m (meters), km (kilometers), mi (miles), ft (feet) withDist = return the distance of returned items from the specified center (using same unit as units specified in the radius) withCoord = return the longitude and latitude coordinates of the matching items

asc = sort returned items from the nearest to the farthest, relative to the center desc = sort returned items from the farthest to the nearest, relative to the center

count = optional limit of return items; default is return all items found, use count to limit the list

store = store the items in a sorted set populated with their geospatial information storeDist = store the items in a sorted set populated with their distance from the center as a floating point number, in the same unit specified in the radius

func (*GEO) GeoRadiusByMemberStore

func (g *GEO) GeoRadiusByMemberStore(key string, member string, query *redis.GeoRadiusQuery) error

GeoRadiusByMemberStore is same as GeoRadiusStore, except instead of taking as the center of the area to query (long lat), this takes the name of a member already existing inside the geospatial index represented by the sorted set

The position of the specified member is used as the center of the query

radius = units are: m (meters), km (kilometers), mi (miles), ft (feet) withDist = return the distance of returned items from the specified center (using same unit as units specified in the radius) withCoord = return the longitude and latitude coordinates of the matching items

asc = sort returned items from the nearest to the farthest, relative to the center desc = sort returned items from the farthest to the nearest, relative to the center

count = optional limit of return items; default is return all items found, use count to limit the list

store = store the items in a sorted set populated with their geospatial information storeDist = store the items in a sorted set populated with their distance from the center as a floating point number, in the same unit specified in the radius

func (*GEO) GeoRadiusStore

func (g *GEO) GeoRadiusStore(key string, longitude float64, latitude float64, query *redis.GeoRadiusQuery) error

GeoRadiusStore will store the members of a sorted set populated with geospatial information using GeoAdd, which are within the borders of the area specified with the center location and the maximum distance from the center (the radius)

radius = units are: m (meters), km (kilometers), mi (miles), ft (feet) withDist = return the distance of returned items from the specified center (using same unit as units specified in the radius) withCoord = return the longitude and latitude coordinates of the matching items

asc = sort returned items from the nearest to the farthest, relative to the center desc = sort returned items from the farthest to the nearest, relative to the center

count = optional limit of return items; default is return all items found, use count to limit the list

store = store the items in a sorted set populated with their geospatial information storeDist = store the items in a sorted set populated with their distance from the center as a floating point number, in the same unit specified in the radius

type HASH

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

HASH defines redis HASH operations

func (*HASH) HDel

func (h *HASH) HDel(key string, field ...string) (deletedCount int64, err error)

HDel removes the specified 'fields' from the hash stored at key, any specified 'fields' that do not exist in the hash are ignored, if key does not exist, it is treated as an empty hash, and 0 is returned

func (*HASH) HExists

func (h *HASH) HExists(key string, field string) (valExists bool, err error)

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

1 = exists; 0 = not exist or key not exist

func (*HASH) HGet

func (h *HASH) HGet(key string, field string, outputDataType redisdatatype.RedisDataType, outputObjectPtr interface{}) (notFound bool, err error)

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

func (*HASH) HGetAll

func (h *HASH) HGetAll(key string) (outputMap map[string]string, notFound bool, err error)

HGetAll returns all fields and values of the hash store 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

func (*HASH) HIncrBy

func (h *HASH) HIncrBy(key string, field string, incrValue int64) error

HIncrBy increments or decrements the number (int64) value at 'field' in the hash stored at key, if key does not exist, a new key holding a hash is created, if 'field' does not exist then the value is set to 0 before operation is performed

this function supports both increment and decrement (although name of function is increment)

func (*HASH) HIncrByFloat

func (h *HASH) HIncrByFloat(key string, field string, incrValue float64) error

HIncrByFloat increments or decrements the number (float64) value at 'field' in the hash stored at key, if key does not exist, a new key holding a hash is created, if 'field' does not exist then the value is set to 0 before operation is performed

this function supports both increment and decrement (although name of function is increment)

func (*HASH) HKeys

func (h *HASH) HKeys(key string) (outputSlice []string, notFound bool, err error)

HKeys returns all field names in the hash stored at key, field names are the element keys

func (*HASH) HLen

func (h *HASH) HLen(key string) (valLen int64, notFound bool, err error)

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

func (*HASH) HMGet

func (h *HASH) HMGet(key string, field ...string) (outputSlice []interface{}, notFound bool, err error)

HMGet will 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, If key is not existent, then nil is returned for all values

func (*HASH) HMSet

func (h *HASH) HMSet(key string, value ...interface{}) error

HMSet will set the specified 'fields' to their respective values in the hash stored by key, This command overrides any specified 'fields' already existing in the hash, If key does not exist, a new key holding a hash is created

func (*HASH) HScan

func (h *HASH) HScan(key string, cursor uint64, match string, count int64) (outputKeys []string, outputCursor uint64, err error)

HScan is used to incrementally iterate over a set of fields for hash stored at key, HScan is a cursor based iterator, at every call of the command, redis returns an updated cursor that client must use for next call to sort,

start iteration = cursor set to 0 stop iteration = when redis returns cursor value of 0

match = filters elements based on match filter, for elements retrieved from redis before return to client

glob-style patterns:
	1) h?llo = ? represents any single char match (hello, hallo, hxllo match, but heello not match)
	2) h??llo = ?? represents any two char match (heello, haello, hxyllo match, but heeello not match)
	3) h*llo = * represents any single or more char match (hllo, heeeelo match)
	4) h[ae]llo = [ae] represents char inside [ ] that are to match (hello, hallo match, but hillo not match)
	5) h[^e]llo = [^e] represents any char other than e to match (hallo, hbllo match, but hello not match)
	6) h[a-b]llo = [a-b] represents any char match between the a-b range (hallo, hbllo match, but hcllo not match)
	7) Use \ to escape special characters if needing to match verbatim

count = hint to redis count of elements to retrieve in the call

func (*HASH) HSet

func (h *HASH) HSet(key string, value ...interface{}) error

HSet will set 'field' in 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 will be overridden if 'field' does not exist, it will be added

func (*HASH) HSetNX

func (h *HASH) HSetNX(key string, field string, value interface{}) error

HSetNX will set 'field' in hash stored at key to 'value', if 'field' does not currently existing in hash

note:

'field' must not yet exist in hash, otherwise will not add

func (*HASH) HVals

func (h *HASH) HVals(key string) (outputSlice []string, notFound bool, err error)

HVals returns all values in the hash stored at key

type LIST

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

LIST defines redis LIST operations

func (*LIST) LIndex

func (l *LIST) LIndex(key string, index int64, outputDataType redisdatatype.RedisDataType, outputObjectPtr interface{}) (notFound bool, err error)

LIndex returns the element by list index position, for the value stored in list by key, Index is zero-based, Negative Index can be used to denote reverse order,

such as -1 = last element
such as -2 = second to last element, and so on

Error is returned if value at key is not a list

func (*LIST) LInsert

func (l *LIST) LInsert(key string, bBefore bool, pivot interface{}, value interface{}) error

LInsert will insert a value either before or after the pivot element

func (*LIST) LLen

func (l *LIST) LLen(key string) (val int64, notFound bool, err error)

LLen returns the length of the list stored at key, if key does not exist, it is treated as empty list and 0 is returned,

Error is returned if value at key is not a list

func (*LIST) LPop

func (l *LIST) LPop(key string, outputDataType redisdatatype.RedisDataType, outputObjectPtr interface{}) (notFound bool, err error)

LPop will remove and return the first element from the list stored at key

func (*LIST) LPush

func (l *LIST) LPush(key string, keyMustExist bool, value ...interface{}) error

LPush stores all the specified values at the head of the list as defined by the key, if key does not exist, then empty list is created before performing the push operation (unless keyMustExist bit is set)

Elements are inserted one after the other to the head of the list, from the leftmost to the rightmost, for example, LPush mylist a b c will result in a list containing c as first element, b as second element, and a as third element

error is returned if the key is not holding a value of type list

func (*LIST) LRange

func (l *LIST) LRange(key string, start int64, stop int64) (outputSlice []string, notFound bool, err error)

LRange returns the specified elements of the list stored at key, Offsets start and stop are zero based indexes, Offsets can be negative, where -1 is the last element, while -2 is next to last element, and so on,

Offsets start > stop, empty list is returned, Offsets stop > last element, stop uses last element instead

Example:

start top = 0 - 10 = returns 11 elements (0 to 10 = 11)

func (*LIST) LRem

func (l *LIST) LRem(key string, count int64, value interface{}) error

LRem removes the first count occurrences of elements equal to 'element value' from list stored at key count indicates number of occurrences

count > 0 = removes elements equal to 'element value' moving from head to tail count < 0 = removes elements equal to 'element value' moving from tail to head count = 0 = removes all elements equal to 'element value'

Example:

LREM list 02 "hello" = removes the last two occurrences of "hello" in the list stored at key named 'list'

func (*LIST) LSet

func (l *LIST) LSet(key string, index int64, value interface{}) error

LSet will set element to the list index

func (*LIST) LTrim

func (l *LIST) LTrim(key string, start int64, stop int64) error

LTrim will trim an existing list so that it will contian only the specified range of elements specified, Both start and stop are zero-based indexes, Both start and stop can be negative, where -1 is the last element, while -2 is the second to last element

Example:

LTRIM foobar 0 2 = modifies the list store at key named 'foobar' so that only the first 3 elements of the list will remain

func (*LIST) RPop

func (l *LIST) RPop(key string, outputDataType redisdatatype.RedisDataType, outputObjectPtr interface{}) (notFound bool, err error)

RPop removes and returns the last element of the list stored at key

func (*LIST) RPopLPush

func (l *LIST) RPopLPush(keySource string, keyDest string, outputDataType redisdatatype.RedisDataType, outputObjectPtr interface{}) (notFound bool, err error)

RPopLPush will atomically remove and return last element of the list stored at keySource, and then push the returned element at first element position (head) of the list stored at keyDest

func (*LIST) RPush

func (l *LIST) RPush(key string, keyMustExist bool, value ...interface{}) error

RPush stores all the specified values at the tail of the list as defined by the key, if key does not exist, then empty list is created before performing the push operation (unless keyMustExist bit is set)

Elements are inserted one after the other to the tail of the list, from the leftmost to the rightmost, for example, RPush mylist a b c will result in a list containing a as first element, b as second element, and c as third element

error is returned if the key is not holding a value of type list

type PIPELINE

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

PIPELINE defines batched pipeline patterns

func (*PIPELINE) Pipeline

func (p *PIPELINE) Pipeline() (redis.Pipeliner, error)

Pipeline allows actions against redis to be handled in a batched fashion

func (*PIPELINE) Pipelined

func (p *PIPELINE) Pipelined(fn func(redis.Pipeliner) error) ([]redis.Cmder, error)

Pipelined allows actions against redis to be handled in a batched fashion

func (*PIPELINE) TxPipeline

func (p *PIPELINE) TxPipeline() (redis.Pipeliner, error)

TxPipeline allows actions against redis to be handled in a batched fashion

func (*PIPELINE) TxPipelined

func (p *PIPELINE) TxPipelined(fn func(redis.Pipeliner) error) ([]redis.Cmder, error)

TxPipelined allows actions against redis to be handled in a batched fashion

type PUBSUB

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

PUBSUB defines redis PUB SUB operations

func (*PUBSUB) PSubscribe

func (ps *PUBSUB) PSubscribe(channel ...string) (*redis.PubSub, error)

PSubscribe (Pattern Subscribe) will subscribe client to the given pattern channels (glob-style), a pointer to redis PubSub object is returned upon successful subscribe

Once client is subscribed, do not call other redis actions, other than Subscribe, PSubscribe, Ping, Unsubscribe, PUnsubscribe, and Quit (Per Redis Doc)

glob-style patterns:

  1. h?llo = ? represents any single char match (hello, hallo, hxllo match, but heello not match)
  2. h??llo = ?? represents any two char match (heello, haello, hxyllo match, but heeello not match)
  3. h*llo = * represents any single or more char match (hllo, heeeelo match)
  4. h[ae]llo = [ae] represents char inside [ ] that are to match (hello, hallo match, but hillo not match)
  5. h[^e]llo = [^e] represents any char other than e to match (hallo, hbllo match, but hello not match)
  6. h[a-b]llo = [a-b] represents any char match between the a-b range (hallo, hbllo match, but hcllo not match)
  7. Use \ to escape special characters if needing to match verbatim

func (*PUBSUB) PubSubChannels

func (ps *PUBSUB) PubSubChannels(pattern string) (valChannels []string, err error)

PubSubChannels lists currently active channels, active channel = pub/sub channel with one or more subscribers (excluding clients subscribed to patterns), pattern = optional, channels matching specific glob-style pattern are listed; otherwise, all channels listed

glob-style patterns:

  1. h?llo = ? represents any single char match (hello, hallo, hxllo match, but heello not match)
  2. h??llo = ?? represents any two char match (heello, haello, hxyllo match, but heeello not match)
  3. h*llo = * represents any single or more char match (hllo, heeeelo match)
  4. h[ae]llo = [ae] represents char inside [ ] that are to match (hello, hallo match, but hillo not match)
  5. h[^e]llo = [^e] represents any char other than e to match (hallo, hbllo match, but hello not match)
  6. h[a-b]llo = [a-b] represents any char match between the a-b range (hallo, hbllo match, but hcllo not match)
  7. Use \ to escape special characters if needing to match verbatim

func (*PUBSUB) PubSubNumPat

func (ps *PUBSUB) PubSubNumPat() (valPatterns int64, err error)

PubSubNumPat (Pub/Sub Number of Patterns) returns the number of subscriptions to patterns (that were using PSubscribe Command), This counts both clients subscribed to patterns, and also total number of patterns all the clients are subscribed to

func (*PUBSUB) PubSubNumSub

func (ps *PUBSUB) PubSubNumSub(channel ...string) (val map[string]int64, err error)

PubSubNumSub (Pub/Sub Number of Subscribers) returns number of subscribers (not counting clients subscribed to patterns) for the specific channels

func (*PUBSUB) Publish

func (ps *PUBSUB) Publish(channel string, message interface{}) (valReceived int64, err error)

Publish will post a message to a given channel, returns number of clients that received the message

func (*PUBSUB) Subscribe

func (ps *PUBSUB) Subscribe(channel ...string) (*redis.PubSub, error)

Subscribe (Non-Pattern Subscribe) will subscribe client to the given channels, a pointer to redis PubSub object is returned upon successful subscribe

Once client is subscribed, do not call other redis actions, other than Subscribe, PSubscribe, Ping, Unsubscribe, PUnsubscribe, and Quit (Per Redis Doc)

type Redis

type Redis struct {
	// config fields
	AwsRedisWriterEndpoint string
	AwsRedisReaderEndpoint string

	// objects containing wrapped functions
	BIT        *BIT
	LIST       *LIST
	HASH       *HASH
	SET        *SET
	SORTED_SET *SORTED_SET
	GEO        *GEO
	STREAM     *STREAM
	PUBSUB     *PUBSUB
	PIPELINE   *PIPELINE
	TTL        *TTL
	UTILS      *UTILS
	// contains filtered or unexported fields
}

Redis defines wrapper struct to handle redis interactions with AWS ElasticCache Redis service (using go-redis package)

IMPORTANT

AWS ELASTICACHE REDIS lives within the VPC that the cluster is launched
Access is allowed ONLY WITHIN EC2 in the same VPC
There is no external public access since AWS Redis uses private IP only

Dev Testing

Test On AWS EC2 (via SSH into EC2) since elastic cache redis is deployed within vpc access only

Reference Info

  1. Redis Commands Documentation = https://redis.io/commands
  2. Go-Redis Documentation = https://pkg.go.dev/github.com/go-redis/redis?tab=doc

func (*Redis) Append

func (r *Redis) Append(key string, valToAppend string) error

Append will append a value to the existing value under the given key in redis, if key does not exist, a new key based on the given key is created

func (*Redis) Connect

func (r *Redis) Connect() error

Connect will establish aws redis writer and reader endpoint client connections

func (*Redis) Del

func (r *Redis) Del(key ...string) (deletedCount int64, err error)

Del will delete one or more keys specified from redis

func (*Redis) Disconnect

func (r *Redis) Disconnect()

Disconnect will close aws redis writer and reader endpoints

func (*Redis) Exists

func (r *Redis) Exists(key ...string) (foundCount int64, err error)

Exists checks if one or more keys exists in redis

foundCount = 0 indicates not found; > 0 indicates found count

func (*Redis) Float64AddOrReduce

func (r *Redis) Float64AddOrReduce(key string, val float64) (newVal float64, notFound bool, err error)

Float64AddOrReduce will add or reduce float64 value against a key in redis, and return the new value if found and performed

func (*Redis) Get

func (r *Redis) Get(key string) (val string, notFound bool, err error)

Get gets string value from redis by key

func (*Redis) GetBase

func (r *Redis) GetBase(key string) (cmd *redis.StringCmd, notFound bool, err error)

GetBase is internal helper to get value from redis

func (*Redis) GetBool

func (r *Redis) GetBool(key string) (val bool, notFound bool, err error)

GetBool gets bool value from redis by key

func (*Redis) GetBytes

func (r *Redis) GetBytes(key string) (val []byte, notFound bool, err error)

GetBytes gets []byte value from redis by key

func (*Redis) GetFloat64

func (r *Redis) GetFloat64(key string) (val float64, notFound bool, err error)

GetFloat64 gets float64 value from redis by key

func (*Redis) GetInt

func (r *Redis) GetInt(key string) (val int, notFound bool, err error)

GetInt gets int value from redis by key

func (*Redis) GetInt64

func (r *Redis) GetInt64(key string) (val int64, notFound bool, err error)

GetInt64 gets int64 value from redis by key

func (*Redis) GetJson

func (r *Redis) GetJson(key string, resultObjectPtr interface{}) (notFound bool, err error)

GetJson gets Json object from redis by key (Json is stored as string in redis, unmarshaled to target object via get)

func (*Redis) GetRange

func (r *Redis) GetRange(key string, start int64, end int64) (val string, notFound bool, err error)

GetRange gets val between start and end positions from string value stored by key in redis

func (*Redis) GetSet

func (r *Redis) GetSet(key string, val string) (oldValue string, notFound bool, err error)

GetSet will get old string value from redis by key, and then set new string value into redis by the same key

func (*Redis) GetTime

func (r *Redis) GetTime(key string) (val time.Time, notFound bool, err error)

GetTime gets time.Time value from redis by key

func (*Redis) Int64AddOrReduce

func (r *Redis) Int64AddOrReduce(key string, val int64, isReduce ...bool) (newVal int64, notFound bool, err error)

Int64AddOrReduce will add or reduce int64 value against a key in redis, and return the new value if found and performed

func (*Redis) MGet

func (r *Redis) MGet(key ...string) (results []interface{}, notFound bool, err error)

MGet is a helper to get values from redis based on one or more keys specified

func (*Redis) MSet

func (r *Redis) MSet(kvMap map[string]interface{}, setIfNotExists ...bool) error

MSet is helper to set multiple values into redis by keys, optional parameter setIfNotExists indicates if instead MSetNX is to be used

notes

kvMap = map of key string, and interface{} value

func (*Redis) PFAdd

func (r *Redis) PFAdd(key string, elements ...interface{}) error

PFAdd is a HyperLogLog function to uniquely accumulate the count of a specific value to redis, such as email hit count, user hit count, ip address hit count etc, that is based on the unique occurences of such value

func (*Redis) PFCount

func (r *Redis) PFCount(key ...string) (val int64, notFound bool, err error)

PFCount is a HyperLogLog function to retrieve the current count associated with the given unique value in redis, Specify one or more keys, if multiple keys used, the result count is the union of all keys' unique value counts

func (*Redis) PFMerge

func (r *Redis) PFMerge(destKey string, sourceKey ...string) error

PFMerge is a HyperLogLog function to merge two or more HyperLogLog as defined by keys together

func (*Redis) Set

func (r *Redis) Set(key string, val string, expires ...time.Duration) error

Set sets string value into redis by key

func (*Redis) SetBase

func (r *Redis) SetBase(key string, val interface{}, setCondition redissetcondition.RedisSetCondition, expires ...time.Duration) error

Set is helper to set value into redis by key

notes

setCondition = support for SetNX and SetXX

func (*Redis) SetBool

func (r *Redis) SetBool(key string, val bool, expires ...time.Duration) error

SetBool sets boolean value into redis by key

func (*Redis) SetBytes

func (r *Redis) SetBytes(key string, val []byte, expires ...time.Duration) error

SetBytes sets []byte value into redis by key

func (*Redis) SetFloat64

func (r *Redis) SetFloat64(key string, val float64, expires ...time.Duration) error

SetFloat64 sets float64 value into redis by key

func (*Redis) SetInt

func (r *Redis) SetInt(key string, val int, expires ...time.Duration) error

SetInt sets int value into redis by key

func (*Redis) SetInt64

func (r *Redis) SetInt64(key string, val int64, expires ...time.Duration) error

SetInt64 sets int64 value into redis by key

func (*Redis) SetJson

func (r *Redis) SetJson(key string, jsonObject interface{}, expires ...time.Duration) error

SetJson sets Json object into redis by key (Json object is marshaled into string and then saved to redis)

func (*Redis) SetRange

func (r *Redis) SetRange(key string, offset int64, val string) error

SetRange sets val into key's stored value in redis, offset by the offset number

example:

  1. "Hello World"
  2. Offset 6 = W
  3. Val "Xyz" replaces string from Offset Position 6
  4. End Result String = "Hello Xyzld"

func (*Redis) SetTime

func (r *Redis) SetTime(key string, val time.Time, expires ...time.Duration) error

SetTime sets time.Time value into redis by key

func (*Redis) StrLen

func (r *Redis) StrLen(key string) (length int64, notFound bool, err error)

StrLen gets the string length of the value stored by the key in redis

func (r *Redis) Unlink(key ...string) (unlinkedCount int64, err error)

Unlink is similar to Del where it removes one or more keys specified from redis, however, unlink performs the delete asynchronously and is faster than Del

type SET

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

SET defines redis SET operations

func (*SET) SAdd

func (s *SET) SAdd(key string, member ...interface{}) 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

Error is returned when the value stored at key is not a set

func (*SET) SCard

func (s *SET) SCard(key string) (val int64, notFound bool, err error)

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

func (*SET) SDiff

func (s *SET) SDiff(key ...string) (outputSlice []string, notFound bool, err error)

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

Example:

key1 = { a, b, c, d }
key2 = { c }
key3 = { a, c, e }
SDIFF key1, key2, key3 = { b, d }
	{ b, d } is returned because this is the difference delta

func (*SET) SDiffStore

func (s *SET) SDiffStore(keyDest string, keySource ...string) error

SDiffStore will store the set differential to destination, if destination already exists, it is overwritten

Example:

key1 = { a, b, c, d }
key2 = { c }
key3 = { a, c, e }
SDIFF key1, key2, key3 = { b, d }
	{ b, d } is stored because this is the difference delta

func (*SET) SInter

func (s *SET) SInter(key ...string) (outputSlice []string, notFound bool, err error)

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

Example:

Key1 = { a, b, c, d }
Key2 = { c }
Key3 = { a, c, e }
SINTER key1 key2 key3 = { c }
	{ c } is returned because this is the intersection on all keys (appearing in all keys)

func (*SET) SInterStore

func (s *SET) SInterStore(keyDest string, keySource ...string) error

SInterStore stores the members of the set resulting from the intersection of all the given sets to destination, if destination already exists, it is overwritten

Example:

Key1 = { a, b, c, d }
Key2 = { c }
Key3 = { a, c, e }
SINTER key1 key2 key3 = { c }
	{ c } is stored because this is the intersection on all keys (appearing in all keys)

func (*SET) SIsMember

func (s *SET) SIsMember(key string, member interface{}) (val bool, err error)

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

func (*SET) SMembers

func (s *SET) SMembers(key string) (outputSlice []string, notFound bool, err error)

SMembers returns all the members of the set value stored at key

func (*SET) SMembersMap

func (s *SET) SMembersMap(key string) (outputMap map[string]struct{}, notFound bool, err error)

SMembersMap returns all the members of the set value stored at key, via map

func (*SET) SMove

func (s *SET) SMove(keySource string, keyDest string, member interface{}) error

SMove will move a member from the set at 'source' to the set at 'destination' atomically, The element will appear to be a member of source or destination for other clients

If 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

If the specified element already exist in the destination set, it is only removed from the source set

Error is returned if the source or destination does not hold a set value

func (*SET) SPop

func (s *SET) SPop(key string, outputDataType redisdatatype.RedisDataType, outputObjectPtr interface{}) (notFound bool, err error)

SPop removes and returns one random element from the set value stored at key

func (*SET) SPopN

func (s *SET) SPopN(key string, count int64) (outputSlice []string, notFound bool, err error)

SPop removes and returns one or more random element from the set value stored at key

count > 0 = returns an array of count distinct elements (non-repeating), up to the set elements size count < 0 = returns an array of count elements (may be repeating), and up to the count size (selected members may still be part of the subsequent selection process)

func (*SET) SRandMember

func (s *SET) SRandMember(key string, outputDataType redisdatatype.RedisDataType, outputObjectPtr interface{}) (notFound bool, err error)

SRandMember returns a random element from the set value stored at key

func (*SET) SRandMemberN

func (s *SET) SRandMemberN(key string, count int64) (outputSlice []string, notFound bool, err error)

SRandMemberN returns one or more random elements from the set value stored at key, with count indicating return limit

count > 0 = returns an array of count distinct elements (non-repeating), up to the set elements size count < 0 = returns an array of count elements (may be repeating), and up to the count size (selected members may still be part of the subsequent selection process)

func (*SET) SRem

func (s *SET) SRem(key string, member ...interface{}) 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

Error is returned if the value stored at key is not a set

func (*SET) SScan

func (s *SET) SScan(key string, cursor uint64, match string, count int64) (outputKeys []string, outputCursor uint64, err error)

SScan is used to incrementally iterate over a set of fields for set stored at key, SScan is a cursor based iterator, at every call of the command, redis returns an updated cursor that client must use for next call to sort,

start iteration = cursor set to 0 stop iteration = when redis returns cursor value of 0

match = filters elements based on match filter, for elements retrieved from redis before return to client

glob-style patterns:
	1) h?llo = ? represents any single char match (hello, hallo, hxllo match, but heello not match)
	2) h??llo = ?? represents any two char match (heello, haello, hxyllo match, but heeello not match)
	3) h*llo = * represents any single or more char match (hllo, heeeelo match)
	4) h[ae]llo = [ae] represents char inside [ ] that are to match (hello, hallo match, but hillo not match)
	5) h[^e]llo = [^e] represents any char other than e to match (hallo, hbllo match, but hello not match)
	6) h[a-b]llo = [a-b] represents any char match between the a-b range (hallo, hbllo match, but hcllo not match)
	7) Use \ to escape special characters if needing to match verbatim

count = hint to redis count of elements to retrieve in the call

func (*SET) SUnion

func (s *SET) SUnion(key ...string) (outputSlice []string, notFound bool, err error)

SUnion returns the members of the set resulting from the union of all the given sets, if a key is not existent, it is treated as a empty set

Example:

key1 = { a, b, c }
key2 = { c }
key3 = { a, c, e }
SUNION key1 key2 key3 = { a, b, c, d, e }

func (*SET) SUnionStore

func (s *SET) SUnionStore(keyDest string, keySource ...string) error

SUnionStore will store the members of the set resulting from the union of all the given sets to 'destination' if a key is not existent, it is treated as a empty set, if 'destination' already exists, it is overwritten

Example:

key1 = { a, b, c }
key2 = { c }
key3 = { a, c, e }
SUNION key1 key2 key3 = { a, b, c, d, e }

type SORTED_SET

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

SORTED_SET defines SORTED SET operations

func (*SORTED_SET) ZAdd

func (z *SORTED_SET) ZAdd(key string, setCondition redissetcondition.RedisSetCondition, getChanged bool, member ...*redis.Z) error

ZAdd will add all the specified members with the specified scores to the sorted set stored at key, 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 is created as if the set was empty

If value at key is not a sorted set, then error is returned

Score Values:

  1. Should be string representation of a double precision floating point number

Other ZAdd Options:

  1. ZAdd XX / XXCH = only update elements that already exists, never add elements
  2. ZAdd NX / NXCH = don't update already existing elements, always add new elements
  3. ZAdd CH = modify the return value from the number of new or updated elements added, CH = Changed

func (*SORTED_SET) ZCard

func (z *SORTED_SET) ZCard(key string) (val int64, notFound bool, err error)

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

func (*SORTED_SET) ZCount

func (z *SORTED_SET) ZCount(key string, min string, max string) (val int64, notFound bool, err error)

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

func (*SORTED_SET) ZIncr

func (z *SORTED_SET) ZIncr(key string, setCondition redissetcondition.RedisSetCondition, member *redis.Z) error

ZIncr will increment the score of member in sorted set at key

Also support for ZIncrXX (member must exist), ZIncrNX (member must not exist)

func (*SORTED_SET) ZIncrBy

func (z *SORTED_SET) ZIncrBy(key string, increment float64, member string) error

ZIncrBy increments or decrements the score of member in the sorted set stored at key, with custom increment value, If member does not exist in the sorted set, it is added with increment value as its score, If key does not exist, a new sorted set with the specified member as its sole member is created

Error is returned if the value stored at key is not a sorted set

Score should be string representation of a numeric value, and accepts double precision floating point numbers To decrement, use negative value

func (*SORTED_SET) ZInterStore

func (z *SORTED_SET) ZInterStore(keyDest string, store *redis.ZStore) error

ZInterStore computes the intersection of numKeys sorted set given by the specified keys, and stores the result in 'destination'

numKeys (input keys) are required

If 'destination' already exists, it is overwritten

Default Logic:

Resulting score of an element is the sum of its scores in the sorted set where it exists

func (*SORTED_SET) ZLexCount

func (z *SORTED_SET) ZLexCount(key string, min string, max string) (val int64, notFound bool, err error)

ZLexCount returns the number of elements in the sorted set at key, with a value between min and max

func (*SORTED_SET) ZPopMax

func (z *SORTED_SET) ZPopMax(key string, count ...int64) (outputSlice []redis.Z, notFound bool, err error)

ZPopMax removes and returns up to the count of members with the highest scores in the sorted set stored at key, Specifying more count than members will not cause error, rather given back smaller result set, Returning elements ordered with highest score first, then subsequent and so on

func (*SORTED_SET) ZPopMin

func (z *SORTED_SET) ZPopMin(key string, count ...int64) (outputSlice []redis.Z, notFound bool, err error)

ZPopMin removes and returns up to the count of members with the lowest scores in the sorted set stored at key, Specifying more count than members will not cause error, rather given back smaller result set, Returning elements ordered with lowest score first, then subsequently higher score, and so on

func (*SORTED_SET) ZRange

func (z *SORTED_SET) ZRange(key string, start int64, stop int64) (outputSlice []string, notFound bool, err error)

ZRange returns the specified range of elements in the sorted set stored at key, The elements are considered to be ordered form lowest to the highest score, Lexicographical order is used for elements with equal score

start and stop are both zero-based indexes, start and stop may be negative, where -1 is the last index, and -2 is the second to the last index, start and stop are inclusive range

func (*SORTED_SET) ZRangeByLex

func (z *SORTED_SET) ZRangeByLex(key string, opt *redis.ZRangeBy) (outputSlice []string, notFound bool, err error)

ZRangeByLex returns all the elements in the sorted set at key with a value between min and max

func (*SORTED_SET) ZRangeByScore

func (z *SORTED_SET) ZRangeByScore(key string, opt *redis.ZRangeBy) (outputSlice []string, notFound bool, err error)

ZRangeByScore returns all the elements in the sorted set at key with a score between min and max, Elements are considered to be ordered from low to high scores

func (*SORTED_SET) ZRangeByScoreWithScores

func (z *SORTED_SET) ZRangeByScoreWithScores(key string, opt *redis.ZRangeBy) (outputSlice []redis.Z, notFound bool, err error)

ZRangeByScoreWithScores returns all the elements in the sorted set at key with a score between min and max, Elements are considered to be ordered from low to high scores

func (*SORTED_SET) ZRank

func (z *SORTED_SET) ZRank(key string, member string) (val int64, notFound bool, err 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 zero-based, where lowest member is index 0 (or rank 0)

func (*SORTED_SET) ZRem

func (z *SORTED_SET) ZRem(key string, member ...interface{}) error

ZRem removes the specified members from the stored set stored at key, Non-existing members are ignored

Error is returned if the value at key is not a sorted set

func (*SORTED_SET) ZRemRangeByLex

func (z *SORTED_SET) ZRemRangeByLex(key string, min string, max string) error

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

func (*SORTED_SET) ZRemRangeByRank

func (z *SORTED_SET) ZRemRangeByRank(key string, start int64, stop int64) error

ZRemRangeByRank removes all elements in the sorted set stored at key, with rank between start and stop

Both start and stop are zero-based, Both start and stop can be negative, where -1 is the element with highest score, -2 is the element with next to highest score, and so on

func (*SORTED_SET) ZRemRangeByScore

func (z *SORTED_SET) ZRemRangeByScore(key string, min string, max string) error

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

func (*SORTED_SET) ZRevRange

func (z *SORTED_SET) ZRevRange(key string, start int64, stop int64) (outputSlice []string, notFound bool, err error)

ZRevRange returns the specified range of elements in the sorted set stored at key, With elements ordered from highest to the lowest score, Descending lexicographical order is used for elements with equal score

func (*SORTED_SET) ZRevRangeByScoreWithScores

func (z *SORTED_SET) ZRevRangeByScoreWithScores(key string, opt *redis.ZRangeBy) (outputSlice []redis.Z, notFound bool, err error)

ZRevRangeByScoreWithScores returns all the elements (with scores) in the sorted set at key, with a score between max and min (inclusive), With elements ordered from highest to lowest scores, Descending lexicographical order is used for elements with equal score

func (*SORTED_SET) ZRevRangeWithScores

func (z *SORTED_SET) ZRevRangeWithScores(key string, start int64, stop int64) (outputSlice []redis.Z, notFound bool, err error)

ZRevRangeWithScores returns the specified range of elements (with scores) in the sorted set stored at key, With elements ordered from highest to the lowest score, Descending lexicographical order is used for elements with equal score

func (*SORTED_SET) ZRevRank

func (z *SORTED_SET) ZRevRank(key string, member string) (val int64, notFound bool, err error)

ZRevRank returns the rank of member in the sorted set stored at key, with the scores ordered from high to low, Rank (index) is ordered from high to low, and is zero-based, where 0 is the highest rank (index) ZRevRank is opposite of ZRank

func (*SORTED_SET) ZScan

func (z *SORTED_SET) ZScan(key string, cursor uint64, match string, count int64) (outputKeys []string, outputCursor uint64, err error)

ZScan is used to incrementally iterate over a sorted set of fields stored at key, ZScan is a cursor based iterator, at every call of the command, redis returns an updated cursor that client must use for next call to sort,

start iteration = cursor set to 0 stop iteration = when redis returns cursor value of 0

match = filters elements based on match filter, for elements retrieved from redis before return to client

glob-style patterns:
	1) h?llo = ? represents any single char match (hello, hallo, hxllo match, but heello not match)
	2) h??llo = ?? represents any two char match (heello, haello, hxyllo match, but heeello not match)
	3) h*llo = * represents any single or more char match (hllo, heeeelo match)
	4) h[ae]llo = [ae] represents char inside [ ] that are to match (hello, hallo match, but hillo not match)
	5) h[^e]llo = [^e] represents any char other than e to match (hallo, hbllo match, but hello not match)
	6) h[a-b]llo = [a-b] represents any char match between the a-b range (hallo, hbllo match, but hcllo not match)
	7) Use \ to escape special characters if needing to match verbatim

count = hint to redis count of elements to retrieve in the call

func (*SORTED_SET) ZScore

func (z *SORTED_SET) ZScore(key string, member string) (val float64, notFound bool, err error)

ZScore returns the score of member in the sorted set at key, if member is not existent in the sorted set, or key does not exist, nil is returned

func (*SORTED_SET) ZUnionStore

func (z *SORTED_SET) ZUnionStore(keyDest string, store *redis.ZStore) error

ZUnionStore computes the union of numKeys sorted set given by the specified keys, and stores the result in 'destination'

numKeys (input keys) are required

type STREAM

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

STREAM defines redis STREAM operations

func (*STREAM) XAck

func (x *STREAM) XAck(stream string, group string, id ...string) error

XAck removes one or multiple messages from the 'pending entries list (PEL)' of a stream consumer group

A message is pending, and as such stored inside the PEL, when it was delivered to some consumer

Once a consumer successfully processes a message, it should call XAck to remove the message so it does not get processed again (and releases message from memory in redis)

func (*STREAM) XAdd

func (x *STREAM) XAdd(addArgs *redis.XAddArgs) error

XAdd appends the specified stream entry to the stream at the specified key, If the key does not exist, as a side effect of running this command the key is created with a stream value

func (*STREAM) XClaim

func (x *STREAM) XClaim(claimArgs *redis.XClaimArgs) (valMessages []redis.XMessage, notFound bool, err error)

XClaim in the context of stream consumer group, this function changes the ownership of a pending message, so that the new owner is the consumer specified as the command argument

func (*STREAM) XClaimJustID

func (x *STREAM) XClaimJustID(claimArgs *redis.XClaimArgs) (outputSlice []string, notFound bool, err error)

XClaimJustID in the context of stream consumer group, this function changes the ownership of a pending message, so that the new owner is the consumer specified as the command argument

func (*STREAM) XDel

func (x *STREAM) XDel(stream string, id ...string) error

XDel removes the specified entries from a stream

func (*STREAM) XGroupCreate

func (x *STREAM) XGroupCreate(stream string, group string, start string) error

XGroupCreate will create a new consumer group associated with a stream

func (*STREAM) XGroupCreateMkStream

func (x *STREAM) XGroupCreateMkStream(stream string, group string, start string) error

XGroupCreateMkStream will create a new consumer group, and create a stream if stream doesn't exist

func (*STREAM) XGroupDelConsumer

func (x *STREAM) XGroupDelConsumer(stream string, group string, consumer string) error

XGroupDelConsumer removes a given consumer from a consumer group

func (*STREAM) XGroupDestroy

func (x *STREAM) XGroupDestroy(stream string, group string) error

XGroupDestroy will destroy a consumer group even if there are active consumers and pending messages

func (*STREAM) XGroupSetID

func (x *STREAM) XGroupSetID(stream string, group string, start string) error

XGroupSetID will set the next message to deliver, Normally the next ID is set when the consumer is created, as the last argument to XGroupCreate, However, using XGroupSetID resets the next message ID in case prior message needs to be reprocessed

func (*STREAM) XInfoGroups

func (x *STREAM) XInfoGroups(key string) (outputSlice []redis.XInfoGroups, notFound bool, err error)

XInfoGroups retrieves different information about the streams, and associated consumer groups

func (*STREAM) XLen

func (x *STREAM) XLen(stream string) (val int64, notFound bool, err error)

XLen returns the number of entries inside a stream

func (*STREAM) XPending

func (x *STREAM) XPending(stream string, group string) (val *redis.XPending, notFound bool, err error)

XPending fetches data from a stream via a consumer group, and not acknowledging such data, its like creating pending entries

func (*STREAM) XPendingExt

func (x *STREAM) XPendingExt(pendingArgs *redis.XPendingExtArgs) (outputSlice []redis.XPendingExt, notFound bool, err error)

XPendingExt fetches data from a stream via a consumer group, and not acknowledging such data, its like creating pending entries

func (*STREAM) XRange

func (x *STREAM) XRange(stream string, start string, stop string, count ...int64) (outputSlice []redis.XMessage, notFound bool, err error)

XRange returns the stream entries matching a given range of IDs, Range is specified by a minimum and maximum ID, Ordering is lowest to highest

func (*STREAM) XRead

func (x *STREAM) XRead(readArgs *redis.XReadArgs) (outputSlice []redis.XStream, notFound bool, err error)

XRead will read data from one or multiple streams, only returning entries with an ID greater than the last received ID reported by the caller

func (*STREAM) XReadGroup

func (x *STREAM) XReadGroup(readGroupArgs *redis.XReadGroupArgs) (outputSlice []redis.XStream, notFound bool, err error)

XReadGroup is a special version of XRead command with support for consumer groups

func (*STREAM) XReadStreams

func (x *STREAM) XReadStreams(stream ...string) (outputSlice []redis.XStream, notFound bool, err error)

XReadStreams is a special version of XRead command for streams

func (*STREAM) XRevRange

func (x *STREAM) XRevRange(stream string, start string, stop string, count ...int64) (outputSlice []redis.XMessage, notFound bool, err error)

XRevRange returns the stream entries matching a given range of IDs, Range is specified by a maximum and minimum ID, Ordering is highest to lowest

func (*STREAM) XTrim

func (x *STREAM) XTrim(key string, maxLen int64) error

XTrim trims the stream to a given number of items, evicting older items (items with lower IDs) if needed

func (*STREAM) XTrimApprox

func (x *STREAM) XTrimApprox(key string, maxLen int64) error

XTrimApprox trims the stream to a given number of items, evicting older items (items with lower IDs) if needed

type TTL

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

TTL defines TTL and Persist related redis patterns

func (*TTL) Expire

func (t *TTL) Expire(key string, bSetMilliseconds bool, expireValue time.Duration) error

Expire sets a timeout on key (seconds or milliseconds based on input parameter)

expireValue = in seconds or milliseconds

func (*TTL) ExpireAt

func (t *TTL) ExpireAt(key string, expireTime time.Time) error

ExpireAt sets the hard expiration date time based on unix timestamp for a given key

Setting expireTime to the past immediately deletes the key

func (*TTL) Persist

func (t *TTL) Persist(key string) error

Persist removes existing timeout TTL of a key so it lives forever

func (*TTL) TTL

func (t *TTL) TTL(key string, bGetMilliseconds bool) (valTTL int64, notFound bool, err error)

TTL returns the remainder time to live in seconds or milliseconds, for key that has a TTL set, returns -1 if no TTL applicable (forever living)

func (*TTL) Touch

func (t *TTL) Touch(key ...string) error

Touch alters the last access time of a key or keys, if key doesn't exist, it is ignored

type UTILS

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

UTILS defines redis helper functions

func (*UTILS) DBSize

func (u *UTILS) DBSize() (val int64, err error)

DBSize returns number of keys in the redis database

func (*UTILS) Keys

func (u *UTILS) Keys(match string) (valKeys []string, notFound bool, err error)

Keys returns all keys matching given pattern (use with extreme care, use for debugging only, may slow production system down significantly)

start iteration = cursor set to 0 stop iteration = when redis returns cursor value of 0

match = filters elements based on match filter, for elements retrieved from redis before return to client

glob-style patterns:
	1) h?llo = ? represents any single char match (hello, hallo, hxllo match, but heello not match)
	2) h??llo = ?? represents any two char match (heello, haello, hxyllo match, but heeello not match)
	3) h*llo = * represents any single or more char match (hllo, heeeelo match)
	4) h[ae]llo = [ae] represents char inside [ ] that are to match (hello, hallo match, but hillo not match)
	5) h[^e]llo = [^e] represents any char other than e to match (hallo, hbllo match, but hello not match)
	6) h[a-b]llo = [a-b] represents any char match between the a-b range (hallo, hbllo match, but hcllo not match)
	7) Use \ to escape special characters if needing to match verbatim

func (*UTILS) LastSave

func (u *UTILS) LastSave() (val time.Time, err error)

LastSave checks if last db save action was successful

func (*UTILS) ObjectEncoding

func (u *UTILS) ObjectEncoding(key string) (val string, notFound bool, err error)

ObjectEncoding returns the internal representation used in order to store the value associated with a key

func (*UTILS) ObjectIdleTime

func (u *UTILS) ObjectIdleTime(key string) (val time.Duration, notFound bool, err error)

ObjectIdleTime returns the number of seconds since the object stored at the specified key is idle (not requested by read or write operations)

func (*UTILS) ObjectRefCount

func (u *UTILS) ObjectRefCount(key string) (val int64, notFound bool, err error)

ObjectRefCount returns the number of references of the value associated with the specified key

func (*UTILS) Ping

func (u *UTILS) Ping() error

Ping will ping the redis server to see if its up

result nil = success; otherwise error info is returned via error object

func (*UTILS) RandomKey

func (u *UTILS) RandomKey() (val string, err error)

RandomKey returns a random key from redis

func (*UTILS) Rename

func (u *UTILS) Rename(keyOriginal string, keyNew string) error

Rename will rename the keyOriginal to be keyNew in redis, if keyNew already exist in redis, then Rename will override existing keyNew with keyOriginal if keyOriginal is not in redis, error is returned

func (*UTILS) RenameNX

func (u *UTILS) RenameNX(keyOriginal string, keyNew string) error

RenameNX will rename the keyOriginal to be keyNew IF keyNew does not yet exist in redis if RenameNX fails due to keyNew already exist, or other errors, the error is returned

func (*UTILS) Scan

func (u *UTILS) Scan(cursor uint64, match string, count int64) (keys []string, resultCursor uint64, err error)

Scan is used to incrementally iterate over a set of keys, Scan is a cursor based iterator, at every call of the command, redis returns an updated cursor that client must use for next call to sort,

start iteration = cursor set to 0 stop iteration = when redis returns cursor value of 0

match = filters elements based on match filter, for elements retrieved from redis before return to client

glob-style patterns:
	1) h?llo = ? represents any single char match (hello, hallo, hxllo match, but heello not match)
	2) h??llo = ?? represents any two char match (heello, haello, hxyllo match, but heeello not match)
	3) h*llo = * represents any single or more char match (hllo, heeeelo match)
	4) h[ae]llo = [ae] represents char inside [ ] that are to match (hello, hallo match, but hillo not match)
	5) h[^e]llo = [^e] represents any char other than e to match (hallo, hbllo match, but hello not match)
	6) h[a-b]llo = [a-b] represents any char match between the a-b range (hallo, hbllo match, but hcllo not match)
	7) Use \ to escape special characters if needing to match verbatim

count = hint to redis count of elements to retrieve in the call

func (*UTILS) Sort

func (u *UTILS) Sort(key string, sortPattern *redis.Sort) (val []string, notFound bool, err error)

Sort will sort values as defined by keyToSort, along with sortPattern, and then return the sorted data via string slice sort is applicable to list, set, or sorted set as defined by key

sortPattern = defines the sort conditions (see redis sort documentation for details)

func (*UTILS) SortInterfaces

func (u *UTILS) SortInterfaces(keyToSort string, sortPattern *redis.Sort) (val []interface{}, notFound bool, err error)

SortInterfaces will sort values as defined by keyToSort, along with sortPattern, and then return the sorted data via []interface{} sort is applicable to list, set, or sorted set as defined by key

sortPattern = defines the sort conditions (see redis sort documentation for details)

func (*UTILS) SortStore

func (u *UTILS) SortStore(keyToSort string, keyToStore string, sortPattern *redis.Sort) error

SortStore will sort values defined by keyToSort, and sort according to sortPattern, and set sorted results into keyToStore in redis sort is applicable to list, set, or sorted set as defined by key

sortPattern = defines the sort conditions (see redis sort documentation for details)

func (*UTILS) Time

func (u *UTILS) Time() (val time.Time, err error)

Time returns the redis server time

func (*UTILS) Type

func (u *UTILS) Type(key string) (val rediskeytype.RedisKeyType, err error)

Type returns the redis key's value type stored expected result in string = list, set, zset, hash, and stream

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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