Documentation
¶
Index ¶
- Constants
- type BackoffStrategy
- type BaseClient
- type BitmapCommands
- type ClusterValue
- type ConnectionManagementClusterCommands
- type ConnectionManagementCommands
- type ConsumerPendingMessage
- type GenericBaseCommands
- type GenericClusterCommands
- type GenericCommands
- type GlideClient
- func (client GlideClient) Append(key string, value string) (int64, error)
- func (client GlideClient) BLMPop(keys []string, listDirection options.ListDirection, timeoutSecs float64) (map[string][]string, error)
- func (client GlideClient) BLMPopCount(keys []string, listDirection options.ListDirection, count int64, ...) (map[string][]string, error)
- func (client GlideClient) BLMove(source string, destination string, whereFrom options.ListDirection, ...) (Result[string], error)
- func (client GlideClient) BLPop(keys []string, timeoutSecs float64) ([]string, error)
- func (client GlideClient) BRPop(keys []string, timeoutSecs float64) ([]string, error)
- func (client GlideClient) BZMPop(keys []string, scoreFilter options.ScoreFilter, timeoutSecs float64) (Result[KeyWithArrayOfMembersAndScores], error)
- func (client GlideClient) BZMPopWithOptions(keys []string, scoreFilter options.ScoreFilter, timeoutSecs float64, ...) (Result[KeyWithArrayOfMembersAndScores], error)
- func (client GlideClient) BZPopMin(keys []string, timeoutSecs float64) (Result[KeyWithMemberAndScore], error)
- func (client GlideClient) BitCount(key string) (int64, error)
- func (client GlideClient) BitCountWithOptions(key string, opts options.BitCountOptions) (int64, error)
- func (client GlideClient) BitField(key string, subCommands []options.BitFieldSubCommands) ([]Result[int64], error)
- func (client GlideClient) BitFieldRO(key string, commands []options.BitFieldROCommands) ([]Result[int64], error)
- func (client GlideClient) Close()
- func (client *GlideClient) ConfigGet(args []string) (map[string]string, error)
- func (client *GlideClient) ConfigSet(parameters map[string]string) (string, error)
- func (client GlideClient) Copy(source string, destination string) (bool, error)
- func (client GlideClient) CopyWithOptions(source string, destination string, options options.CopyOptions) (bool, error)
- func (client *GlideClient) CustomCommand(args []string) (interface{}, error)
- func (client *GlideClient) DBSize() (int64, error)
- func (client GlideClient) Decr(key string) (int64, error)
- func (client GlideClient) DecrBy(key string, amount int64) (int64, error)
- func (client GlideClient) Del(keys []string) (int64, error)
- func (client GlideClient) Dump(key string) (Result[string], error)
- func (client *GlideClient) Echo(message string) (Result[string], error)
- func (client GlideClient) Exists(keys []string) (int64, error)
- func (client GlideClient) Expire(key string, seconds int64) (bool, error)
- func (client GlideClient) ExpireAt(key string, unixTimestampInSeconds int64) (bool, error)
- func (client GlideClient) ExpireAtWithOptions(key string, unixTimestampInSeconds int64, ...) (bool, error)
- func (client GlideClient) ExpireTime(key string) (int64, error)
- func (client GlideClient) ExpireWithOptions(key string, seconds int64, expireCondition options.ExpireCondition) (bool, error)
- func (client GlideClient) Get(key string) (Result[string], error)
- func (client GlideClient) GetBit(key string, offset int64) (int64, error)
- func (client GlideClient) GetDel(key string) (Result[string], error)
- func (client GlideClient) GetEx(key string) (Result[string], error)
- func (client GlideClient) GetExWithOptions(key string, options options.GetExOptions) (Result[string], error)
- func (client GlideClient) GetRange(key string, start int, end int) (string, error)
- func (client GlideClient) HDel(key string, fields []string) (int64, error)
- func (client GlideClient) HExists(key string, field string) (bool, error)
- func (client GlideClient) HGet(key string, field string) (Result[string], error)
- func (client GlideClient) HGetAll(key string) (map[string]string, error)
- func (client GlideClient) HIncrBy(key string, field string, increment int64) (int64, error)
- func (client GlideClient) HIncrByFloat(key string, field string, increment float64) (float64, error)
- func (client GlideClient) HKeys(key string) ([]string, error)
- func (client GlideClient) HLen(key string) (int64, error)
- func (client GlideClient) HMGet(key string, fields []string) ([]Result[string], error)
- func (client GlideClient) HRandField(key string) (Result[string], error)
- func (client GlideClient) HRandFieldWithCount(key string, count int64) ([]string, error)
- func (client GlideClient) HRandFieldWithCountWithValues(key string, count int64) ([][]string, error)
- func (client GlideClient) HScan(key string, cursor string) (string, []string, error)
- func (client GlideClient) HScanWithOptions(key string, cursor string, options options.HashScanOptions) (string, []string, error)
- func (client GlideClient) HSet(key string, values map[string]string) (int64, error)
- func (client GlideClient) HSetNX(key string, field string, value string) (bool, error)
- func (client GlideClient) HStrLen(key string, field string) (int64, error)
- func (client GlideClient) HVals(key string) ([]string, error)
- func (client GlideClient) Incr(key string) (int64, error)
- func (client GlideClient) IncrBy(key string, amount int64) (int64, error)
- func (client GlideClient) IncrByFloat(key string, amount float64) (float64, error)
- func (client *GlideClient) Info() (string, error)
- func (client *GlideClient) InfoWithOptions(options options.InfoOptions) (string, error)
- func (client GlideClient) LCS(key1 string, key2 string) (string, error)
- func (client GlideClient) LIndex(key string, index int64) (Result[string], error)
- func (client GlideClient) LInsert(key string, insertPosition options.InsertPosition, pivot string, ...) (int64, error)
- func (client GlideClient) LLen(key string) (int64, error)
- func (client GlideClient) LMPop(keys []string, listDirection options.ListDirection) (map[string][]string, error)
- func (client GlideClient) LMPopCount(keys []string, listDirection options.ListDirection, count int64) (map[string][]string, error)
- func (client GlideClient) LMove(source string, destination string, whereFrom options.ListDirection, ...) (Result[string], error)
- func (client GlideClient) LPop(key string) (Result[string], error)
- func (client GlideClient) LPopCount(key string, count int64) ([]string, error)
- func (client GlideClient) LPos(key string, element string) (Result[int64], error)
- func (client GlideClient) LPosCount(key string, element string, count int64) ([]int64, error)
- func (client GlideClient) LPosCountWithOptions(key string, element string, count int64, opts options.LPosOptions) ([]int64, error)
- func (client GlideClient) LPosWithOptions(key string, element string, options options.LPosOptions) (Result[int64], error)
- func (client GlideClient) LPush(key string, elements []string) (int64, error)
- func (client GlideClient) LPushX(key string, elements []string) (int64, error)
- func (client GlideClient) LRange(key string, start int64, end int64) ([]string, error)
- func (client GlideClient) LRem(key string, count int64, element string) (int64, error)
- func (client GlideClient) LSet(key string, index int64, element string) (string, error)
- func (client GlideClient) LTrim(key string, start int64, end int64) (string, error)
- func (client GlideClient) MGet(keys []string) ([]Result[string], error)
- func (client GlideClient) MSet(keyValueMap map[string]string) (string, error)
- func (client GlideClient) MSetNX(keyValueMap map[string]string) (bool, error)
- func (client GlideClient) ObjectEncoding(key string) (Result[string], error)
- func (client GlideClient) ObjectFreq(key string) (Result[int64], error)
- func (client GlideClient) ObjectIdleTime(key string) (Result[int64], error)
- func (client GlideClient) ObjectRefCount(key string) (Result[int64], error)
- func (client GlideClient) PExpire(key string, milliseconds int64) (bool, error)
- func (client GlideClient) PExpireAt(key string, unixTimestampInMilliSeconds int64) (bool, error)
- func (client GlideClient) PExpireAtWithOptions(key string, unixTimestampInMilliSeconds int64, ...) (bool, error)
- func (client GlideClient) PExpireTime(key string) (int64, error)
- func (client GlideClient) PExpireWithOptions(key string, milliseconds int64, expireCondition options.ExpireCondition) (bool, error)
- func (client GlideClient) PTTL(key string) (int64, error)
- func (client GlideClient) Persist(key string) (bool, error)
- func (client GlideClient) PfAdd(key string, elements []string) (int64, error)
- func (client GlideClient) PfCount(keys []string) (int64, error)
- func (client *GlideClient) Ping() (string, error)
- func (client *GlideClient) PingWithOptions(pingOptions options.PingOptions) (string, error)
- func (client GlideClient) RPop(key string) (Result[string], error)
- func (client GlideClient) RPopCount(key string, count int64) ([]string, error)
- func (client GlideClient) RPush(key string, elements []string) (int64, error)
- func (client GlideClient) RPushX(key string, elements []string) (int64, error)
- func (client GlideClient) Rename(key string, newKey string) (string, error)
- func (client GlideClient) RenameNX(key string, newKey string) (bool, error)
- func (client GlideClient) Restore(key string, ttl int64, value string) (Result[string], error)
- func (client GlideClient) RestoreWithOptions(key string, ttl int64, value string, options options.RestoreOptions) (Result[string], error)
- func (client GlideClient) SAdd(key string, members []string) (int64, error)
- func (client GlideClient) SCard(key string) (int64, error)
- func (client GlideClient) SDiff(keys []string) (map[string]struct{}, error)
- func (client GlideClient) SDiffStore(destination string, keys []string) (int64, error)
- func (client GlideClient) SInter(keys []string) (map[string]struct{}, error)
- func (client GlideClient) SInterCard(keys []string) (int64, error)
- func (client GlideClient) SInterCardLimit(keys []string, limit int64) (int64, error)
- func (client GlideClient) SInterStore(destination string, keys []string) (int64, error)
- func (client GlideClient) SIsMember(key string, member string) (bool, error)
- func (client GlideClient) SMIsMember(key string, members []string) ([]bool, error)
- func (client GlideClient) SMembers(key string) (map[string]struct{}, error)
- func (client GlideClient) SMove(source string, destination string, member string) (bool, error)
- func (client GlideClient) SPop(key string) (Result[string], error)
- func (client GlideClient) SRandMember(key string) (Result[string], error)
- func (client GlideClient) SRem(key string, members []string) (int64, error)
- func (client GlideClient) SScan(key string, cursor string) (string, []string, error)
- func (client GlideClient) SScanWithOptions(key string, cursor string, options options.BaseScanOptions) (string, []string, error)
- func (client GlideClient) SUnion(keys []string) (map[string]struct{}, error)
- func (client GlideClient) SUnionStore(destination string, keys []string) (int64, error)
- func (client *GlideClient) Select(index int64) (string, error)
- func (client GlideClient) Set(key string, value string) (string, error)
- func (client GlideClient) SetBit(key string, offset int64, value int64) (int64, error)
- func (client GlideClient) SetRange(key string, offset int, value string) (int64, error)
- func (client GlideClient) SetWithOptions(key string, value string, options options.SetOptions) (Result[string], error)
- func (client GlideClient) Sort(key string) ([]Result[string], error)
- func (client GlideClient) SortReadOnly(key string) ([]Result[string], error)
- func (client GlideClient) SortReadOnlyWithOptions(key string, options options.SortOptions) ([]Result[string], error)
- func (client GlideClient) SortStore(key string, destination string) (int64, error)
- func (client GlideClient) SortStoreWithOptions(key string, destination string, opts options.SortOptions) (int64, error)
- func (client GlideClient) SortWithOptions(key string, options options.SortOptions) ([]Result[string], error)
- func (client GlideClient) Strlen(key string) (int64, error)
- func (client GlideClient) TTL(key string) (int64, error)
- func (client GlideClient) Time() ([]string, error)
- func (client GlideClient) Touch(keys []string) (int64, error)
- func (client GlideClient) Type(key string) (string, error)
- func (client GlideClient) Unlink(keys []string) (int64, error)
- func (client GlideClient) Wait(numberOfReplicas int64, timeout int64) (int64, error)
- func (client GlideClient) XAck(key string, group string, ids []string) (int64, error)
- func (client GlideClient) XAdd(key string, values [][]string) (Result[string], error)
- func (client GlideClient) XAddWithOptions(key string, values [][]string, options options.XAddOptions) (Result[string], error)
- func (client GlideClient) XAutoClaim(key string, group string, consumer string, minIdleTime int64, start string) (XAutoClaimResponse, error)
- func (client GlideClient) XAutoClaimJustId(key string, group string, consumer string, minIdleTime int64, start string) (XAutoClaimJustIdResponse, error)
- func (client GlideClient) XAutoClaimJustIdWithOptions(key string, group string, consumer string, minIdleTime int64, start string, ...) (XAutoClaimJustIdResponse, error)
- func (client GlideClient) XAutoClaimWithOptions(key string, group string, consumer string, minIdleTime int64, start string, ...) (XAutoClaimResponse, error)
- func (client GlideClient) XClaim(key string, group string, consumer string, minIdleTime int64, ids []string) (map[string][][]string, error)
- func (client GlideClient) XClaimJustId(key string, group string, consumer string, minIdleTime int64, ids []string) ([]string, error)
- func (client GlideClient) XClaimJustIdWithOptions(key string, group string, consumer string, minIdleTime int64, ids []string, ...) ([]string, error)
- func (client GlideClient) XClaimWithOptions(key string, group string, consumer string, minIdleTime int64, ids []string, ...) (map[string][][]string, error)
- func (client GlideClient) XDel(key string, ids []string) (int64, error)
- func (client GlideClient) XGroupCreate(key string, group string, id string) (string, error)
- func (client GlideClient) XGroupCreateConsumer(key string, group string, consumer string) (bool, error)
- func (client GlideClient) XGroupCreateWithOptions(key string, group string, id string, opts options.XGroupCreateOptions) (string, error)
- func (client GlideClient) XGroupDelConsumer(key string, group string, consumer string) (int64, error)
- func (client GlideClient) XGroupDestroy(key string, group string) (bool, error)
- func (client GlideClient) XGroupSetId(key string, group string, id string) (string, error)
- func (client GlideClient) XGroupSetIdWithOptions(key string, group string, id string, opts options.XGroupSetIdOptions) (string, error)
- func (client GlideClient) XLen(key string) (int64, error)
- func (client GlideClient) XPending(key string, group string) (XPendingSummary, error)
- func (client GlideClient) XPendingWithOptions(key string, group string, opts options.XPendingOptions) ([]XPendingDetail, error)
- func (client GlideClient) XRange(key string, start options.StreamBoundary, end options.StreamBoundary) ([]XRangeResponse, error)
- func (client GlideClient) XRangeWithOptions(key string, start options.StreamBoundary, end options.StreamBoundary, ...) ([]XRangeResponse, error)
- func (client GlideClient) XRead(keysAndIds map[string]string) (map[string]map[string][][]string, error)
- func (client GlideClient) XReadGroup(group string, consumer string, keysAndIds map[string]string) (map[string]map[string][][]string, error)
- func (client GlideClient) XReadGroupWithOptions(group string, consumer string, keysAndIds map[string]string, ...) (map[string]map[string][][]string, error)
- func (client GlideClient) XReadWithOptions(keysAndIds map[string]string, opts options.XReadOptions) (map[string]map[string][][]string, error)
- func (client GlideClient) XRevRange(key string, start options.StreamBoundary, end options.StreamBoundary) ([]XRangeResponse, error)
- func (client GlideClient) XRevRangeWithOptions(key string, start options.StreamBoundary, end options.StreamBoundary, ...) ([]XRangeResponse, error)
- func (client GlideClient) XTrim(key string, options options.XTrimOptions) (int64, error)
- func (client GlideClient) ZAdd(key string, membersScoreMap map[string]float64) (int64, error)
- func (client GlideClient) ZAddIncr(key string, member string, increment float64) (Result[float64], error)
- func (client GlideClient) ZAddIncrWithOptions(key string, member string, increment float64, opts options.ZAddOptions) (Result[float64], error)
- func (client GlideClient) ZAddWithOptions(key string, membersScoreMap map[string]float64, opts options.ZAddOptions) (int64, error)
- func (client GlideClient) ZCard(key string) (int64, error)
- func (client GlideClient) ZCount(key string, rangeOptions options.ZCountRange) (int64, error)
- func (client GlideClient) ZDiff(keys []string) ([]string, error)
- func (client GlideClient) ZDiffStore(destination string, keys []string) (int64, error)
- func (client GlideClient) ZDiffWithScores(keys []string) (map[string]float64, error)
- func (client GlideClient) ZIncrBy(key string, increment float64, member string) (float64, error)
- func (client GlideClient) ZInter(keys options.KeyArray) ([]string, error)
- func (client GlideClient) ZInterStore(destination string, keysOrWeightedKeys options.KeysOrWeightedKeys) (int64, error)
- func (client GlideClient) ZInterStoreWithOptions(destination string, keysOrWeightedKeys options.KeysOrWeightedKeys, ...) (int64, error)
- func (client GlideClient) ZInterWithScores(keysOrWeightedKeys options.KeysOrWeightedKeys, ...) (map[string]float64, error)
- func (client GlideClient) ZMScore(key string, members []string) ([]Result[float64], error)
- func (client GlideClient) ZPopMax(key string) (map[string]float64, error)
- func (client GlideClient) ZPopMaxWithOptions(key string, options options.ZPopOptions) (map[string]float64, error)
- func (client GlideClient) ZPopMin(key string) (map[string]float64, error)
- func (client GlideClient) ZPopMinWithOptions(key string, options options.ZPopOptions) (map[string]float64, error)
- func (client GlideClient) ZRandMember(key string) (Result[string], error)
- func (client GlideClient) ZRandMemberWithCount(key string, count int64) ([]string, error)
- func (client GlideClient) ZRandMemberWithCountWithScores(key string, count int64) ([]MemberAndScore, error)
- func (client GlideClient) ZRange(key string, rangeQuery options.ZRangeQuery) ([]string, error)
- func (client GlideClient) ZRangeWithScores(key string, rangeQuery options.ZRangeQueryWithScores) ([]MemberAndScore, error)
- func (client GlideClient) ZRank(key string, member string) (Result[int64], error)
- func (client GlideClient) ZRankWithScore(key string, member string) (Result[int64], Result[float64], error)
- func (client GlideClient) ZRem(key string, members []string) (int64, error)
- func (client GlideClient) ZRemRangeByLex(key string, rangeQuery options.RangeByLex) (int64, error)
- func (client GlideClient) ZRemRangeByRank(key string, start int64, stop int64) (int64, error)
- func (client GlideClient) ZRemRangeByScore(key string, rangeQuery options.RangeByScore) (int64, error)
- func (client GlideClient) ZRevRank(key string, member string) (Result[int64], error)
- func (client GlideClient) ZRevRankWithScore(key string, member string) (Result[int64], Result[float64], error)
- func (client GlideClient) ZScan(key string, cursor string) (string, []string, error)
- func (client GlideClient) ZScanWithOptions(key string, cursor string, options options.ZScanOptions) (string, []string, error)
- func (client GlideClient) ZScore(key string, member string) (Result[float64], error)
- type GlideClientCommands
- type GlideClientConfiguration
- func (config *GlideClientConfiguration) WithAddress(address *NodeAddress) *GlideClientConfiguration
- func (config *GlideClientConfiguration) WithClientName(clientName string) *GlideClientConfiguration
- func (config *GlideClientConfiguration) WithCredentials(credentials *ServerCredentials) *GlideClientConfiguration
- func (config *GlideClientConfiguration) WithDatabaseId(id int) *GlideClientConfiguration
- func (config *GlideClientConfiguration) WithReadFrom(readFrom ReadFrom) *GlideClientConfiguration
- func (config *GlideClientConfiguration) WithReconnectStrategy(strategy *BackoffStrategy) *GlideClientConfiguration
- func (config *GlideClientConfiguration) WithRequestTimeout(requestTimeout int) *GlideClientConfiguration
- func (config *GlideClientConfiguration) WithUseTLS(useTLS bool) *GlideClientConfiguration
- type GlideClusterClient
- func (client GlideClusterClient) Append(key string, value string) (int64, error)
- func (client GlideClusterClient) BLMPop(keys []string, listDirection options.ListDirection, timeoutSecs float64) (map[string][]string, error)
- func (client GlideClusterClient) BLMPopCount(keys []string, listDirection options.ListDirection, count int64, ...) (map[string][]string, error)
- func (client GlideClusterClient) BLMove(source string, destination string, whereFrom options.ListDirection, ...) (Result[string], error)
- func (client GlideClusterClient) BLPop(keys []string, timeoutSecs float64) ([]string, error)
- func (client GlideClusterClient) BRPop(keys []string, timeoutSecs float64) ([]string, error)
- func (client GlideClusterClient) BZMPop(keys []string, scoreFilter options.ScoreFilter, timeoutSecs float64) (Result[KeyWithArrayOfMembersAndScores], error)
- func (client GlideClusterClient) BZMPopWithOptions(keys []string, scoreFilter options.ScoreFilter, timeoutSecs float64, ...) (Result[KeyWithArrayOfMembersAndScores], error)
- func (client GlideClusterClient) BZPopMin(keys []string, timeoutSecs float64) (Result[KeyWithMemberAndScore], error)
- func (client GlideClusterClient) BitCount(key string) (int64, error)
- func (client GlideClusterClient) BitCountWithOptions(key string, opts options.BitCountOptions) (int64, error)
- func (client GlideClusterClient) BitField(key string, subCommands []options.BitFieldSubCommands) ([]Result[int64], error)
- func (client GlideClusterClient) BitFieldRO(key string, commands []options.BitFieldROCommands) ([]Result[int64], error)
- func (client GlideClusterClient) Close()
- func (client GlideClusterClient) Copy(source string, destination string) (bool, error)
- func (client GlideClusterClient) CopyWithOptions(source string, destination string, options options.CopyOptions) (bool, error)
- func (client *GlideClusterClient) CustomCommand(args []string) (ClusterValue[interface{}], error)
- func (client *GlideClusterClient) CustomCommandWithRoute(args []string, route config.Route) (ClusterValue[interface{}], error)
- func (client *GlideClusterClient) DBSizeWithOptions(opts options.RouteOption) (int64, error)
- func (client GlideClusterClient) Decr(key string) (int64, error)
- func (client GlideClusterClient) DecrBy(key string, amount int64) (int64, error)
- func (client GlideClusterClient) Del(keys []string) (int64, error)
- func (client GlideClusterClient) Dump(key string) (Result[string], error)
- func (client GlideClusterClient) Echo(message string) (Result[string], error)
- func (client *GlideClusterClient) EchoWithOptions(echoOptions options.ClusterEchoOptions) (ClusterValue[string], error)
- func (client GlideClusterClient) Exists(keys []string) (int64, error)
- func (client GlideClusterClient) Expire(key string, seconds int64) (bool, error)
- func (client GlideClusterClient) ExpireAt(key string, unixTimestampInSeconds int64) (bool, error)
- func (client GlideClusterClient) ExpireAtWithOptions(key string, unixTimestampInSeconds int64, ...) (bool, error)
- func (client GlideClusterClient) ExpireTime(key string) (int64, error)
- func (client GlideClusterClient) ExpireWithOptions(key string, seconds int64, expireCondition options.ExpireCondition) (bool, error)
- func (client GlideClusterClient) Get(key string) (Result[string], error)
- func (client GlideClusterClient) GetBit(key string, offset int64) (int64, error)
- func (client GlideClusterClient) GetDel(key string) (Result[string], error)
- func (client GlideClusterClient) GetEx(key string) (Result[string], error)
- func (client GlideClusterClient) GetExWithOptions(key string, options options.GetExOptions) (Result[string], error)
- func (client GlideClusterClient) GetRange(key string, start int, end int) (string, error)
- func (client GlideClusterClient) HDel(key string, fields []string) (int64, error)
- func (client GlideClusterClient) HExists(key string, field string) (bool, error)
- func (client GlideClusterClient) HGet(key string, field string) (Result[string], error)
- func (client GlideClusterClient) HGetAll(key string) (map[string]string, error)
- func (client GlideClusterClient) HIncrBy(key string, field string, increment int64) (int64, error)
- func (client GlideClusterClient) HIncrByFloat(key string, field string, increment float64) (float64, error)
- func (client GlideClusterClient) HKeys(key string) ([]string, error)
- func (client GlideClusterClient) HLen(key string) (int64, error)
- func (client GlideClusterClient) HMGet(key string, fields []string) ([]Result[string], error)
- func (client GlideClusterClient) HRandField(key string) (Result[string], error)
- func (client GlideClusterClient) HRandFieldWithCount(key string, count int64) ([]string, error)
- func (client GlideClusterClient) HRandFieldWithCountWithValues(key string, count int64) ([][]string, error)
- func (client GlideClusterClient) HScan(key string, cursor string) (string, []string, error)
- func (client GlideClusterClient) HScanWithOptions(key string, cursor string, options options.HashScanOptions) (string, []string, error)
- func (client GlideClusterClient) HSet(key string, values map[string]string) (int64, error)
- func (client GlideClusterClient) HSetNX(key string, field string, value string) (bool, error)
- func (client GlideClusterClient) HStrLen(key string, field string) (int64, error)
- func (client GlideClusterClient) HVals(key string) ([]string, error)
- func (client GlideClusterClient) Incr(key string) (int64, error)
- func (client GlideClusterClient) IncrBy(key string, amount int64) (int64, error)
- func (client GlideClusterClient) IncrByFloat(key string, amount float64) (float64, error)
- func (client *GlideClusterClient) Info() (map[string]string, error)
- func (client *GlideClusterClient) InfoWithOptions(options options.ClusterInfoOptions) (ClusterValue[string], error)
- func (client GlideClusterClient) LCS(key1 string, key2 string) (string, error)
- func (client GlideClusterClient) LIndex(key string, index int64) (Result[string], error)
- func (client GlideClusterClient) LInsert(key string, insertPosition options.InsertPosition, pivot string, ...) (int64, error)
- func (client GlideClusterClient) LLen(key string) (int64, error)
- func (client GlideClusterClient) LMPop(keys []string, listDirection options.ListDirection) (map[string][]string, error)
- func (client GlideClusterClient) LMPopCount(keys []string, listDirection options.ListDirection, count int64) (map[string][]string, error)
- func (client GlideClusterClient) LMove(source string, destination string, whereFrom options.ListDirection, ...) (Result[string], error)
- func (client GlideClusterClient) LPop(key string) (Result[string], error)
- func (client GlideClusterClient) LPopCount(key string, count int64) ([]string, error)
- func (client GlideClusterClient) LPos(key string, element string) (Result[int64], error)
- func (client GlideClusterClient) LPosCount(key string, element string, count int64) ([]int64, error)
- func (client GlideClusterClient) LPosCountWithOptions(key string, element string, count int64, opts options.LPosOptions) ([]int64, error)
- func (client GlideClusterClient) LPosWithOptions(key string, element string, options options.LPosOptions) (Result[int64], error)
- func (client GlideClusterClient) LPush(key string, elements []string) (int64, error)
- func (client GlideClusterClient) LPushX(key string, elements []string) (int64, error)
- func (client GlideClusterClient) LRange(key string, start int64, end int64) ([]string, error)
- func (client GlideClusterClient) LRem(key string, count int64, element string) (int64, error)
- func (client GlideClusterClient) LSet(key string, index int64, element string) (string, error)
- func (client GlideClusterClient) LTrim(key string, start int64, end int64) (string, error)
- func (client GlideClusterClient) MGet(keys []string) ([]Result[string], error)
- func (client GlideClusterClient) MSet(keyValueMap map[string]string) (string, error)
- func (client GlideClusterClient) MSetNX(keyValueMap map[string]string) (bool, error)
- func (client GlideClusterClient) ObjectEncoding(key string) (Result[string], error)
- func (client GlideClusterClient) ObjectFreq(key string) (Result[int64], error)
- func (client GlideClusterClient) ObjectIdleTime(key string) (Result[int64], error)
- func (client GlideClusterClient) ObjectRefCount(key string) (Result[int64], error)
- func (client GlideClusterClient) PExpire(key string, milliseconds int64) (bool, error)
- func (client GlideClusterClient) PExpireAt(key string, unixTimestampInMilliSeconds int64) (bool, error)
- func (client GlideClusterClient) PExpireAtWithOptions(key string, unixTimestampInMilliSeconds int64, ...) (bool, error)
- func (client GlideClusterClient) PExpireTime(key string) (int64, error)
- func (client GlideClusterClient) PExpireWithOptions(key string, milliseconds int64, expireCondition options.ExpireCondition) (bool, error)
- func (client GlideClusterClient) PTTL(key string) (int64, error)
- func (client GlideClusterClient) Persist(key string) (bool, error)
- func (client GlideClusterClient) PfAdd(key string, elements []string) (int64, error)
- func (client GlideClusterClient) PfCount(keys []string) (int64, error)
- func (client *GlideClusterClient) Ping() (string, error)
- func (client *GlideClusterClient) PingWithOptions(pingOptions options.ClusterPingOptions) (string, error)
- func (client GlideClusterClient) RPop(key string) (Result[string], error)
- func (client GlideClusterClient) RPopCount(key string, count int64) ([]string, error)
- func (client GlideClusterClient) RPush(key string, elements []string) (int64, error)
- func (client GlideClusterClient) RPushX(key string, elements []string) (int64, error)
- func (client GlideClusterClient) Rename(key string, newKey string) (string, error)
- func (client GlideClusterClient) RenameNX(key string, newKey string) (bool, error)
- func (client GlideClusterClient) Restore(key string, ttl int64, value string) (Result[string], error)
- func (client GlideClusterClient) RestoreWithOptions(key string, ttl int64, value string, options options.RestoreOptions) (Result[string], error)
- func (client GlideClusterClient) SAdd(key string, members []string) (int64, error)
- func (client GlideClusterClient) SCard(key string) (int64, error)
- func (client GlideClusterClient) SDiff(keys []string) (map[string]struct{}, error)
- func (client GlideClusterClient) SDiffStore(destination string, keys []string) (int64, error)
- func (client GlideClusterClient) SInter(keys []string) (map[string]struct{}, error)
- func (client GlideClusterClient) SInterCard(keys []string) (int64, error)
- func (client GlideClusterClient) SInterCardLimit(keys []string, limit int64) (int64, error)
- func (client GlideClusterClient) SInterStore(destination string, keys []string) (int64, error)
- func (client GlideClusterClient) SIsMember(key string, member string) (bool, error)
- func (client GlideClusterClient) SMIsMember(key string, members []string) ([]bool, error)
- func (client GlideClusterClient) SMembers(key string) (map[string]struct{}, error)
- func (client GlideClusterClient) SMove(source string, destination string, member string) (bool, error)
- func (client GlideClusterClient) SPop(key string) (Result[string], error)
- func (client GlideClusterClient) SRandMember(key string) (Result[string], error)
- func (client GlideClusterClient) SRem(key string, members []string) (int64, error)
- func (client GlideClusterClient) SScan(key string, cursor string) (string, []string, error)
- func (client GlideClusterClient) SScanWithOptions(key string, cursor string, options options.BaseScanOptions) (string, []string, error)
- func (client GlideClusterClient) SUnion(keys []string) (map[string]struct{}, error)
- func (client GlideClusterClient) SUnionStore(destination string, keys []string) (int64, error)
- func (client GlideClusterClient) Set(key string, value string) (string, error)
- func (client GlideClusterClient) SetBit(key string, offset int64, value int64) (int64, error)
- func (client GlideClusterClient) SetRange(key string, offset int, value string) (int64, error)
- func (client GlideClusterClient) SetWithOptions(key string, value string, options options.SetOptions) (Result[string], error)
- func (client GlideClusterClient) Sort(key string) ([]Result[string], error)
- func (client GlideClusterClient) SortReadOnly(key string) ([]Result[string], error)
- func (client GlideClusterClient) SortReadOnlyWithOptions(key string, options options.SortOptions) ([]Result[string], error)
- func (client GlideClusterClient) SortStore(key string, destination string) (int64, error)
- func (client GlideClusterClient) SortStoreWithOptions(key string, destination string, opts options.SortOptions) (int64, error)
- func (client GlideClusterClient) SortWithOptions(key string, options options.SortOptions) ([]Result[string], error)
- func (client GlideClusterClient) Strlen(key string) (int64, error)
- func (client GlideClusterClient) TTL(key string) (int64, error)
- func (client GlideClusterClient) Time() ([]string, error)
- func (client *GlideClusterClient) TimeWithOptions(opts options.RouteOption) (ClusterValue[[]string], error)
- func (client GlideClusterClient) Touch(keys []string) (int64, error)
- func (client GlideClusterClient) Type(key string) (string, error)
- func (client GlideClusterClient) Unlink(keys []string) (int64, error)
- func (client GlideClusterClient) Wait(numberOfReplicas int64, timeout int64) (int64, error)
- func (client GlideClusterClient) XAck(key string, group string, ids []string) (int64, error)
- func (client GlideClusterClient) XAdd(key string, values [][]string) (Result[string], error)
- func (client GlideClusterClient) XAddWithOptions(key string, values [][]string, options options.XAddOptions) (Result[string], error)
- func (client GlideClusterClient) XAutoClaim(key string, group string, consumer string, minIdleTime int64, start string) (XAutoClaimResponse, error)
- func (client GlideClusterClient) XAutoClaimJustId(key string, group string, consumer string, minIdleTime int64, start string) (XAutoClaimJustIdResponse, error)
- func (client GlideClusterClient) XAutoClaimJustIdWithOptions(key string, group string, consumer string, minIdleTime int64, start string, ...) (XAutoClaimJustIdResponse, error)
- func (client GlideClusterClient) XAutoClaimWithOptions(key string, group string, consumer string, minIdleTime int64, start string, ...) (XAutoClaimResponse, error)
- func (client GlideClusterClient) XClaim(key string, group string, consumer string, minIdleTime int64, ids []string) (map[string][][]string, error)
- func (client GlideClusterClient) XClaimJustId(key string, group string, consumer string, minIdleTime int64, ids []string) ([]string, error)
- func (client GlideClusterClient) XClaimJustIdWithOptions(key string, group string, consumer string, minIdleTime int64, ids []string, ...) ([]string, error)
- func (client GlideClusterClient) XClaimWithOptions(key string, group string, consumer string, minIdleTime int64, ids []string, ...) (map[string][][]string, error)
- func (client GlideClusterClient) XDel(key string, ids []string) (int64, error)
- func (client GlideClusterClient) XGroupCreate(key string, group string, id string) (string, error)
- func (client GlideClusterClient) XGroupCreateConsumer(key string, group string, consumer string) (bool, error)
- func (client GlideClusterClient) XGroupCreateWithOptions(key string, group string, id string, opts options.XGroupCreateOptions) (string, error)
- func (client GlideClusterClient) XGroupDelConsumer(key string, group string, consumer string) (int64, error)
- func (client GlideClusterClient) XGroupDestroy(key string, group string) (bool, error)
- func (client GlideClusterClient) XGroupSetId(key string, group string, id string) (string, error)
- func (client GlideClusterClient) XGroupSetIdWithOptions(key string, group string, id string, opts options.XGroupSetIdOptions) (string, error)
- func (client GlideClusterClient) XLen(key string) (int64, error)
- func (client GlideClusterClient) XPending(key string, group string) (XPendingSummary, error)
- func (client GlideClusterClient) XPendingWithOptions(key string, group string, opts options.XPendingOptions) ([]XPendingDetail, error)
- func (client GlideClusterClient) XRange(key string, start options.StreamBoundary, end options.StreamBoundary) ([]XRangeResponse, error)
- func (client GlideClusterClient) XRangeWithOptions(key string, start options.StreamBoundary, end options.StreamBoundary, ...) ([]XRangeResponse, error)
- func (client GlideClusterClient) XRead(keysAndIds map[string]string) (map[string]map[string][][]string, error)
- func (client GlideClusterClient) XReadGroup(group string, consumer string, keysAndIds map[string]string) (map[string]map[string][][]string, error)
- func (client GlideClusterClient) XReadGroupWithOptions(group string, consumer string, keysAndIds map[string]string, ...) (map[string]map[string][][]string, error)
- func (client GlideClusterClient) XReadWithOptions(keysAndIds map[string]string, opts options.XReadOptions) (map[string]map[string][][]string, error)
- func (client GlideClusterClient) XRevRange(key string, start options.StreamBoundary, end options.StreamBoundary) ([]XRangeResponse, error)
- func (client GlideClusterClient) XRevRangeWithOptions(key string, start options.StreamBoundary, end options.StreamBoundary, ...) ([]XRangeResponse, error)
- func (client GlideClusterClient) XTrim(key string, options options.XTrimOptions) (int64, error)
- func (client GlideClusterClient) ZAdd(key string, membersScoreMap map[string]float64) (int64, error)
- func (client GlideClusterClient) ZAddIncr(key string, member string, increment float64) (Result[float64], error)
- func (client GlideClusterClient) ZAddIncrWithOptions(key string, member string, increment float64, opts options.ZAddOptions) (Result[float64], error)
- func (client GlideClusterClient) ZAddWithOptions(key string, membersScoreMap map[string]float64, opts options.ZAddOptions) (int64, error)
- func (client GlideClusterClient) ZCard(key string) (int64, error)
- func (client GlideClusterClient) ZCount(key string, rangeOptions options.ZCountRange) (int64, error)
- func (client GlideClusterClient) ZDiff(keys []string) ([]string, error)
- func (client GlideClusterClient) ZDiffStore(destination string, keys []string) (int64, error)
- func (client GlideClusterClient) ZDiffWithScores(keys []string) (map[string]float64, error)
- func (client GlideClusterClient) ZIncrBy(key string, increment float64, member string) (float64, error)
- func (client GlideClusterClient) ZInter(keys options.KeyArray) ([]string, error)
- func (client GlideClusterClient) ZInterStore(destination string, keysOrWeightedKeys options.KeysOrWeightedKeys) (int64, error)
- func (client GlideClusterClient) ZInterStoreWithOptions(destination string, keysOrWeightedKeys options.KeysOrWeightedKeys, ...) (int64, error)
- func (client GlideClusterClient) ZInterWithScores(keysOrWeightedKeys options.KeysOrWeightedKeys, ...) (map[string]float64, error)
- func (client GlideClusterClient) ZMScore(key string, members []string) ([]Result[float64], error)
- func (client GlideClusterClient) ZPopMax(key string) (map[string]float64, error)
- func (client GlideClusterClient) ZPopMaxWithOptions(key string, options options.ZPopOptions) (map[string]float64, error)
- func (client GlideClusterClient) ZPopMin(key string) (map[string]float64, error)
- func (client GlideClusterClient) ZPopMinWithOptions(key string, options options.ZPopOptions) (map[string]float64, error)
- func (client GlideClusterClient) ZRandMember(key string) (Result[string], error)
- func (client GlideClusterClient) ZRandMemberWithCount(key string, count int64) ([]string, error)
- func (client GlideClusterClient) ZRandMemberWithCountWithScores(key string, count int64) ([]MemberAndScore, error)
- func (client GlideClusterClient) ZRange(key string, rangeQuery options.ZRangeQuery) ([]string, error)
- func (client GlideClusterClient) ZRangeWithScores(key string, rangeQuery options.ZRangeQueryWithScores) ([]MemberAndScore, error)
- func (client GlideClusterClient) ZRank(key string, member string) (Result[int64], error)
- func (client GlideClusterClient) ZRankWithScore(key string, member string) (Result[int64], Result[float64], error)
- func (client GlideClusterClient) ZRem(key string, members []string) (int64, error)
- func (client GlideClusterClient) ZRemRangeByLex(key string, rangeQuery options.RangeByLex) (int64, error)
- func (client GlideClusterClient) ZRemRangeByRank(key string, start int64, stop int64) (int64, error)
- func (client GlideClusterClient) ZRemRangeByScore(key string, rangeQuery options.RangeByScore) (int64, error)
- func (client GlideClusterClient) ZRevRank(key string, member string) (Result[int64], error)
- func (client GlideClusterClient) ZRevRankWithScore(key string, member string) (Result[int64], Result[float64], error)
- func (client GlideClusterClient) ZScan(key string, cursor string) (string, []string, error)
- func (client GlideClusterClient) ZScanWithOptions(key string, cursor string, options options.ZScanOptions) (string, []string, error)
- func (client GlideClusterClient) ZScore(key string, member string) (Result[float64], error)
- type GlideClusterClientCommands
- type GlideClusterClientConfiguration
- func (config *GlideClusterClientConfiguration) WithAddress(address *NodeAddress) *GlideClusterClientConfiguration
- func (config *GlideClusterClientConfiguration) WithClientName(clientName string) *GlideClusterClientConfiguration
- func (config *GlideClusterClientConfiguration) WithCredentials(credentials *ServerCredentials) *GlideClusterClientConfiguration
- func (config *GlideClusterClientConfiguration) WithReadFrom(readFrom ReadFrom) *GlideClusterClientConfiguration
- func (config *GlideClusterClientConfiguration) WithRequestTimeout(requestTimeout int) *GlideClusterClientConfiguration
- func (config *GlideClusterClientConfiguration) WithUseTLS(useTLS bool) *GlideClusterClientConfiguration
- type HashCommands
- type HyperLogLogCommands
- type KeyWithArrayOfMembersAndScores
- type KeyWithMemberAndScore
- type ListCommands
- type MemberAndScore
- type NodeAddress
- type ReadFrom
- type Result
- func CreateFloat64Result(floatVal float64) Result[float64]
- func CreateInt64Result(intVal int64) Result[int64]
- func CreateKeyWithArrayOfMembersAndScoresResult(kmsVals KeyWithArrayOfMembersAndScores) Result[KeyWithArrayOfMembersAndScores]
- func CreateKeyWithMemberAndScoreResult(kmsVal KeyWithMemberAndScore) Result[KeyWithMemberAndScore]
- func CreateNilFloat64Result() Result[float64]
- func CreateNilInt64Result() Result[int64]
- func CreateNilKeyWithArrayOfMembersAndScoresResult() Result[KeyWithArrayOfMembersAndScores]
- func CreateNilKeyWithMemberAndScoreResult() Result[KeyWithMemberAndScore]
- func CreateNilStringResult() Result[string]
- func CreateStringResult(str string) Result[string]
- type ServerCredentials
- type ServerManagementClusterCommands
- type ServerManagementCommands
- type SetCommands
- type SortedSetCommands
- type StreamCommands
- type StringCommands
- type ValueType
- type XAutoClaimJustIdResponse
- type XAutoClaimResponse
- type XPendingDetail
- type XPendingSummary
- type XRangeResponse
Examples ¶
- GlideClient.Append
- GlideClient.BLMPop
- GlideClient.BLMPopCount
- GlideClient.BLMove
- GlideClient.BLPop
- GlideClient.BRPop
- GlideClient.BZMPop
- GlideClient.BZMPopWithOptions
- GlideClient.BZPopMin
- GlideClient.BitCount
- GlideClient.BitCountWithOptions
- GlideClient.BitField
- GlideClient.BitFieldRO
- GlideClient.ConfigGet
- GlideClient.ConfigSet
- GlideClient.Copy
- GlideClient.CopyWithOptions
- GlideClient.CustomCommand
- GlideClient.DBSize
- GlideClient.Decr
- GlideClient.DecrBy
- GlideClient.Del
- GlideClient.Dump
- GlideClient.Echo
- GlideClient.Exists
- GlideClient.Expire
- GlideClient.ExpireAt
- GlideClient.ExpireAtWithOptions
- GlideClient.ExpireTime
- GlideClient.ExpireWithOptions
- GlideClient.Get (Keyexists)
- GlideClient.Get (Keynotexists)
- GlideClient.GetBit
- GlideClient.GetDel
- GlideClient.GetEx
- GlideClient.GetExWithOptions
- GlideClient.GetRange (One)
- GlideClient.GetRange (Two)
- GlideClient.HDel
- GlideClient.HExists
- GlideClient.HGet
- GlideClient.HGetAll
- GlideClient.HIncrBy
- GlideClient.HIncrByFloat
- GlideClient.HKeys
- GlideClient.HLen
- GlideClient.HMGet
- GlideClient.HRandField
- GlideClient.HRandFieldWithCount
- GlideClient.HRandFieldWithCountWithValues
- GlideClient.HScan
- GlideClient.HScanWithOptions
- GlideClient.HSet
- GlideClient.HSetNX
- GlideClient.HStrLen
- GlideClient.HVals
- GlideClient.Incr
- GlideClient.IncrBy
- GlideClient.IncrByFloat
- GlideClient.Info
- GlideClient.InfoWithOptions
- GlideClient.LCS
- GlideClient.LIndex
- GlideClient.LInsert
- GlideClient.LLen
- GlideClient.LMPop
- GlideClient.LMPopCount
- GlideClient.LMove
- GlideClient.LPop
- GlideClient.LPopCount
- GlideClient.LPos
- GlideClient.LPosCount
- GlideClient.LPosCountWithOptions
- GlideClient.LPosWithOptions
- GlideClient.LPush
- GlideClient.LPushX
- GlideClient.LRange
- GlideClient.LRem
- GlideClient.LSet
- GlideClient.LTrim
- GlideClient.MGet
- GlideClient.MSet
- GlideClient.MSetNX
- GlideClient.ObjectEncoding
- GlideClient.ObjectFreq
- GlideClient.ObjectIdleTime
- GlideClient.ObjectRefCount
- GlideClient.PExpire
- GlideClient.PExpireAt
- GlideClient.PExpireAtWithOptions
- GlideClient.PExpireTime
- GlideClient.PExpireWithOptions
- GlideClient.PTTL
- GlideClient.Persist
- GlideClient.PfAdd
- GlideClient.PfCount
- GlideClient.Ping
- GlideClient.PingWithOptions
- GlideClient.RPop
- GlideClient.RPopCount
- GlideClient.RPush
- GlideClient.RPushX
- GlideClient.Rename
- GlideClient.RenameNX
- GlideClient.Restore
- GlideClient.RestoreWithOptions
- GlideClient.SAdd
- GlideClient.SCard
- GlideClient.SDiff
- GlideClient.SDiffStore
- GlideClient.SInter
- GlideClient.SInterCard
- GlideClient.SInterCardLimit
- GlideClient.SInterStore
- GlideClient.SIsMember
- GlideClient.SMIsMember
- GlideClient.SMembers
- GlideClient.SMove
- GlideClient.SPop
- GlideClient.SRandMember
- GlideClient.SRem
- GlideClient.SScan
- GlideClient.SScanWithOptions
- GlideClient.SUnion
- GlideClient.SUnionStore
- GlideClient.Select
- GlideClient.Set
- GlideClient.SetBit
- GlideClient.SetRange (One)
- GlideClient.SetRange (Two)
- GlideClient.SetWithOptions
- GlideClient.Sort
- GlideClient.SortReadOnly
- GlideClient.SortReadOnlyWithOptions
- GlideClient.SortStore
- GlideClient.SortStoreWithOptions
- GlideClient.SortWithOptions
- GlideClient.Strlen
- GlideClient.TTL
- GlideClient.Time
- GlideClient.Touch
- GlideClient.Type
- GlideClient.Unlink
- GlideClient.Wait
- GlideClient.XAck
- GlideClient.XAdd
- GlideClient.XAddWithOptions
- GlideClient.XAutoClaim
- GlideClient.XAutoClaimJustId
- GlideClient.XAutoClaimJustIdWithOptions
- GlideClient.XAutoClaimWithOptions
- GlideClient.XClaim
- GlideClient.XClaimJustId
- GlideClient.XClaimJustIdWithOptions
- GlideClient.XClaimWithOptions
- GlideClient.XDel
- GlideClient.XGroupCreate
- GlideClient.XGroupCreateConsumer
- GlideClient.XGroupCreateWithOptions
- GlideClient.XGroupDelConsumer
- GlideClient.XGroupDestroy
- GlideClient.XGroupSetId
- GlideClient.XGroupSetIdWithOptions
- GlideClient.XLen
- GlideClient.XPending
- GlideClient.XPendingWithOptions
- GlideClient.XRange
- GlideClient.XRangeWithOptions
- GlideClient.XRead
- GlideClient.XReadGroup
- GlideClient.XReadGroupWithOptions
- GlideClient.XReadWithOptions
- GlideClient.XRevRange
- GlideClient.XRevRangeWithOptions
- GlideClient.XTrim
- GlideClient.ZAdd
- GlideClient.ZAddIncr
- GlideClient.ZAddIncrWithOptions
- GlideClient.ZAddWithOptions
- GlideClient.ZCard
- GlideClient.ZCount
- GlideClient.ZDiff
- GlideClient.ZDiffStore
- GlideClient.ZDiffWithScores
- GlideClient.ZIncrBy
- GlideClient.ZInter
- GlideClient.ZInterStore
- GlideClient.ZInterStoreWithOptions
- GlideClient.ZInterWithScores
- GlideClient.ZMScore
- GlideClient.ZPopMax
- GlideClient.ZPopMaxWithOptions
- GlideClient.ZPopMin
- GlideClient.ZPopMinWithOptions
- GlideClient.ZRandMember
- GlideClient.ZRandMemberWithCount
- GlideClient.ZRandMemberWithCountWithScores
- GlideClient.ZRange
- GlideClient.ZRangeWithScores
- GlideClient.ZRank
- GlideClient.ZRankWithScore
- GlideClient.ZRem
- GlideClient.ZRemRangeByLex
- GlideClient.ZRemRangeByRank
- GlideClient.ZRemRangeByScore
- GlideClient.ZRevRank
- GlideClient.ZRevRankWithScore
- GlideClient.ZScan
- GlideClient.ZScanWithOptions
- GlideClient.ZScore
- GlideClusterClient.Append
- GlideClusterClient.BLMPop
- GlideClusterClient.BLMPopCount
- GlideClusterClient.BLMove
- GlideClusterClient.BLPop
- GlideClusterClient.BRPop
- GlideClusterClient.BZMPop
- GlideClusterClient.BZMPopWithOptions
- GlideClusterClient.BZPopMin
- GlideClusterClient.BitCount
- GlideClusterClient.BitCountWithOptions
- GlideClusterClient.BitField
- GlideClusterClient.BitFieldRO
- GlideClusterClient.Copy
- GlideClusterClient.CopyWithOptions
- GlideClusterClient.CustomCommand
- GlideClusterClient.CustomCommandWithRoute
- GlideClusterClient.DBSizeWithOptions
- GlideClusterClient.Decr
- GlideClusterClient.DecrBy
- GlideClusterClient.Del
- GlideClusterClient.Dump
- GlideClusterClient.Echo
- GlideClusterClient.EchoWithOptions
- GlideClusterClient.Exists
- GlideClusterClient.Expire
- GlideClusterClient.ExpireAt
- GlideClusterClient.ExpireAtWithOptions
- GlideClusterClient.ExpireTime
- GlideClusterClient.ExpireWithOptions
- GlideClusterClient.Get (Keyexists)
- GlideClusterClient.Get (Keynotexists)
- GlideClusterClient.GetBit
- GlideClusterClient.GetDel
- GlideClusterClient.GetEx
- GlideClusterClient.GetExWithOptions
- GlideClusterClient.GetRange (One)
- GlideClusterClient.GetRange (Two)
- GlideClusterClient.HDel
- GlideClusterClient.HExists
- GlideClusterClient.HGet
- GlideClusterClient.HGetAll
- GlideClusterClient.HIncrBy
- GlideClusterClient.HIncrByFloat
- GlideClusterClient.HKeys
- GlideClusterClient.HLen
- GlideClusterClient.HMGet
- GlideClusterClient.HRandField
- GlideClusterClient.HRandFieldWithCount
- GlideClusterClient.HRandFieldWithCountWithValues
- GlideClusterClient.HScan
- GlideClusterClient.HScanWithOptions
- GlideClusterClient.HSet
- GlideClusterClient.HSetNX
- GlideClusterClient.HStrLen
- GlideClusterClient.HVals
- GlideClusterClient.Incr
- GlideClusterClient.IncrBy
- GlideClusterClient.IncrByFloat
- GlideClusterClient.Info
- GlideClusterClient.InfoWithOptions
- GlideClusterClient.LCS
- GlideClusterClient.LIndex
- GlideClusterClient.LInsert
- GlideClusterClient.LLen
- GlideClusterClient.LMPop
- GlideClusterClient.LMPopCount
- GlideClusterClient.LMove
- GlideClusterClient.LPop
- GlideClusterClient.LPopCount
- GlideClusterClient.LPos
- GlideClusterClient.LPosCount
- GlideClusterClient.LPosCountWithOptions
- GlideClusterClient.LPosWithOptions
- GlideClusterClient.LPush
- GlideClusterClient.LPushX
- GlideClusterClient.LRange
- GlideClusterClient.LRem
- GlideClusterClient.LSet
- GlideClusterClient.LTrim
- GlideClusterClient.MGet
- GlideClusterClient.MSet
- GlideClusterClient.MSetNX
- GlideClusterClient.ObjectEncoding
- GlideClusterClient.ObjectFreq
- GlideClusterClient.ObjectIdleTime
- GlideClusterClient.ObjectRefCount
- GlideClusterClient.PExpire
- GlideClusterClient.PExpireAt
- GlideClusterClient.PExpireAtWithOptions
- GlideClusterClient.PExpireTime
- GlideClusterClient.PExpireWithOptions
- GlideClusterClient.PTTL
- GlideClusterClient.Persist
- GlideClusterClient.PfAdd
- GlideClusterClient.PfCount
- GlideClusterClient.Ping
- GlideClusterClient.PingWithOptions
- GlideClusterClient.RPop
- GlideClusterClient.RPopCount
- GlideClusterClient.RPush
- GlideClusterClient.RPushX
- GlideClusterClient.Rename
- GlideClusterClient.RenameNX
- GlideClusterClient.Restore
- GlideClusterClient.RestoreWithOptions
- GlideClusterClient.SAdd
- GlideClusterClient.SCard
- GlideClusterClient.SDiff
- GlideClusterClient.SDiffStore
- GlideClusterClient.SInter
- GlideClusterClient.SInterCard
- GlideClusterClient.SInterCardLimit
- GlideClusterClient.SInterStore
- GlideClusterClient.SIsMember
- GlideClusterClient.SMIsMember
- GlideClusterClient.SMembers
- GlideClusterClient.SMove
- GlideClusterClient.SPop
- GlideClusterClient.SRandMember
- GlideClusterClient.SRem
- GlideClusterClient.SScan
- GlideClusterClient.SScanWithOptions
- GlideClusterClient.SUnion
- GlideClusterClient.SUnionStore
- GlideClusterClient.Set
- GlideClusterClient.SetBit
- GlideClusterClient.SetRange (One)
- GlideClusterClient.SetRange (Two)
- GlideClusterClient.SetWithOptions
- GlideClusterClient.Sort
- GlideClusterClient.SortReadOnly
- GlideClusterClient.SortReadOnlyWithOptions
- GlideClusterClient.SortStore
- GlideClusterClient.SortStoreWithOptions
- GlideClusterClient.SortWithOptions
- GlideClusterClient.Strlen
- GlideClusterClient.TTL
- GlideClusterClient.Time
- GlideClusterClient.TimeWithOptions
- GlideClusterClient.Touch
- GlideClusterClient.Type
- GlideClusterClient.Unlink
- GlideClusterClient.Wait
- GlideClusterClient.XAck
- GlideClusterClient.XAdd
- GlideClusterClient.XAddWithOptions
- GlideClusterClient.XAutoClaim
- GlideClusterClient.XAutoClaimJustId
- GlideClusterClient.XAutoClaimJustIdWithOptions
- GlideClusterClient.XAutoClaimWithOptions
- GlideClusterClient.XClaim
- GlideClusterClient.XClaimJustId
- GlideClusterClient.XClaimJustIdWithOptions
- GlideClusterClient.XClaimWithOptions
- GlideClusterClient.XDel
- GlideClusterClient.XGroupCreate
- GlideClusterClient.XGroupCreateConsumer
- GlideClusterClient.XGroupCreateWithOptions
- GlideClusterClient.XGroupDelConsumer
- GlideClusterClient.XGroupDestroy
- GlideClusterClient.XGroupSetId
- GlideClusterClient.XGroupSetIdWithOptions
- GlideClusterClient.XLen
- GlideClusterClient.XPending
- GlideClusterClient.XPendingWithOptions
- GlideClusterClient.XRange
- GlideClusterClient.XRangeWithOptions
- GlideClusterClient.XRead
- GlideClusterClient.XReadGroup
- GlideClusterClient.XReadGroupWithOptions
- GlideClusterClient.XReadWithOptions
- GlideClusterClient.XRevRange
- GlideClusterClient.XRevRangeWithOptions
- GlideClusterClient.XTrim
- GlideClusterClient.ZAdd
- GlideClusterClient.ZAddIncr
- GlideClusterClient.ZAddIncrWithOptions
- GlideClusterClient.ZAddWithOptions
- GlideClusterClient.ZCard
- GlideClusterClient.ZCount
- GlideClusterClient.ZDiff
- GlideClusterClient.ZDiffStore
- GlideClusterClient.ZDiffWithScores
- GlideClusterClient.ZIncrBy
- GlideClusterClient.ZInter
- GlideClusterClient.ZInterStore
- GlideClusterClient.ZInterStoreWithOptions
- GlideClusterClient.ZInterWithScores
- GlideClusterClient.ZMScore
- GlideClusterClient.ZPopMax
- GlideClusterClient.ZPopMaxWithOptions
- GlideClusterClient.ZPopMin
- GlideClusterClient.ZPopMinWithOptions
- GlideClusterClient.ZRandMember
- GlideClusterClient.ZRandMemberWithCount
- GlideClusterClient.ZRandMemberWithCountWithScores
- GlideClusterClient.ZRange
- GlideClusterClient.ZRangeWithScores
- GlideClusterClient.ZRank
- GlideClusterClient.ZRankWithScore
- GlideClusterClient.ZRem
- GlideClusterClient.ZRemRangeByLex
- GlideClusterClient.ZRemRangeByRank
- GlideClusterClient.ZRemRangeByScore
- GlideClusterClient.ZRevRank
- GlideClusterClient.ZRevRankWithScore
- GlideClusterClient.ZScan
- GlideClusterClient.ZScanWithOptions
- GlideClusterClient.ZScore
Constants ¶
const ( DefaultHost = "localhost" DefaultPort = 6379 )
const OK = "OK"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackoffStrategy ¶
type BackoffStrategy struct {
// contains filtered or unexported fields
}
BackoffStrategy represents the strategy used to determine how and when to reconnect, in case of connection failures. The time between attempts grows exponentially, to the formula:
rand(0 ... factor * (exponentBase ^ N))
where N is the number of failed attempts.
Once the maximum value is reached, that will remain the time between retry attempts until a reconnect attempt is successful. The client will attempt to reconnect indefinitely.
func NewBackoffStrategy ¶
func NewBackoffStrategy(numOfRetries int, factor int, exponentBase int) *BackoffStrategy
NewBackoffStrategy returns a BackoffStrategy with the given configuration parameters.
type BaseClient ¶
type BaseClient interface { StringCommands HashCommands ListCommands SetCommands StreamCommands SortedSetCommands HyperLogLogCommands GenericBaseCommands BitmapCommands // Close terminates the client by closing all associated resources. Close() }
BaseClient defines an interface for methods common to both GlideClientCommands and GlideClusterClientCommands.
type BitmapCommands ¶
type BitmapCommands interface { SetBit(key string, offset int64, value int64) (int64, error) GetBit(key string, offset int64) (int64, error) BitCount(key string) (int64, error) BitCountWithOptions(key string, options options.BitCountOptions) (int64, error) BitField(key string, subCommands []options.BitFieldSubCommands) ([]Result[int64], error) BitFieldRO(key string, commands []options.BitFieldROCommands) ([]Result[int64], error) }
Supports commands and transactions for the "Bitmap" group of commands for standalone and cluster clients.
See valkey.io for details.
type ClusterValue ¶
type ClusterValue[T any] struct { // contains filtered or unexported fields }
Enum-like structure which stores either a single-node response or multi-node response. Multi-node response stored in a map, where keys are hostnames or "<ip>:<port>" strings.
Example:
// Command failed: value, err := clusterClient.CustomCommand(args) value.IsEmpty(): true err != nil: true // Command returns response from multiple nodes: value, _ := clusterClient.Info() for node, nodeResponse := range value.MultiValue() { response := nodeResponse // `node` stores cluster node IP/hostname, `response` stores the command output from that node } // Command returns a response from single node: value, _ := clusterClient.InfoWithOptions(api.ClusterInfoOptions{InfoOptions: nil, Route: api.RandomRoute.ToPtr()}) response := value.SingleValue() // `response` stores the command output from a cluster node
func (ClusterValue[T]) IsEmpty ¶
func (value ClusterValue[T]) IsEmpty() bool
func (ClusterValue[T]) IsMultiValue ¶
func (value ClusterValue[T]) IsMultiValue() bool
func (ClusterValue[T]) IsSingleValue ¶
func (value ClusterValue[T]) IsSingleValue() bool
func (ClusterValue[T]) MultiValue ¶
func (value ClusterValue[T]) MultiValue() map[string]T
Get the multi value stored (value returned by multiple cluster nodes).
func (ClusterValue[T]) SingleValue ¶
func (value ClusterValue[T]) SingleValue() T
Get the single value stored (value returned by a single cluster node).
func (ClusterValue[T]) ValueType ¶
func (value ClusterValue[T]) ValueType() ValueType
Get the value type
type ConnectionManagementClusterCommands ¶
type ConnectionManagementClusterCommands interface { Ping() (string, error) PingWithOptions(pingOptions options.ClusterPingOptions) (string, error) Echo(message string) (Result[string], error) EchoWithOptions(echoOptions options.ClusterEchoOptions) (ClusterValue[string], error) }
Supports commands and transactions for the "Connection Management" group of commands for cluster client.
See valkey.io for details.
type ConnectionManagementCommands ¶
type ConnectionManagementCommands interface { Ping() (string, error) PingWithOptions(pingOptions options.PingOptions) (string, error) Echo(message string) (Result[string], error) }
Supports commands and transactions for the "Connection Management" group of commands for standalone client.
See valkey.io for details.
type ConsumerPendingMessage ¶
type ConsumerPendingMessage struct { // ConsumerName is the name of the consumer. ConsumerName string // MessageCount is the number of pending messages for the consumer. MessageCount int64 }
ConsumerPendingMessage represents a pending message for a consumer in a Redis stream group. It includes the consumer's name and the count of pending messages for that consumer.
type GenericBaseCommands ¶
type GenericBaseCommands interface { Del(keys []string) (int64, error) Exists(keys []string) (int64, error) Expire(key string, seconds int64) (bool, error) ExpireWithOptions(key string, seconds int64, expireCondition options.ExpireCondition) (bool, error) ExpireAt(key string, unixTimestampInSeconds int64) (bool, error) ExpireAtWithOptions(key string, unixTimestampInSeconds int64, expireCondition options.ExpireCondition) (bool, error) PExpire(key string, milliseconds int64) (bool, error) PExpireWithOptions(key string, milliseconds int64, expireCondition options.ExpireCondition) (bool, error) PExpireAt(key string, unixTimestampInMilliSeconds int64) (bool, error) PExpireAtWithOptions(key string, unixTimestampInMilliSeconds int64, expireCondition options.ExpireCondition) (bool, error) ExpireTime(key string) (int64, error) PExpireTime(key string) (int64, error) TTL(key string) (int64, error) PTTL(key string) (int64, error) Unlink(keys []string) (int64, error) Touch(keys []string) (int64, error) Type(key string) (string, error) Rename(key string, newKey string) (string, error) RenameNX(key string, newKey string) (bool, error) Persist(key string) (bool, error) Restore(key string, ttl int64, value string) (Result[string], error) RestoreWithOptions(key string, ttl int64, value string, option options.RestoreOptions) (Result[string], error) ObjectEncoding(key string) (Result[string], error) Dump(key string) (Result[string], error) ObjectFreq(key string) (Result[int64], error) ObjectIdleTime(key string) (Result[int64], error) ObjectRefCount(key string) (Result[int64], error) Sort(key string) ([]Result[string], error) SortWithOptions(key string, sortOptions options.SortOptions) ([]Result[string], error) SortStore(key string, destination string) (int64, error) SortStoreWithOptions(key string, destination string, sortOptions options.SortOptions) (int64, error) SortReadOnly(key string) ([]Result[string], error) SortReadOnlyWithOptions(key string, sortOptions options.SortOptions) ([]Result[string], error) Wait(numberOfReplicas int64, timeout int64) (int64, error) Copy(source string, destination string) (bool, error) CopyWithOptions(source string, destination string, option options.CopyOptions) (bool, error) }
Supports commands and transactions for the "Generic Commands" group for standalone and cluster clients.
See valkey.io for details.
type GenericClusterCommands ¶
type GenericClusterCommands interface { CustomCommand(args []string) (ClusterValue[interface{}], error) CustomCommandWithRoute(args []string, route config.Route) (ClusterValue[interface{}], error) }
GenericClusterCommands supports commands for the "Generic Commands" group for cluster client.
See valkey.io for details.
type GenericCommands ¶
GenericCommands supports commands for the "Generic Commands" group for standalone client.
See valkey.io for details.
type GlideClient ¶
type GlideClient struct {
// contains filtered or unexported fields
}
GlideClient implements standalone mode operations by extending baseClient functionality.
func (GlideClient) Append ¶
Appends a value to a key. 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.
See valkey.io for details.
Parameters:
key - The key of the string. value - The value to append.
Return value:
The length of the string after appending the value.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Set("my_key", "my_valu") result, err := client.Append("my_key", "e") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) value, _ := client.Get("my_key") fmt.Println(value.Value())
Output: 8 my_value
func (GlideClient) BLMPop ¶
func (client GlideClient) BLMPop( keys []string, listDirection options.ListDirection, timeoutSecs float64, ) (map[string][]string, error)
Blocks the connection until it pops one element from the first non-empty list from the provided keys. BLMPop is the blocking variant of api.LMPop.
Note:
- When in cluster mode, all keys must map to the same hash slot.
- BLMPop is a client blocking command, see Blocking Commands for more details and best practices.
Since:
Valkey 7.0 and above.
See valkey.io for details.
Parameters:
keys - An array of keys to lists. listDirection - The direction based on which elements are popped from - see [options.ListDirection]. timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of 0 will block indefinitely.
Return value:
A map of key name mapped array of popped element. If no member could be popped and the timeout expired, returns nil.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("my_list", []string{"one", "two", "three"}) result1, err := client.BLMPop([]string{"my_list"}, options.Left, 0.1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 map[my_list:[three]]
func (GlideClient) BLMPopCount ¶
func (client GlideClient) BLMPopCount( keys []string, listDirection options.ListDirection, count int64, timeoutSecs float64, ) (map[string][]string, error)
Blocks the connection until it pops one or more elements from the first non-empty list from the provided keys. BLMPopCount is the blocking variant of api.LMPopCount.
Note:
- When in cluster mode, all keys must map to the same hash slot.
- BLMPopCount is a client blocking command, see Blocking Commands for more details and best practices.
Since:
Valkey 7.0 and above.
See valkey.io for details.
Parameters:
keys - An array of keys to lists. listDirection - The direction based on which elements are popped from - see [options.ListDirection]. count - The maximum number of popped elements. timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of 0 will block
indefinitely.
Return value:
A map of key name mapped array of popped element. If no member could be popped and the timeout expired, returns nil.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("my_list", []string{"one", "two", "three"}) result1, err := client.BLMPopCount([]string{"my_list"}, options.Left, 2, 0.1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 map[my_list:[three two]]
func (GlideClient) BLMove ¶
func (client GlideClient) BLMove( source string, destination string, whereFrom options.ListDirection, whereTo options.ListDirection, timeoutSecs float64, ) (Result[string], error)
Blocks the connection until it pops atomically and removes the left/right-most element to the list stored at source depending on whereFrom, and pushes the element at the first/last element of the list stored at <destination depending on wherefrom. BLMove is the blocking variant of api.LMove.
Note:
- When in cluster mode, all source and destination must map to the same hash slot.
- BLMove is a client blocking command, see Blocking Commands for more details and best practices.
Since:
Valkey 6.2.0 and above.
See valkey.io for details.
Parameters:
source - The key to the source list. destination - The key to the destination list. wherefrom - The ListDirection the element should be removed from. whereto - The ListDirection the element should be added to. timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of 0 will block indefinitely.
Return value:
A Result[string] containing the popped element or api.CreateNilStringResult() if source does not exist or if the operation timed-out.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("my_list1", []string{"two", "one"}) result1, err := client.LPush("my_list2", []string{"four", "three"}) result2, err := client.BLMove("my_list1", "my_list2", options.Left, options.Left, 0.1) result3, err := client.LRange("my_list1", 0, -1) result4, err := client.LRange("my_list2", 0, -1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2) fmt.Println(result3) fmt.Println(result4)
Output: 2 2 {one false} [two] [one three four]
func (GlideClient) BLPop ¶
Pops an element from the head of the first list that is non-empty, with the given keys being checked in the order that they are given. Blocks the connection when there are no elements to pop from any of the given lists.
Note:
- When in cluster mode, all keys must map to the same hash slot.
- BLPop is a client blocking command, see Blocking Commands for more details and best practices.
See valkey.io for details.
Parameters:
keys - The keys of the lists to pop from. timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of 0 will block indefinitely.
Return value:
A two-element array containing the key from which the element was popped and the value of the popped element, formatted as [key, value]. If no element could be popped and the timeout expired, returns `nil`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.RPush("list_a", []string{"a", "b", "c", "d", "e"}) result1, err := client.RPush("list_b", []string{"f", "g", "h", "i", "j"}) result2, err := client.BLPop([]string{"list_a", "list_b"}, 0.5) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 5 5 [list_a a]
func (GlideClient) BRPop ¶
Pops an element from the tail of the first list that is non-empty, with the given keys being checked in the order that they are given. Blocks the connection when there are no elements to pop from any of the given lists.
Note:
- When in cluster mode, all keys must map to the same hash slot.
- BRPop is a client blocking command, see Blocking Commands for more details and best practices.
See valkey.io for details.
Parameters:
keys - The keys of the lists to pop from. timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of 0 will block indefinitely.
Return value:
A two-element array containing the key from which the element was popped and the value of the popped element, formatted as [key, value]. If no element could be popped and the timeoutSecs expired, returns `nil`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Del([]string{"my_list", "list_a", "list_b"}) result, err := client.RPush("list_a", []string{"a", "b", "c", "d", "e"}) result1, err := client.RPush("list_b", []string{"f", "g", "h", "i", "j"}) result2, err := client.BRPop([]string{"list_a", "list_b"}, 0.5) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 5 5 [list_a e]
func (GlideClient) BZMPop ¶
func (client GlideClient) BZMPop( keys []string, scoreFilter options.ScoreFilter, timeoutSecs float64, ) (Result[KeyWithArrayOfMembersAndScores], error)
Blocks the connection until it pops and returns a member-score pair from the first non-empty sorted set, with the given keys being checked in the order they are provided. BZMPop is the blocking variant of [baseClient.ZMPop].
Note:
- When in cluster mode, all keys must map to the same hash slot.
- BZMPop is a client blocking command, see Blocking Commands for more details and best practices.
Since:
Valkey 7.0 and above.
See valkey.io for details.
Parameters:
keys - An array of keys to lists. scoreFilter - The element pop criteria - either [options.MIN] or [options.MAX] to pop members with the lowest/highest scores accordingly. timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of `0` will block indefinitely.
Return value:
An object containing the following elements: - The key name of the set from which the element was popped. - An array of member scores of the popped elements. Returns `nil` if no member could be popped and the timeout expired.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) result, err := client.BZMPop([]string{"key1"}, options.MAX, float64(0.5)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } jsonSummary, _ := json.Marshal(result.Value()) fmt.Println(string(jsonSummary))
Output: {"Key":"key1","MembersAndScores":[{"Member":"d","Score":4}]}
func (GlideClient) BZMPopWithOptions ¶
func (client GlideClient) BZMPopWithOptions( keys []string, scoreFilter options.ScoreFilter, timeoutSecs float64, opts options.ZMPopOptions, ) (Result[KeyWithArrayOfMembersAndScores], error)
Blocks the connection until it pops and returns a member-score pair from the first non-empty sorted set, with the given keys being checked in the order they are provided. BZMPop is the blocking variant of [baseClient.ZMPop].
Note:
- When in cluster mode, all keys must map to the same hash slot.
- BZMPop is a client blocking command, see Blocking Commands for more details and best practices.
Since:
Valkey 7.0 and above.
See valkey.io for details.
Parameters:
keys - An array of keys to lists. scoreFilter - The element pop criteria - either [options.MIN] or [options.MAX] to pop members with the lowest/highest scores accordingly. count - The maximum number of popped elements. timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of `0` will block indefinitely. opts - Pop options, see [options.ZMPopOptions].
Return value:
An object containing the following elements: - The key name of the set from which the element was popped. - An array of member scores of the popped elements. Returns `nil` if no member could be popped and the timeout expired.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) result, err := client.BZMPopWithOptions([]string{"key1"}, options.MAX, 0.1, *options.NewZMPopOptions().SetCount(2)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } kms := KeyWithArrayOfMembersAndScores{ Key: "key1", MembersAndScores: []MemberAndScore{ {Member: "d", Score: 4}, {Member: "c", Score: 3}, }, } fmt.Println(kms.Key == result.Value().Key) // isEqual := CompareUnorderedSlices[MemberAndScore]( // kms.MembersAndScores, // result.Value().MembersAndScores, // ) // helper function for comparing arrays and slices // fmt.Println(isEqual)
Output: true
func (GlideClient) BZPopMin ¶
func (client GlideClient) BZPopMin(keys []string, timeoutSecs float64) (Result[KeyWithMemberAndScore], error)
Blocks the connection until it removes and returns a member with the lowest score from the first non-empty sorted set, with the given `keys` being checked in the order they are provided. `BZPOPMIN` is the blocking variant of `ZPOPMIN`.
Note:
- When in cluster mode, all `keys` must map to the same hash slot.
- `BZPOPMIN` is a client blocking command, see [Blocking Commands] for more details and best practices.
See valkey.io for more details.
Parameters:
keys - The keys of the sorted sets. timeout - The number of seconds to wait for a blocking operation to complete. A value of `0` will block indefinitely.
Return value:
A `KeyWithMemberAndScore` struct containing the key where the member was popped out, the member itself, and the member score. If no member could be popped and the `timeout` expired, returns `nil`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function zaddResult1, err := client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 1.5}) zaddResult2, err := client.ZAdd("key2", map[string]float64{"c": 2.0}) result1, err := client.BZPopMin([]string{"key1", "key2"}, 0.5) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(zaddResult1) fmt.Println(zaddResult2) fmt.Println(result1)
Output: 2 1 {{key1 a 1} false}
func (GlideClient) BitCount ¶
Counts the number of set bits (population counting) in a string stored at key.
Parameters:
key - The key for the string to count the set bits of.
Return value:
The number of set bits in the string. Returns zero if the key is missing as it is treated as an empty string.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.SetBit("my_key", 1, 1) client.SetBit("my_key", 2, 1) result, err := client.BitCount("my_key") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 2
func (GlideClient) BitCountWithOptions ¶
func (client GlideClient) BitCountWithOptions(key string, opts options.BitCountOptions) (int64, error)
Counts the number of set bits (population counting) in a string stored at key. The offsets start and end are zero-based indexes, with `0` being the first element 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, with `-1` being the last element of the list, `-2` being the penultimate, and so on.
Parameters:
key - The key for the string to count the set bits of. options - The offset options - see [options.BitOffsetOptions].
Return value:
The number of set bits in the string interval specified by start, end, and options. Returns zero if the key is missing as it is treated as an empty string.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function options := options.NewBitCountOptions(). SetStart(1). SetEnd(1). SetBitmapIndexType(options.BYTE) result, err := client.BitCountWithOptions("my_key", *options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 0
func (GlideClient) BitField ¶
func (client GlideClient) BitField(key string, subCommands []options.BitFieldSubCommands) ([]Result[int64], error)
Reads or modifies the array of bits representing the string that is held at key based on the specified sub commands.
See valkey.io for details.
Parameters:
key - The key of the string. subCommands - The subCommands to be performed on the binary value of the string at key, which could be any of the following: - [BitFieldGet]. - [BitFieldSet]. - [BitFieldIncrby]. - [BitFieldOverflow]. Use `options.NewBitFieldGet()` to specify a BitField GET command. Use `options.NewBitFieldSet()` to specify a BitField SET command. Use `options.NewBitFieldIncrby()` to specify a BitField INCRYBY command. Use `options.BitFieldOverflow()` to specify a BitField OVERFLOW command.
Return value:
Result from the executed subcommands. - BitFieldGet returns the value in the binary representation of the string. - BitFieldSet returns the previous value before setting the new value in the binary representation. - BitFieldIncrBy returns the updated value after increasing or decreasing the bits. - BitFieldOverflow controls the behavior of subsequent operations and returns a result based on the specified overflow type (WRAP, SAT, FAIL).
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function commands := []options.BitFieldSubCommands{ options.NewBitFieldGet(options.SignedInt, 8, 16), options.NewBitFieldOverflow(options.SAT), options.NewBitFieldSet(options.UnsignedInt, 4, 0, 7), options.NewBitFieldIncrBy(options.SignedInt, 5, 100, 1), } result, err := client.BitField("mykey", commands) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: [{0 false} {0 false} {1 false}]
func (GlideClient) BitFieldRO ¶
func (client GlideClient) BitFieldRO(key string, commands []options.BitFieldROCommands) ([]Result[int64], error)
Reads the array of bits representing the string that is held at key based on the specified sub commands.
See valkey.io for details.
Parameters:
key - The key of the string. subCommands - The read-only subCommands to be performed on the binary value of the string at key, which could be: - [BitFieldGet]. Use `options.NewBitFieldGet()` to specify a BitField GET command.
Return value:
Result from the executed GET subcommands. - BitFieldGet returns the value in the binary representation of the string.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "mykey" bfcommands := []options.BitFieldSubCommands{ options.NewBitFieldSet(options.UnsignedInt, 8, 0, 24), } client.BitField(key, bfcommands) commands := []options.BitFieldROCommands{ options.NewBitFieldGet(options.UnsignedInt, 8, 0), } result, err := client.BitFieldRO(key, commands) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: [{24 false}]
func (GlideClient) Close ¶
func (client GlideClient) Close()
Close terminates the client by closing all associated resources.
func (*GlideClient) ConfigGet ¶
func (client *GlideClient) ConfigGet(args []string) (map[string]string, error)
Gets the values of configuration parameters.
Note: Prior to Version 7.0.0, only one parameter can be send.
See valkey.io for details.
Parameters:
args - A slice of configuration parameter names to retrieve values for.
Return value:
A map of api.Result[string] corresponding to the configuration parameters.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.ConfigSet(map[string]string{"timeout": "1000", "maxmemory": "1GB"}) // example configuration result, err := client.ConfigGet([]string{"timeout", "maxmemory"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: map[maxmemory:1073741824 timeout:1000]
func (*GlideClient) ConfigSet ¶
func (client *GlideClient) ConfigSet(parameters map[string]string) (string, error)
Sets configuration parameters to the specified values.
Note: Prior to Version 7.0.0, only one parameter can be send.
See valkey.io for details.
Parameters:
parameters - A map consisting of configuration parameters and their respective values to set.
Return value:
`"OK"` if all configurations have been successfully set. Otherwise, raises an error.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ConfigSet(map[string]string{"timeout": "1000", "maxmemory": "1GB"}) // example configuration if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: OK
func (GlideClient) Copy ¶
Copies the value stored at the source to the destination key if the destination key does not yet exist.
Note:
When in cluster mode, both source and destination must map to the same hash slot.
Parameters:
source - The key to the source value. destination - The key where the value should be copied to.
Return value:
`true` if source was copied, `false` if source was not copied.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.Copy("key1", "key2") result2, err := client.Get("key2") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: OK true {someValue false}
func (GlideClient) CopyWithOptions ¶
func (client GlideClient) CopyWithOptions( source string, destination string, options options.CopyOptions, ) (bool, error)
Copies the value stored at the source to the destination key. When replace is true, removes the destination key first if it already exists, otherwise performs no action.
Note:
When in cluster mode, both source and destination must map to the same hash slot.
Parameters:
source - The key to the source value. destination - The key where the value should be copied to. copyOptions - Set copy options with replace and DB destination-db
Return value:
`true` if source was copied, `false` if source was not copied.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Set("key1", "someValue") opts := options.NewCopyOptions().SetReplace() client.CopyWithOptions("key1", "key2", *opts) result, err := client.Get("key2") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.Value())
Output: someValue
func (*GlideClient) CustomCommand ¶
func (client *GlideClient) CustomCommand(args []string) (interface{}, error)
CustomCommand executes a single command, specified by args, without checking inputs. Every part of the command, including the command name and subcommands, should be added as a separate value in args. The returning value depends on the executed command.
See Valkey GLIDE Wiki for details on the restrictions and limitations of the custom command API.
This function should only be used for single-response commands. Commands that don't return complete response and awaits (such as SUBSCRIBE), or that return potentially more than a single response (such as XREAD), or that change the client's behavior (such as entering pub/sub mode on RESP2 connections) shouldn't be called using this function.
Parameters:
args - Arguments for the custom command including the command name.
Return value:
The returned value for the custom command.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.CustomCommand([]string{"ping"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: PONG
func (*GlideClient) DBSize ¶
func (client *GlideClient) DBSize() (int64, error)
Returns the number of keys in the currently selected database.
Return value:
The number of keys in the currently selected database.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function // Assume flushed client, so no keys are currently stored client.Set("key", "val") result, err := client.DBSize() if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 1
func (GlideClient) Decr ¶
Decrements the number stored at key by one. If key does not exist, it is set to 0 before performing the operation.
See valkey.io for details.
Parameters:
key - The key to decrement its value.
Return value:
The value of `key` after the decrement.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Set("my_key", "0") result, err := client.Decr("my_key") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: -1
func (GlideClient) DecrBy ¶
Decrements the number stored at code by amount. If key does not exist, it is set to 0 before performing the operation.
See valkey.io for details.
Parameters:
key - The key to decrement its value. amount - The amount to decrement.
Return value:
The value of `key` after the decrement.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Set("my_key", "20") result, err := client.DecrBy("my_key", 5) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 15
func (GlideClient) Del ¶
Del removes the specified keys from the database. A key is ignored if it does not exist.
Note:
In cluster mode, if keys in `keyValueMap` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
keys - One or more keys to delete.
Return value:
Returns the number of keys that were removed.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.Set("key2", "someValue") result2, err := client.Del([]string{"key1", "key2", "key3"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: OK OK 2
func (GlideClient) Dump ¶
Serialize the value stored at key in a Valkey-specific format and return it to the user.
Parameters:
The key to serialize.
Return value:
The serialized value of the data stored at key. If key does not exist, null will be returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.Dump("key1") // Contains serialized value of the data stored at key1 if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1.IsNil())
Output: OK false
func (*GlideClient) Echo ¶
func (client *GlideClient) Echo(message string) (Result[string], error)
Echo the provided message back. The command will be routed a random node.
Parameters:
message - The provided message.
Return value:
The provided message
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Echo("Hello World") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: {Hello World false}
func (GlideClient) Exists ¶
Exists returns the number of keys that exist in the database
Note:
In cluster mode, if keys in `keyValueMap` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
keys - One or more keys to check if they exist.
Return value:
Returns the number of existing keys.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.Set("key2", "someValue") result2, err := client.Exists([]string{"key1", "key2", "key3"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: OK OK 2
func (GlideClient) Expire ¶
Expire sets a timeout on key. After the timeout has expired, the key will automatically be deleted.
If key already has an existing expire set, the time to live is updated to the new value. If seconds is a non-positive number, the key will be deleted rather than expired. The timeout will only be cleared by commands that delete or overwrite the contents of key.
Parameters:
key - The key to expire. seconds - Time in seconds for the key to expire
Return value:
`true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.ExpireAt("key", time.Now().Unix()+1) result2, err := client.Expire("key", 1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: OK true true
func (GlideClient) ExpireAt ¶
ExpireAt sets a timeout on key. It takes an absolute Unix timestamp (seconds since January 1, 1970) instead of specifying the number of seconds. A timestamp in the past will delete the key immediately. After the timeout has expired, the key will automatically be deleted. If key already has an existing expire set, the time to live is updated to the new value. The timeout will only be cleared by commands that delete or overwrite the contents of key If key already has an existing expire set, the time to live is updated to the new value. If seconds is a non-positive number, the key will be deleted rather than expired. The timeout will only be cleared by commands that delete or overwrite the contents of key
Parameters:
key - The key to expire. unixTimestampInSeconds - Absolute Unix timestamp
Return value:
`true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.ExpireAt("key", time.Now().Unix()+1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK true
func (GlideClient) ExpireAtWithOptions ¶
func (client GlideClient) ExpireAtWithOptions( key string, unixTimestampInSeconds int64, expireCondition options.ExpireCondition, ) (bool, error)
ExpireAt sets a timeout on key. It takes an absolute Unix timestamp (seconds since January 1, 1970) instead of specifying the number of seconds. A timestamp in the past will delete the key immediately. After the timeout has expired, the key will automatically be deleted. If key already has an existing expire set, the time to live is updated to the new value. The timeout will only be cleared by commands that delete or overwrite the contents of key If key already has an existing expire set, the time to live is updated to the new value. If seconds is a non-positive number, the key will be deleted rather than expired. The timeout will only be cleared by commands that delete or overwrite the contents of key
Parameters: key - The key to expire. unixTimestampInSeconds - Absolute Unix timestamp. option - The option to set expiry - see options.ExpireCondition.
Return value:
`true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.ExpireAtWithOptions("key", time.Now().Unix()+1, options.HasNoExpiry) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK true
func (GlideClient) ExpireTime ¶
Expire Time returns the absolute Unix timestamp (since January 1, 1970) at which the given key will expire, in seconds.
Parameters:
key - The key to determine the expiration value of.
Return value:
The expiration Unix timestamp in seconds. `-2` if key does not exist or `-1` is key exists but has no associated expiration.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.ExpireTime("key") _, err = client.ExpireAt("key", time.Now().Unix()*1000) // ExpireTime("key") returns proper unix timestamp in seconds if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK -1
func (GlideClient) ExpireWithOptions ¶
func (client GlideClient) ExpireWithOptions(key string, seconds int64, expireCondition options.ExpireCondition) (bool, error)
Expire sets a timeout on key. After the timeout has expired, the key will automatically be deleted
If key already has an existing expire set, the time to live is updated to the new value. If seconds is a non-positive number, the key will be deleted rather than expired. The timeout will only be cleared by commands that delete or overwrite the contents of key
Parameters: key - The key to expire. seconds - Time in seconds for the key to expire. option - The option to set expiry, see options.ExpireCondition.
Return value:
`true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.ExpireWithOptions("key", 1, options.HasNoExpiry) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK true
func (GlideClient) Get ¶
Get string value associated with the given key, or api.CreateNilStringResult() is returned if no such value exists.
See valkey.io for details.
Parameters:
key - The key to be retrieved from the database.
Return value:
If key exists, returns the value of key as a String. Otherwise, return [api.CreateNilStringResult()].
Example (Keyexists) ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Set("my_key", "my_value") result, err := client.Get("my_key") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.Value())
Output: my_value
Example (Keynotexists) ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Get("my_key") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.IsNil()) // missing key returns nil result
Output: true
func (GlideClient) GetBit ¶
Returns the bit value at offset in the string value stored at key.
offset should be greater than or equal to zero.
Parameters:
key - The key of the string. offset - The index of the bit to return.
Return value:
The bit at offset of the string. Returns zero if the key is empty or if the positive offset exceeds the length of the string.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.SetBit("my_key", 1, 1) result, err := client.GetBit("my_key", 1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 1
func (GlideClient) GetDel ¶
GetDel gets the value associated with the given key and deletes the key.
Parameters:
key - The key to get and delete.
Return value:
If key exists, returns the value of the key as a String and deletes the key. If key does not exist, returns a [api.NilResult[string]] (api.CreateNilStringResult()).
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Set("my_key", "my_value") result, err := client.GetDel("my_key") // return value and delete key if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.Value()) value, _ := client.Get("my_key") // key should be missing fmt.Println(value.IsNil())
Output: my_value true
func (GlideClient) GetEx ¶
Get string value associated with the given key, or an empty string is returned [api.CreateNilStringResult()] if no such value exists.
See valkey.io for details.
Parameters:
key - The key to be retrieved from the database.
Return value:
If key exists, returns the value of key as a Result[string]. Otherwise, return [api.CreateNilStringResult()].
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Set("my_key", "my_value") result, err := client.GetEx("my_key") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.Value()) ttl, _ := client.TTL("my_key") fmt.Println(ttl)
Output: my_value -1
func (GlideClient) GetExWithOptions ¶
func (client GlideClient) GetExWithOptions(key string, options options.GetExOptions) (Result[string], error)
Get string value associated with the given key and optionally sets the expiration of the key.
See valkey.io for details.
Parameters:
key - The key to be retrieved from the database. options - The [options.GetExOptions].
Return value:
If key exists, returns the value of key as a Result[string]. Otherwise, return [api.CreateNilStringResult()].
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Set("my_key", "my_value") options := options.NewGetExOptions(). SetExpiry(options.NewExpiry(). SetType(options.Seconds). SetCount(5)) result, err := client.GetExWithOptions("my_key", *options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.Value()) ttl, _ := client.TTL("my_key") fmt.Println(ttl)
Output: my_value 5
func (GlideClient) GetRange ¶
Returns the substring of the string value stored at key, determined by the byte's 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.
See valkey.io for details.
Parameters:
key - The key of the string. start - The starting offset. end - The ending offset.
Return value:
A substring extracted from the value stored at key. Returns empty string if the offset is out of bounds.
Example (One) ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Set("my_key", "Welcome to Valkey Glide!") result, err := client.GetRange("my_key", 0, 7) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: Welcome
Example (Two) ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Set("my_key", "愛") fmt.Println([]byte("愛")) // "愛" is a single character in UTF-8, but 3 bytes long result, err := client.GetRange("my_key", 0, 1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println([]byte(result))
Output: [230 132 155] [230 132]
func (GlideClient) HDel ¶
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.
See valkey.io for details.
Parameters:
key - The key of the hash. fields - The fields to remove from the hash stored at key.
Return value:
The number of fields that were removed from the hash, not including specified but non-existing fields.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) result1, err := client.HDel("my_hash", []string{"field1", "field2"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 2 2
func (GlideClient) HExists ¶
HExists returns if field is an existing field in the hash stored at key.
See valkey.io for details.
Parameters:
key - The key of the hash. field - The field to check in the hash stored at key.
Return value:
A bool containing true if the hash contains the specified field. false if the hash does not contain the field, or if the key does not exist.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) result1, err := client.HExists("my_hash", "field1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 2 true
func (GlideClient) HGet ¶
HGet returns the value associated with field in the hash stored at key.
See valkey.io for details.
Parameters:
key - The key of the hash. field - The field in the hash stored at key to retrieve from the database.
Return value:
The Result[string] associated with field, or [api.NilResult[string]](api.CreateNilStringResult()) when field is not present in the hash or key does not exist.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) payload, err := client.HGet("my_hash", "field1") payload2, err := client.HGet("my_hash", "nonexistent_field") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(payload) fmt.Println(payload2.IsNil())
Output: 2 {someValue false} true
func (GlideClient) HGetAll ¶
HGetAll returns all fields and values of the hash stored at key.
See valkey.io for details.
Parameters:
key - The key of the hash.
Return value:
A map of all fields and their values as Result[string] in the hash, or an empty map when key does not exist.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) payload, err := client.HGetAll("my_hash") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(payload["field1"]) fmt.Println(payload["field2"]) fmt.Println(payload["notExistentField"]) // prints nothing
Output: 2 someValue someOtherValue
func (GlideClient) HIncrBy ¶
Increments the number stored at `field` in the hash stored at `key` by increment. By using a negative increment value, the value stored at `field` in the hash stored at `key` is decremented. If `field` or `key` does not exist, it is set to 0 before performing the operation.
See valkey.io for details.
Parameters:
key - The key of the hash. field - The field in the hash stored at `key` to increment its value. increment - The amount to increment.
Return value:
The value of `field` in the hash stored at `key` after the increment.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function fields := map[string]string{ "field1": "10", "field2": "14", } result, err := client.HSet("my_hash", fields) result1, err := client.HIncrBy("my_hash", "field1", 1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 2 11
func (GlideClient) HIncrByFloat ¶
func (client GlideClient) HIncrByFloat(key string, field string, increment float64) (float64, error)
Increments the string representing a floating point number stored at `field` in the hash stored at `key` by increment. By using a negative increment value, the value stored at `field` in the hash stored at `key` is decremented. If `field` or `key` does not exist, it is set to `0` before performing the operation.
See valkey.io for details.
Parameters:
key - The key of the hash. field - The field in the hash stored at `key` to increment its value. increment - The amount to increment.
Return value:
The value of `field` in the hash stored at `key` after the increment.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function fields := map[string]string{ "field1": "10", "field2": "14", } result, err := client.HSet("my_hash", fields) result1, err := client.HIncrByFloat("my_hash", "field1", 1.5) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 2 11.5
func (GlideClient) HKeys ¶
HKeys returns all field names in the hash stored at key.
See valkey.io for details.
Parameters:
key - The key of the hash.
Return value:
A slice containing all the field names in the hash, or an empty slice when key does not exist.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function fields := map[string]string{ "field1": "someValue", } client.HSet("my_hash", fields) result, err := client.HKeys("my_hash") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: [field1]
func (GlideClient) HLen ¶
HLen returns the number of fields contained in the hash stored at key.
See valkey.io for details.
Parameters:
key - The key of the hash.
Return value:
The number of fields in the hash, or `0` when key does not exist. If key holds a value that is not a hash, an error is returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) result1, err := client.HLen("my_hash") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 2 2
func (GlideClient) HMGet ¶
HMGet returns the values associated with the specified fields in the hash stored at key.
See valkey.io for details.
Parameters:
key - The key of the hash. fields - The fields in the hash stored at key to retrieve from the database.
Return value:
An array of Result[string]s associated with the given fields, in the same order as they are requested. For every field that does not exist in the hash, a [api.NilResult[string]](api.CreateNilStringResult()) is returned. If key does not exist, returns an empty string array.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) values, err := client.HMGet("my_hash", []string{"field1", "field2"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(values[0]) fmt.Println(values[1])
Output: 2 {someValue false} {someOtherValue false}
func (GlideClient) HRandField ¶
Returns a random field name from the hash value stored at `key`.
Since:
Valkey 6.2.0 and above.
See valkey.io for details.
Parameters:
key - The key of the hash.
Return value:
A random field name from the hash stored at `key`, or `nil` when the key does not exist.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function // For this example we only use 1 field to ensure consistent output fields := map[string]string{ "field1": "someValue", // other fields here... } client.HSet("my_hash", fields) result, err := client.HRandField("my_hash") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: {field1 false}
func (GlideClient) HRandFieldWithCount ¶
Retrieves up to `count` random field names from the hash value stored at `key`.
Since:
Valkey 6.2.0 and above.
See valkey.io for details.
Parameters:
key - The key of the hash. count - The number of field names to return. If `count` is positive, returns unique elements. If negative, allows for duplicates.
Return value:
An array of random field names from the hash stored at `key`, or an empty array when the key does not exist.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } client.HSet("my_hash", fields) result, err := client.HRandFieldWithCount("my_hash", 2) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(len(result) == 2)
Output: true
func (GlideClient) HRandFieldWithCountWithValues ¶
func (client GlideClient) HRandFieldWithCountWithValues(key string, count int64) ([][]string, error)
Retrieves up to `count` random field names along with their values from the hash value stored at `key`.
Since:
Valkey 6.2.0 and above.
See valkey.io for details.
Parameters:
key - The key of the hash. count - The number of field names to return. If `count` is positive, returns unique elements. If negative, allows for duplicates.
Return value:
A 2D `array` of `[field, value]` arrays, where `field` is a random field name from the hash and `value` is the associated value of the field name. If the hash does not exist or is empty, the response will be an empty array.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } client.HSet("my_hash", fields) result, err := client.HRandFieldWithCountWithValues("my_hash", 2) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(len(result) == 2)
Output: true
func (GlideClient) HScan ¶
Iterates fields of Hash types and their associated values. This definition of HSCAN command does not include the optional arguments of the command.
See valkey.io for details.
Parameters:
key - The key of the hash. cursor - The cursor that points to the next iteration of results. A value of "0" indicates the start of the search.
Return value:
An array of the cursor and the subset of the hash held by `key`. The first element is always the `cursor` for the next iteration of results. The `cursor` will be `"0"` on the last iteration of the subset. The second element is always an array of the subset of the set held in `key`. The array in the second element is always a flattened series of String pairs, where the key is at even indices and the value is at odd indices.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function // For this example we only use 1 field to ensure a consistent output fields := map[string]string{ "field1": "someValue", // other fields here } result, err := client.HSet("my_hash", fields) resCursor, resCollection, err := client.HScan("my_hash", "0") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(resCursor) fmt.Println(resCollection)
Output: 1 0 [field1 someValue]
func (GlideClient) HScanWithOptions ¶
func (client GlideClient) HScanWithOptions( key string, cursor string, options options.HashScanOptions, ) (string, []string, error)
Iterates fields of Hash types and their associated values. This definition of HSCAN includes optional arguments of the command.
See valkey.io for details.
Parameters:
key - The key of the hash. cursor - The cursor that points to the next iteration of results. A value of "0" indicates the start of the search. options - The [options.HashScanOptions].
Return value:
An array of the cursor and the subset of the hash held by `key`. The first element is always the `cursor` for the next iteration of results. The `cursor` will be `"0"` on the last iteration of the subset. The second element is always an array of the subset of the set held in `key`. The array in the second element is always a flattened series of String pairs, where the key is at even indices and the value is at odd indices.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function fields := map[string]string{ "a": "1", "b": "2", } result, err := client.HSet("my_hash", fields) opts := options.NewHashScanOptions().SetMatch("a") resCursor, resCollection, err := client.HScanWithOptions("my_hash", "0", *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(resCursor) fmt.Println( resCollection, ) // The resCollection only contains the hash map entry that matches with the match option provided with the command
Output: 2 0 [a 1]
func (GlideClient) HSet ¶
HSet sets the specified fields to their respective values in the hash stored at key. This command overwrites the values of specified fields that exist in the hash. If key doesn't exist, a new key holding a hash is created.
See valkey.io for details.
Parameters:
key - The key of the hash. values - A map of field-value pairs to set in the hash.
Return value:
The number of fields that were added or updated.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) result1, err := client.HGet("my_hash", "field1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 2 {someValue false}
func (GlideClient) HSetNX ¶
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.
See valkey.io for details.
Parameters:
key - The key of the hash. field - The field to set. value - The value to set.
Return value:
A bool containing true if field is a new field in the hash and value was set. false if field already exists in the hash and no operation was performed.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) result1, err := client.HSetNX("my_hash", "field3", "value") payload, err := client.HGet("my_hash", "field3") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(payload)
Output: 2 true {value false}
func (GlideClient) HStrLen ¶
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.
See valkey.io for details.
Parameters:
key - The key of the hash. field - The field to get the string length of its value.
Return value:
The length of the string value associated with field, or `0` when field or key do not exist.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) result1, err := client.HStrLen("my_hash", "field1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 2 9
func (GlideClient) HVals ¶
HVals returns all values in the hash stored at key.
See valkey.io for details.
Parameters:
key - The key of the hash.
Return value:
A slice containing all the values in the hash, or an empty slice when key does not exist.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function // For this example, we only use 1 field for consistent output fields := map[string]string{ "field1": "someValue", // other fields here } result, err := client.HSet("my_hash", fields) result1, err := client.HVals("my_hash") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 1 [someValue]
func (GlideClient) Incr ¶
Increments the number stored at key by one. If key does not exist, it is set to 0 before performing the operation.
See valkey.io for details.
Parameters:
key - The key to increment its value.
Return value:
The value of `key` after the increment.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Set("my_key", "1") result, err := client.Incr("my_key") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 2
func (GlideClient) IncrBy ¶
Increments the number stored at key by amount. If key does not exist, it is set to 0 before performing the operation.
See valkey.io for details.
Parameters:
key - The key to increment its value. amount - The amount to increment.
Return value:
The value of `key` after the increment.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Set("my_key", "5") result, err := client.IncrBy("my_key", 5) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 10
func (GlideClient) IncrByFloat ¶
Increments the string representing a floating point number stored at key by amount. By using a negative increment value, the result is that the value stored at key is decremented. If key does not exist, it is set to `0` before performing the operation.
See valkey.io for details.
Parameters:
key - The key to increment its value. amount - The amount to increment.
Return value:
The value of key after the increment.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Set("my_key", "1") result, err := client.IncrByFloat("my_key", 5.5) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 6.5
func (*GlideClient) Info ¶
func (client *GlideClient) Info() (string, error)
Gets information and statistics about the server.
See valkey.io for details.
Return value:
A string with the information for the default sections.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function response, err := client.Info() if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Printf("response is of type %T\n", response)
Output: response is of type string
func (*GlideClient) InfoWithOptions ¶
func (client *GlideClient) InfoWithOptions(options options.InfoOptions) (string, error)
Gets information and statistics about the server.
See valkey.io for details.
Parameters:
options - Additional command parameters, see [InfoOptions] for more details.
Return value:
A string containing the information for the sections requested.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function opts := options.InfoOptions{Sections: []options.Section{options.Server}} response, err := client.InfoWithOptions(opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Printf("response is of type %T\n", response)
Output: response is of type string
func (GlideClient) LCS ¶
Returns the longest common subsequence between strings stored at key1 and key2.
Since:
Valkey 7.0 and above.
Note:
In cluster mode, if keys in `keyValueMap` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
key1 - The key that stores the first string. key2 - The key that stores the second string.
Return value:
The longest common subsequence between the 2 strings. An empty string is returned if the keys do not exist or have no common subsequences.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.MSet(map[string]string{"my_key1": "oh my gosh", "my_key2": "hello world"}) result, err := client.LCS("my_key1", "my_key2") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: h o
func (GlideClient) LIndex ¶
Returns the element at index from 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.
See valkey.io for details.
Parameters:
key - The key of the list. index - The index of the element in the list to retrieve.
Return value:
The Result[string] containing element at index in the list stored at key. If index is out of range or if key does not exist, [api.CreateNilStringResult()] is returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.LIndex("my_list", 3) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 7 {d false}
func (GlideClient) LInsert ¶
func (client GlideClient) LInsert( key string, insertPosition options.InsertPosition, pivot string, element string, ) (int64, error)
Inserts element in the list at key either before or after the pivot.
See valkey.io for details.
Parameters:
key - The key of the list. insertPosition - The relative position to insert into - either options.Before or options.After the pivot. pivot - An element of the list. element - The new element to insert.
Return value:
The list length after a successful insert operation. If the `key` doesn't exist returns `-1`. If the `pivot` wasn't found, returns `0`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Del([]string{"my_list"}) result, err := client.RPush("my_list", []string{"hello", "world"}) result1, err := client.LInsert("my_list", options.Before, "world", "there") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 2 3
func (GlideClient) LLen ¶
Returns the length of the list stored at key.
See valkey.io for details.
Parameters:
key - The key of the list.
Return value:
The length of the list at `key`. If `key` does not exist, it is interpreted as an empty list and `0` is returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.LLen("my_list") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 7 7
func (GlideClient) LMPop ¶
func (client GlideClient) LMPop(keys []string, listDirection options.ListDirection) (map[string][]string, error)
Pops one element from the first non-empty list from the provided keys.
Since:
Valkey 7.0 and above.
See valkey.io for details.
Parameters:
keys - An array of keys to lists. listDirection - The direction based on which elements are popped from - see [options.ListDirection].
Return value:
A map of key name mapped array of popped element.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("my_list", []string{"one", "two", "three"}) result1, err := client.LMPop([]string{"my_list"}, options.Left) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 map[my_list:[three]]
func (GlideClient) LMPopCount ¶
func (client GlideClient) LMPopCount( keys []string, listDirection options.ListDirection, count int64, ) (map[string][]string, error)
Pops one or more elements from the first non-empty list from the provided keys.
Since:
Valkey 7.0 and above.
See valkey.io for details.
Parameters:
keys - An array of keys to lists. listDirection - The direction based on which elements are popped from - see [options.ListDirection]. count - The maximum number of popped elements.
Return value:
A map of key name mapped array of popped elements.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("my_list", []string{"one", "two", "three"}) result1, err := client.LMPopCount([]string{"my_list"}, options.Left, 2) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 map[my_list:[three two]]
func (GlideClient) LMove ¶
func (client GlideClient) LMove( source string, destination string, whereFrom options.ListDirection, whereTo options.ListDirection, ) (Result[string], error)
Atomically pops and removes the left/right-most element to the list stored at source depending on whereFrom, and pushes the element at the first/last element of the list stored at destination depending on whereTo.
See valkey.io for details.
Parameters:
source - The key to the source list. destination - The key to the destination list. wherefrom - The ListDirection the element should be removed from. whereto - The ListDirection the element should be added to.
Return value:
A Result[string] containing the popped element or api.CreateNilStringResult() if source does not exist.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("my_list1", []string{"two", "one"}) result1, err := client.LPush("my_list2", []string{"four", "three"}) result2, err := client.LMove("my_list1", "my_list2", options.Left, options.Left) result3, err := client.LRange("my_list1", 0, -1) result4, err := client.LRange("my_list2", 0, -1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2) fmt.Println(result3) fmt.Println(result4)
Output: 2 2 {one false} [two] [one three four]
func (GlideClient) LPop ¶
Removes and returns the first elements of the list stored at key. The command pops a single element from the beginning of the list.
See valkey.io for details.
Parameters:
key - The key of the list.
Return value:
The Result[string] containing the value of the first element. If key does not exist, [api.CreateNilStringResult()] will be returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("my_list", []string{"value1", "value2"}) result1, err := client.LPop("my_list") result2, err := client.LPop("non_existent") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2.IsNil())
Output: 2 {value2 false} true
func (GlideClient) LPopCount ¶
Removes and returns up to count elements of the list stored at key, depending on the list's length.
See valkey.io for details.
Parameters:
key - The key of the list. count - The count of the elements to pop from the list.
Return value:
An array of the popped elements as strings will be returned depending on the list's length If key does not exist, nil will be returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("my_list", []string{"value1", "value2"}) result1, err := client.LPopCount("my_list", 2) result2, err := client.LPop("non_existent") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2.IsNil())
Output: 2 [value2 value1] true
func (GlideClient) LPos ¶
Returns the index of the first occurrence of element inside the list specified by key. If no match is found, [api.CreateNilInt64Result()] is returned.
See valkey.io for details.
Parameters:
key - The name of the list. element - The value to search for within the list.
Return value:
The Result[int64] containing the index of the first occurrence of element, or [api.CreateNilInt64Result()] if element is not in the list.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e"}) result1, err := client.LPos("my_list", "e") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 6 {4 false}
func (GlideClient) LPosCount ¶
Returns an array of indices of matching elements within a list.
See valkey.io for details.
Parameters:
key - The name of the list. element - The value to search for within the list. count - The number of matches wanted.
Return value:
An array that holds the indices of the matching elements within the list.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.LPosCount("my_list", "e", 3) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 7 [4 5 6]
func (GlideClient) LPosCountWithOptions ¶
func (client GlideClient) LPosCountWithOptions( key string, element string, count int64, opts options.LPosOptions, ) ([]int64, error)
Returns an array of indices of matching elements within a list based on the given options. If no match is found, an empty array is returned.
See valkey.io for details.
Parameters:
key - The name of the list. element - The value to search for within the list. count - The number of matches wanted. opts - The LPos options.
Return value:
An array that holds the indices of the matching elements within the list.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.LPosCountWithOptions("my_list", "e", 1, *options.NewLPosOptions().SetRank(2)) result2, err := client.LPosCountWithOptions("my_list", "e", 3, *options.NewLPosOptions().SetRank(2).SetMaxLen(1000)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 7 [5] [5 6]
func (GlideClient) LPosWithOptions ¶
func (client GlideClient) LPosWithOptions(key string, element string, options options.LPosOptions) (Result[int64], error)
Returns the index of an occurrence of element within a list based on the given options. If no match is found, [api.CreateNilInt64Result()] is returned.
See valkey.io for details.
Parameters:
key - The name of the list. element - The value to search for within the list. options - The LPos options.
Return value:
The Result[int64] containing the index of element, or [api.CreateNilInt64Result()] if element is not in the list.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e"}) result1, err := client.LPosWithOptions( "my_list", "e", *options.NewLPosOptions().SetRank(2), ) // (Returns the second occurrence of the element "e") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 6 {5 false}
func (GlideClient) LPush ¶
Inserts all the specified values at the head of the list stored at key. elements are inserted one after the other to the head of the list, from the leftmost element to the rightmost element. If key does not exist, it is created as an empty list before performing the push operation.
See valkey.io for details.
Parameters:
key - The key of the list. elements - The elements to insert at the head of the list stored at key.
Return value:
The length of the list after the push operation.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("my_list", []string{"value1", "value2"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 2
func (GlideClient) LPushX ¶
Inserts all the specified values at the head of the list stored at key, only if key exists and holds a list. If key is not a list, this performs no operation.
See valkey.io for details.
Parameters:
key - The key of the list. elements - The elements to insert at the head of the list stored at key.
Return value:
The length of the list after the push operation.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.RPush("my_list", []string{"value1"}) result1, err := client.LPushX("my_list", []string{"value2", "value3"}) result2, err := client.LRange("my_list", 0, -1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 1 3 [value3 value2 value1]
func (GlideClient) LRange ¶
Returns the specified elements of the list stored at key. The offsets start and end are zero-based indexes, with 0 being the first element 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, with -1 being the last element of the list, -2 being the penultimate, and so on.
See valkey.io for details.
Parameters:
key - The key of the list. start - The starting point of the range. end - The end of the range.
Return value:
Array of elements as Result[string] in the specified range. If start exceeds the end of the list, or if start is greater than end, an empty array will be returned. If end exceeds the actual end of the list, the range will stop at the actual end of the list. If key does not exist an empty array will be returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.LRange("my_list", 0, 2) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 7 [a b c]
func (GlideClient) LRem ¶
Removes the first count occurrences of elements equal to element from the list stored at key. If count is positive: Removes elements equal to element moving from head to tail. If count is negative: Removes elements equal to element moving from tail to head. If count is 0 or count is greater than the occurrences of elements equal to element, it removes all elements equal to element.
See valkey.io for details.
Parameters:
key - The key of the list. count - The count of the occurrences of elements equal to element to remove. element - The element to remove from the list.
Return value:
The number of the removed elements. If `key` does not exist, `0` is returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.LRem("my_list", 2, "e") result2, err := client.LRange("my_list", 0, -1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 7 2 [a b c d e]
func (GlideClient) LSet ¶
Sets the list element at index to element. 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.
See valkey.io for details.
Parameters:
key - The key of the list. index - The index of the element in the list to be set. element - The element to be set.
Return value:
`"OK"`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("my_list", []string{"one", "two", "three"}) result1, err := client.LSet("my_list", 1, "someOtherValue") result2, err := client.LRange("my_list", 0, -1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 3 OK [three someOtherValue one]
func (GlideClient) LTrim ¶
Trims an existing list so that it will contain only the specified range of elements specified. The offsets start and end are zero-based indexes, with 0 being the first element 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, with -1 being the last element of the list, -2 being the penultimate, and so on.
See valkey.io for details.
Parameters:
key - The key of the list. start - The starting point of the range. end - The end of the range.
Return value:
Always `"OK"`. If start exceeds the end of the list, or if start is greater than end, the result will be an empty list (which causes key to be removed). If end exceeds the actual end of the list, it will be treated like the last element of the list. If key does not exist, `"OK"` will be returned without changes to the database.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.LTrim("my_list", 0, 4) result2, err := client.LRange("my_list", 0, -1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 7 OK [a b c d e]
func (GlideClient) MGet ¶
Retrieves the values of multiple keys.
Note:
In cluster mode, if keys in `keys` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
keys - A list of keys to retrieve values for.
Return value:
An array of values corresponding to the provided keys. If a key is not found, its corresponding value in the list will be a [api.CreateNilStringResult()]
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.MSet(map[string]string{"my_key1": "my_value1", "my_key2": "my_value2", "my_key3": "my_value3"}) keys := []string{"my_key1", "my_key2", "my_key3"} result, err := client.MGet(keys) if err != nil { fmt.Println("Glide example failed with an error: ", err) } for _, res := range result { fmt.Println(res.Value()) }
Output: my_value1 my_value2 my_value3
func (GlideClient) MSet ¶
Sets multiple keys to multiple values in a single operation.
Note:
In cluster mode, if keys in `keyValueMap` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
keyValueMap - A key-value map consisting of keys and their respective values to set.
Return value:
`"OK"` on success.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function keyValueMap := map[string]string{ "key1": "value1", "key2": "value2", } result, err := client.MSet(keyValueMap) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: OK
func (GlideClient) MSetNX ¶
Sets multiple keys to values if the key does not exist. The operation is atomic, and if one or more keys already exist, the entire operation fails.
Note:
In cluster mode, if keys in `keyValueMap` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
keyValueMap - A key-value map consisting of keys and their respective values to set.
Return value:
A bool containing true, if all keys were set. false, if no key was set.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function keyValueMap := map[string]string{"my_key1": "my_value1", "my_key2": "my_value2"} result, err := client.MSetNX(keyValueMap) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) client.Set("my_key3", "my_value3") result, _ = client.MSetNX(map[string]string{"my_key3": "my_value3"}) fmt.Println(result)
Output: true false
func (GlideClient) ObjectEncoding ¶
Returns the internal encoding for the Valkey object stored at key.
Note:
When in cluster mode, both key and newkey must map to the same hash slot.
Parameters:
The key of the object to get the internal encoding of.
Return value:
If key exists, returns the internal encoding of the object stored at key as a String. Otherwise, returns `null`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.ObjectEncoding("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK {embstr false}
func (GlideClient) ObjectFreq ¶
Returns the logarithmic access frequency counter of a Valkey object stored at key.
Parameters:
key - The key of the object to get the logarithmic access frequency counter of.
Return value:
If key exists, returns the logarithmic access frequency counter of the object stored at key as a long. Otherwise, returns `nil`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.ConfigSet(map[string]string{"maxmemory-policy": "allkeys-lfu"}) // example configuration client.Set("key1", "someValue") client.Set("key1", "someOtherValue") result, err := client.ObjectFreq("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: {6 false}
func (GlideClient) ObjectIdleTime ¶
Returns the logarithmic access frequency counter of a Valkey object stored at key.
Parameters:
key - The key of the object to get the logarithmic access frequency counter of.
Return value:
If key exists, returns the idle time in seconds. Otherwise, returns `nil`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.ConfigSet(map[string]string{"maxmemory-policy": "allkeys-lru"}) // example configuration result, err := client.Set("key1", "someValue") result1, err := client.ObjectIdleTime("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK {0 false}
func (GlideClient) ObjectRefCount ¶
Returns the reference count of the object stored at key.
Parameters:
key - The key of the object to get the reference count of.
Return value:
If key exists, returns the reference count of the object stored at key. Otherwise, returns `nil`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function _, err := client.ConfigSet(map[string]string{"maxmemory-policy": "allkeys-lru"}) // example configuration result, err := client.Set("key1", "someValue") result1, err := client.ObjectRefCount("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK {1 false}
func (GlideClient) PExpire ¶
Parameters:
key - The key to set timeout on it. milliseconds - The timeout in milliseconds.
Return value:
`true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.PExpire("key", int64(5*1000)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK true
func (GlideClient) PExpireAt ¶
Sets a timeout on key. It takes an absolute Unix timestamp (milliseconds since January 1, 1970) instead of specifying the number of milliseconds. A timestamp in the past will delete the key immediately. After the timeout has expired, the key will automatically be deleted If key already has an existing expire set, the time to live is updated to the new value/ The timeout will only be cleared by commands that delete or overwrite the contents of key
Parameters:
key - The key to set timeout on it. unixMilliseconds - The timeout in an absolute Unix timestamp.
Return value:
`true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.PExpireAt("key", time.Now().Unix()*1000) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK true
func (GlideClient) PExpireAtWithOptions ¶
func (client GlideClient) PExpireAtWithOptions( key string, unixTimestampInMilliSeconds int64, expireCondition options.ExpireCondition, ) (bool, error)
Sets a timeout on key. It takes an absolute Unix timestamp (milliseconds since January 1, 1970) instead of specifying the number of milliseconds. A timestamp in the past will delete the key immediately. After the timeout has expired, the key will automatically be deleted. If key already has an existing expire set, the time to live is updated to the new value. The timeout will only be cleared by commands that delete or overwrite the contents of key
Parameters:
key - The key to set timeout on it. unixMilliseconds - The timeout in an absolute Unix timestamp. option - The option to set expiry, see [options.ExpireCondition].
Return value:
`true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.PExpireAtWithOptions("key", time.Now().Unix()*1000, options.HasNoExpiry) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK true
func (GlideClient) PExpireTime ¶
PExpire Time returns the absolute Unix timestamp (since January 1, 1970) at which the given key will expire, in milliseconds.
Parameters:
key - The key to determine the expiration value of.
Return value:
The expiration Unix timestamp in milliseconds. `-2` if key does not exist or `-1` is key exists but has no associated expiration.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.PExpireTime("key") _, err = client.PExpireAt("key", time.Now().Unix()*1000) // PExpireTime("key") returns proper unix time in milliseconds if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK -1
func (GlideClient) PExpireWithOptions ¶
func (client GlideClient) PExpireWithOptions( key string, milliseconds int64, expireCondition options.ExpireCondition, ) (bool, error)
Sets a timeout on key in milliseconds. After the timeout has expired, the key will automatically be deleted. If key already has an existing expire set, the time to live is updated to the new value. If milliseconds is a non-positive number, the key will be deleted rather than expired The timeout will only be cleared by commands that delete or overwrite the contents of key.
Parameters:
key - The key to set timeout on it. milliseconds - The timeout in milliseconds. option - The option to set expiry, see [options.ExpireCondition].
Return value:
`true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.PExpireWithOptions("key", int64(5*1000), options.HasNoExpiry) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK true
func (GlideClient) PTTL ¶
PTTL returns the remaining time to live of key that has a timeout, in milliseconds.
Parameters:
key - The key to return its timeout.
Return value:
Returns TTL in milliseconds, `-2` if key does not exist, or `-1` if key exists but has no associated expiration.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.PTTL("key") _, err = client.PExpireAt("key", time.Now().Unix()*100000) // PTTL("key") returns proper TTL in milliseconds if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK -1
func (GlideClient) 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).
Parameters:
key - The key to remove the existing timeout on.
Return value:
`false` if key does not exist or does not have an associated timeout, `true` if the timeout has been removed.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.ExpireAt("key1", time.Now().Unix()*1000) result2, err := client.Persist("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: OK true true
func (GlideClient) PfAdd ¶
PfAdd adds all elements to the HyperLogLog data structure stored at the specified key. Creates a new structure if the key does not exist. When no elements are provided, and key exists and is a HyperLogLog, then no operation is performed. If key does not exist, then the HyperLogLog structure is created.
Parameters:
key - The key of the HyperLogLog data structure to add elements into. elements - An array of members to add to the HyperLogLog stored at key.
Return value:
If the HyperLogLog is newly created, or if the HyperLogLog approximated cardinality is altered, then returns `1`. Otherwise, returns `0`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.PfAdd(uuid.New().String(), []string{"value1", "value2", "value3"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 1
func (GlideClient) PfCount ¶
Estimates the cardinality of the data stored in a HyperLogLog structure for a single key or calculates the combined cardinality of multiple keys by merging their HyperLogLogs temporarily.
Note:
In cluster mode, if keys in `keyValueMap` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
key - The keys of the HyperLogLog data structures to be analyzed.
Return value:
The approximated cardinality of given HyperLogLog data structures. The cardinality of a key that does not exist is `0`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := uuid.New().String() result, err := client.PfAdd(key, []string{"value1", "value2", "value3"}) result1, err := client.PfCount([]string{key}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 1 3
func (*GlideClient) Ping ¶
func (client *GlideClient) Ping() (string, error)
Pings the server.
Return value:
Returns "PONG".
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Ping() if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: PONG
func (*GlideClient) PingWithOptions ¶
func (client *GlideClient) PingWithOptions(pingOptions options.PingOptions) (string, error)
Pings the server.
Parameters:
pingOptions - The PingOptions type.
Return value:
Returns the copy of message.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function options := options.PingOptions{Message: "hello"} result, err := client.PingWithOptions(options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: hello
func (GlideClient) RPop ¶
Removes and returns the last elements of the list stored at key. The command pops a single element from the end of the list.
See valkey.io for details.
Parameters:
key - The key of the list.
Return value:
The Result[string] containing the value of the last element. If key does not exist, [api.CreateNilStringResult()] will be returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.RPop("my_list") result2, err := client.RPop("non_existing_key") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2.IsNil())
Output: 7 {e false} true
func (GlideClient) RPopCount ¶
Removes and returns up to count elements from the list stored at key, depending on the list's length.
See valkey.io for details.
Parameters:
key - The key of the list. count - The count of the elements to pop from the list.
Return value:
An array of popped elements as strings will be returned depending on the list's length. If key does not exist, nil will be returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.RPopCount("my_list", 4) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 7 [e e e d]
func (GlideClient) RPush ¶
Inserts all the specified values at the tail of the list stored at key. elements are inserted one after the other to the tail of the list, from the leftmost element to the rightmost element. If key does not exist, it is created as an empty list before performing the push operation.
See valkey.io for details.
Parameters:
key - The key of the list. elements - The elements to insert at the tail of the list stored at key.
Return value:
The length of the list after the push operation.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 7
func (GlideClient) RPushX ¶
Inserts all the specified values at the tail of the list stored at key, only if key exists and holds a list. If key is not a list, this performs no operation.
See valkey.io for details.
Parameters:
key - The key of the list. elements - The elements to insert at the tail of the list stored at key.
Return value:
The length of the list after the push operation.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.RPush("my_list", []string{"value1"}) result1, err := client.RPushX("my_list", []string{"value2", "value3"}) result2, err := client.LRange("my_list", 0, -1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 1 3 [value1 value2 value3]
func (GlideClient) Rename ¶
Renames key to new key.
If new Key already exists it is overwritten.
Note:
When in cluster mode, both key and newKey must map to the same hash slot.
Parameters:
key - The key to rename. newKey - The new name of the key.
Return value:
If the key was successfully renamed, return "OK". If key does not exist, an error is thrown.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.Rename("key1", "key2") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK OK
func (GlideClient) RenameNX ¶
Renames key to newkey if newKey does not yet exist.
Note:
When in cluster mode, both key and newkey must map to the same hash slot.
Parameters:
key - The key to rename. newKey - The new name of the key.
Return value:
`true` if key was renamed to `newKey`, `false` if `newKey` already exists.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.RenameNX("key1", "key2") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK true
func (GlideClient) Restore ¶
Create a key associated with a value that is obtained by deserializing the provided serialized value (obtained via valkey.io: Https://valkey.io/commands/dump/).
Parameters:
key - The key to create. ttl - The expiry time (in milliseconds). If 0, the key will persist. value - The serialized value to deserialize and assign to key.
Return value:
Return OK if successfully create a key with a value </code>.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key1", "someValue") dump, err := client.Dump("key1") result1, err := client.Del([]string{"key1"}) result2, err := client.Restore("key1", 0, dump.Value()) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2.Value())
Output: OK 1 OK
func (GlideClient) RestoreWithOptions ¶
func (client GlideClient) RestoreWithOptions(key string, ttl int64, value string, options options.RestoreOptions, ) (Result[string], error)
Create a key associated with a value that is obtained by deserializing the provided serialized value (obtained via valkey.io: Https://valkey.io/commands/dump/).
Parameters:
key - The key to create. ttl - The expiry time (in milliseconds). If 0, the key will persist. value - The serialized value to deserialize and assign to key. restoreOptions - Set restore options with replace and absolute TTL modifiers, object idletime and frequency.
Return value:
Return OK if successfully create a key with a value.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key1", "someValue") dump, err := client.Dump("key1") result1, err := client.Del([]string{"key1"}) opts := options.NewRestoreOptions().SetReplace().SetABSTTL().SetEviction(options.FREQ, 10) result2, err := client.RestoreWithOptions("key1", 0, dump.Value(), *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2.Value())
Output: OK 1 OK
func (GlideClient) SAdd ¶
SAdd adds specified members to the set stored at key.
See valkey.io for details.
Parameters:
key - The key where members will be added to its set. members - A list of members to add to the set stored at key.
Return value:
The number of members that were added to the set, excluding members already present.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "my_set" result, err := client.SAdd(key, []string{"member1", "member2"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 2
func (GlideClient) SCard ¶
SCard retrieves the set cardinality (number of elements) of the set stored at key.
See valkey.io for details.
Parameters:
key - The key from which to retrieve the number of set members.
Return value:
The cardinality (number of elements) of the set, or `0` if the key does not exist.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "my_set" client.SAdd(key, []string{"member1", "member2"}) result, err := client.SCard(key) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 2
func (GlideClient) SDiff ¶
SDiff computes the difference between the first set and all the successive sets in keys.
Note: When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
keys - The keys of the sets to diff.
Return value:
A `map[string]struct{}` representing the difference between the sets. If a key does not exist, it is treated as an empty set.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key1 := "my_set_1" key2 := "my_set_2" client.SAdd(key1, []string{"member1", "member2"}) client.SAdd(key2, []string{"member2"}) result, err := client.SDiff([]string{key1, key2}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: map[member1:{}]
func (GlideClient) SDiffStore ¶
SDiffStore stores the difference between the first set and all the successive sets in keys into a new set at destination.
Note: When in cluster mode, destination and all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
destination - The key of the destination set. keys - The keys of the sets to diff.
Return value:
The number of elements in the resulting set.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key1 := "my_set_1" key2 := "my_set_2" destination := "my_set_diff" client.SAdd(key1, []string{"member1", "member2"}) client.SAdd(key2, []string{"member2"}) result, err := client.SDiffStore(destination, []string{key1, key2}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 1
func (GlideClient) SInter ¶
SInter gets the intersection of all the given sets.
Note: When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
keys - The keys of the sets to intersect.
Return value:
A `map[string]struct{}` containing members which are present in all given sets. If one or more sets do not exist, an empty collection will be returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key1 := "my_set_1" key2 := "my_set_2" client.SAdd(key1, []string{"member1", "member2"}) client.SAdd(key2, []string{"member2"}) result, err := client.SInter([]string{key1, key2}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: map[member2:{}]
func (GlideClient) SInterCard ¶
SInterCard gets the cardinality of the intersection of all the given sets.
Since:
Valkey 7.0 and above.
Note: When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
keys - The keys of the sets to intersect.
Return value:
The cardinality of the intersection result. If one or more sets do not exist, `0` is returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key1 := "my_set_1" key2 := "my_set_2" client.SAdd(key1, []string{"member1", "member2"}) client.SAdd(key2, []string{"member2"}) result, err := client.SInterCard([]string{key1, key2}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 1
func (GlideClient) SInterCardLimit ¶
SInterCardLimit gets the cardinality of the intersection of all the given sets, up to the specified limit.
Since:
Valkey 7.0 and above.
Note: When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
keys - The keys of the sets to intersect. limit - The limit for the intersection cardinality value.
Return value:
The cardinality of the intersection result, or the limit if reached. If one or more sets do not exist, `0` is returned. If the intersection cardinality reaches 'limit' partway through the computation, returns 'limit' as the cardinality.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key1 := "my_set_1" key2 := "my_set_2" limit := int64(1) client.SAdd(key1, []string{"member1", "member2", "member3"}) client.SAdd(key2, []string{"member2", "member3"}) result, err := client.SInterCardLimit([]string{key1, key2}, limit) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 1
func (GlideClient) SInterStore ¶
Stores the members of the intersection of all given sets specified by `keys` into a new set at `destination`
Note: When in cluster mode, `destination` and all `keys` must map to the same hash slot.
See valkey.io for details.
Parameters:
destination - The key of the destination set. keys - The keys from which to retrieve the set members.
Return value:
The number of elements in the resulting set.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key1 := "my_set_1" key2 := "my_set_2" destination := "my_set_inter" client.SAdd(key1, []string{"member1", "member2"}) client.SAdd(key2, []string{"member2"}) result, err := client.SInterStore(destination, []string{key1, key2}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 1
func (GlideClient) SIsMember ¶
SIsMember returns if member is a member of the set stored at key.
See valkey.io for details.
Parameters:
key - The key of the set. member - The member to check for existence in the set.
Return value:
A bool containing true if the member exists in the set, false otherwise. If key doesn't exist, it is treated as an empty set and the method returns false.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "my_set" client.SAdd(key, []string{"member1", "member2"}) result, err := client.SIsMember(key, "member1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: true
func (GlideClient) SMIsMember ¶
SMIsMember returns whether each member is a member of the set stored at key.
See valkey.io for details.
Parameters:
key - The key of the set.
Return value:
A []bool containing whether each member is a member of the set stored at key.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "my_set" members := []string{"member1", "member2"} client.SAdd(key, members) memberTest := []string{"member1", "member2", "member3"} result, err := client.SMIsMember(key, memberTest) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: [true true false]
func (GlideClient) SMembers ¶
SMembers retrieves all the members of the set value stored at key.
See valkey.io for details.
Parameters:
key - The key from which to retrieve the set members.
Return value:
A `map[string]struct{}` containing all members of the set. Returns an empty collection if key does not exist.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "my_set" client.SAdd(key, []string{"member1", "member2"}) result, err := client.SMembers(key) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: map[member1:{} member2:{}]
func (GlideClient) SMove ¶
Moves `member` from the set at `source` to the set at `destination`, removing it from the source set. Creates a new destination set if needed. The operation is atomic.
Note: When in cluster mode, `source` and `destination` must map to the same hash slot.
See valkey.io for details.
Parameters:
source - The key of the set to remove the element from. destination - The key of the set to add the element to. member - The set element to move.
Return value:
`true` on success, or `false` if the `source` set does not exist or the element is not a member of the source set.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function source := "my_set_1" destination := "my_set_2" member := "member1" client.SAdd(source, []string{member}) result, err := client.SMove(source, destination, member) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: true
func (GlideClient) SPop ¶
SPop removes and returns one random member from the set stored at key.
See valkey.io for details.
Parameters:
key - The key of the set.
Return value:
A Result[string] containing the value of the popped member. Returns a NilResult if key does not exist.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "my_set" client.SAdd(key, []string{"member1", "member2"}) result, err := client.SPop(key) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.IsNil())
Output: false
func (GlideClient) SRandMember ¶
SRandMember returns a random element from the set value stored at key.
See valkey.io for details.
Parameters:
key - The key from which to retrieve the set member.
Return value:
A Result[string] containing a random element from the set. Returns api.CreateNilStringResult() if key does not exist.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "my_set" client.SAdd(key, []string{"member1", "member2"}) result, err := client.SRandMember(key) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.IsNil()) // Unable to test for a random value so just check if it is not nil
Output: false
func (GlideClient) SRem ¶
SRem removes specified members from the set stored at key.
See valkey.io for details.
Parameters:
key - The key from which members will be removed. members - A list of members to remove from the set stored at key.
Return value:
The number of members that were removed from the set, excluding non-existing members.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "my_set" client.SAdd(key, []string{"member1", "member2"}) result, err := client.SRem(key, []string{"member1", "member2"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 2
func (GlideClient) SScan ¶
Iterates incrementally over a set.
Note: When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
key - The key of the set. cursor - The cursor that points to the next iteration of results. A value of `"0"` indicates the start of the search. For Valkey 8.0 and above, negative cursors are treated like the initial cursor("0").
Return value:
An array of the cursor and the subset of the set held by `key`. The first element is always the `cursor` and for the next iteration of results. The `cursor` will be `"0"` on the last iteration of the set. The second element is always an array of the subset of the set held in `key`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "my_set" client.SAdd(key, []string{"member1", "member2"}) cursor := "0" result, nextCursor, err := client.SScan(key, cursor) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result, nextCursor)
Output: 0 [member1 member2]
func (GlideClient) SScanWithOptions ¶
func (client GlideClient) SScanWithOptions( key string, cursor string, options options.BaseScanOptions, ) (string, []string, error)
Iterates incrementally over a set.
Note: When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
key - The key of the set. cursor - The cursor that points to the next iteration of results. A value of `"0"` indicates the start of the search. For Valkey 8.0 and above, negative cursors are treated like the initial cursor("0"). options - [options.BaseScanOptions]
Return value:
An array of the cursor and the subset of the set held by `key`. The first element is always the `cursor` and for the next iteration of results. The `cursor` will be `"0"` on the last iteration of the set. The second element is always an array of the subset of the set held in `key`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "my_set" client.SAdd(key, []string{"member1", "member2", "item3"}) cursor := "0" options := options.NewBaseScanOptions().SetMatch("mem*") result, nextCursor, err := client.SScanWithOptions(key, cursor, *options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result, nextCursor)
Output: 0 [member1 member2]
func (GlideClient) SUnion ¶
SUnion gets the union of all the given sets.
Note: When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
keys - The keys of the sets.
Return value:
A `map[string]struct{}` of members which are present in at least one of the given sets. If none of the sets exist, an empty collection will be returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key1 := "my_set_1" key2 := "my_set_2" client.SAdd(key1, []string{"member1", "member2"}) client.SAdd(key2, []string{"member2", "member3"}) result, err := client.SUnion([]string{key1, key2}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: map[member1:{} member2:{} member3:{}]
func (GlideClient) SUnionStore ¶
SUnionStore stores the members of the union of all given sets specified by `keys` into a new set at `destination`.
Note: When in cluster mode, `destination` and all `keys` must map to the same hash slot.
See valkey.io for details.
Parameters:
destination - The key of the destination set. keys - The keys from which to retrieve the set members.
Return value:
The number of elements in the resulting set.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key1 := "my_set_1" key2 := "my_set_2" destination := "my_set_union" client.SAdd(key1, []string{"member1", "member2"}) client.SAdd(key2, []string{"member2", "member3"}) result, err := client.SUnionStore(destination, []string{key1, key2}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 3
func (*GlideClient) Select ¶
func (client *GlideClient) Select(index int64) (string, error)
Select changes the currently selected database.
Parameters:
index - The index of the database to select.
Return value:
A simple `"OK"` response.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Select(2) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: OK
func (GlideClient) Set ¶
Set the given key with the given value. The return value is a response from Valkey containing the string "OK".
See valkey.io for details.
Parameters:
key - The key to store. value - The value to store with the given key.
Return value:
`"OK"` response on success.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("my_key", "my_value") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: OK
func (GlideClient) SetBit ¶
Sets or clears the bit at offset in the string value stored at key. The offset is a zero-based index, with `0` being the first element of the list, `1` being the next element, and so on. The offset must be less than `2^32` and greater than or equal to `0` If a key is non-existent then the bit at offset is set to value and the preceding bits are set to `0`.
Parameters:
key - The key of the string. offset - The index of the bit to be set. value - The bit value to set at offset The value must be `0` or `1`.
Return value:
The bit value that was previously stored at offset.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.SetBit("my_key", 1, 1) // initialize bit 1 with a value of 1 result, err := client.SetBit("my_key", 1, 1) // set bit should return the previous value of bit 1 if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 1
func (GlideClient) SetRange ¶
Overwrites part of the string stored at key, starting at the specified byte's 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. Creates the key if it doesn't exist.
See valkey.io for details.
Parameters:
key - The key of the string to update. offset - The position in the string where value should be written. value - The string written with offset.
Return value:
The length of the string stored at `key` after it was modified.
Example (One) ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Set("my_key", "my_value") result, err := client.SetRange("my_key", 3, "example") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) value, _ := client.Get("my_key") fmt.Println(value.Value())
Output: 10 my_example
Example (Two) ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Set("my_key", "愛") // "愛" is a single character in UTF-8, but 3 bytes long result, err := client.SetRange("my_key", 1, "a") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 3
func (GlideClient) SetWithOptions ¶
func (client GlideClient) SetWithOptions(key string, value string, options options.SetOptions) (Result[string], error)
SetWithOptions sets the given key with the given value using the given options. The return value is dependent on the passed options. If the value is successfully set, "OK" is returned. If value isn't set because of [OnlyIfExists] or [OnlyIfDoesNotExist] conditions, api.CreateNilStringResult() is returned. If [SetOptions#ReturnOldValue] is set, the old value is returned.
See valkey.io for details.
Parameters:
key - The key to store. value - The value to store with the given key. options - The [api.SetOptions].
Return value:
If the value is successfully set, return api.Result[string] containing "OK". If value isn't set because of ConditionalSet.OnlyIfExists or ConditionalSet.OnlyIfDoesNotExist conditions, return api.CreateNilStringResult(). If SetOptions.returnOldValue is set, return the old value as a String.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function options := options.NewSetOptions(). SetExpiry(options.NewExpiry(). SetType(options.Seconds). SetCount(5)) result, err := client.SetWithOptions("my_key", "my_value", *options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.Value())
Output: OK
func (GlideClient) Sort ¶
Sorts the elements in the list, set, or sorted set at key and returns the result. The sort command can be used to sort elements based on different criteria and apply transformations on sorted elements. To store the result into a new key, see the sortStore function.
Parameters:
key - The key of the list, set, or sorted set to be sorted.
Return value:
An Array of sorted elements.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("key1", []string{"1", "3", "2", "4"}) result1, err := client.Sort("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 [{1 false} {2 false} {3 false} {4 false}]
func (GlideClient) SortReadOnly ¶
Sorts the elements in the list, set, or sorted set at key and returns the result. The sortReadOnly command can be used to sort elements based on different criteria and apply transformations on sorted elements. This command is routed depending on the client's ReadFrom strategy.
Parameters:
key - The key of the list, set, or sorted set to be sorted.
Return value:
An Array of sorted elements.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("key1", []string{"1", "3", "2", "4"}) result1, err := client.SortReadOnly("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 [{1 false} {2 false} {3 false} {4 false}]
func (GlideClient) SortReadOnlyWithOptions ¶
func (client GlideClient) SortReadOnlyWithOptions(key string, options options.SortOptions) ([]Result[string], error)
Sorts the elements in the list, set, or sorted set at key and returns the result. The sort command can be used to sort elements based on different criteria and apply transformations on sorted elements. This command is routed depending on the client's ReadFrom strategy.
Note:
In cluster mode, if `key` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity. The use of SortOptions.byPattern and SortOptions.getPatterns in cluster mode is supported since Valkey version 8.0.
Parameters:
key - The key of the list, set, or sorted set to be sorted. sortOptions - The SortOptions type.
Return value:
An Array of sorted elements.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function opts := options.NewSortOptions().SetByPattern("weight_*").SetIsAlpha(false).SetOrderBy(options.ASC) client.Set("weight_item1", "3") client.Set("weight_item2", "1") client.Set("weight_item3", "2") result, err := client.LPush("key1", []string{"item1", "item2", "item3"}) result1, err := client.SortReadOnlyWithOptions("key1", *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 [{item2 false} {item3 false} {item1 false}]
func (GlideClient) SortStore ¶
Sorts the elements in the list, set, or sorted set at key and stores the result in destination. The sort command can be used to sort elements based on different criteria, apply transformations on sorted elements, and store the result in a new key. The sort command can be used to sort elements based on different criteria and apply transformations on sorted elements. To get the sort result without storing it into a key, see the sort or sortReadOnly function.
Note:
In cluster mode, if `key` and `destination` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
key - The key of the list, set, or sorted set to be sorted. destination - The key where the sorted result will be stored.
Return value:
The number of elements in the sorted key stored at destination.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("key1", []string{"1", "3", "2", "4"}) result1, err := client.SortStore("key1", "key1_store") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 4
func (GlideClient) SortStoreWithOptions ¶
func (client GlideClient) SortStoreWithOptions( key string, destination string, opts options.SortOptions, ) (int64, error)
Sorts the elements in the list, set, or sorted set at key and stores the result in destination. The sort command can be used to sort elements based on different criteria, apply transformations on sorted elements, and store the result in a new key. The sort command can be used to sort elements based on different criteria and apply transformations on sorted elements. To get the sort result without storing it into a key, see the sort or sortReadOnly function.
Note:
In cluster mode, if `key` and `destination` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity. The use of SortOptions.byPattern and SortOptions.getPatterns in cluster mode is supported since Valkey version 8.0.
Parameters: key - The key of the list, set, or sorted set to be sorted. destination - The key where the sorted result will be stored. opts - The options.SortOptions type.
Return value:
The number of elements in the sorted key stored at destination.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function opts := options.NewSortOptions().SetByPattern("weight_*").SetIsAlpha(false).SetOrderBy(options.ASC) client.Set("weight_item1", "3") client.Set("weight_item2", "1") client.Set("weight_item3", "2") result, err := client.LPush("key1", []string{"item1", "item2", "item3"}) result1, err := client.SortStoreWithOptions("key1", "key1_store", *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 3
func (GlideClient) SortWithOptions ¶
func (client GlideClient) SortWithOptions(key string, options options.SortOptions) ([]Result[string], error)
Sorts the elements in the list, set, or sorted set at key and returns the result. The sort command can be used to sort elements based on different criteria and apply transformations on sorted elements. To store the result into a new key, see the sortStore function.
Note:
In cluster mode, if `key` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity. The use of SortOptions.byPattern and SortOptions.getPatterns in cluster mode is supported since Valkey version 8.0.
Parameters:
key - The key of the list, set, or sorted set to be sorted. sortOptions - The SortOptions type.
Return value:
An Array of sorted elements.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function opts := options.NewSortOptions().SetByPattern("weight_*").SetIsAlpha(false).SetOrderBy(options.ASC) client.Set("weight_item1", "3") client.Set("weight_item2", "1") client.Set("weight_item3", "2") result, err := client.LPush("key1", []string{"item1", "item2", "item3"}) result1, err := client.SortWithOptions("key1", *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 [{item2 false} {item3 false} {item1 false}]
func (GlideClient) Strlen ¶
Returns the length of the string value stored at key.
See valkey.io for details.
Parameters:
key - The key to check its length.
Return value:
The length of the string value stored at `key`. If key does not exist, it is treated as an empty string, and the command returns `0`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Set("my_key", "my_value") result, err := client.Strlen("my_key") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 8
func (GlideClient) TTL ¶
TTL returns the remaining time to live of key that has a timeout, in seconds.
Parameters:
key - The key to return its timeout.
Return value:
Returns TTL in seconds, `-2` if key does not exist, or `-1` if key exists but has no associated expiration.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.TTL("key") _, err = client.ExpireAt("key", time.Now().Unix()*1000) // TTL("key") returns proper TTL in seconds if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK -1
func (GlideClient) Time ¶
Returns the server time.
Return value:
The current server time as a String array with two elements: A UNIX TIME and the amount of microseconds already elapsed in the current second. The returned array is in a [UNIX TIME, Microseconds already elapsed] format.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function timeMargin := int64(5) clientTime := time.Now().Unix() result, err := client.Time() if err != nil { fmt.Println("Glide example failed with an error: ", err) } serverTime, _ := strconv.ParseInt(result[0], 10, 64) fmt.Println((serverTime - clientTime) < timeMargin)
Output: true
func (GlideClient) Touch ¶
Alters the last access time of a key(s). A key is ignored if it does not exist.
Note:
In cluster mode, if keys in keys map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
keys - The keys to update last access time.
Return value:
The number of keys that were updated.
[valkey.io]: Https://valkey.io/commands/touch/
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.Set("key2", "someValue") result2, err := client.Touch([]string{"key1", "key2", "key3"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: OK OK 2
func (GlideClient) Type ¶
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.
Parameters:
key - string
Return value:
If the key exists, the type of the stored value is returned. Otherwise, a "none" string is returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.Type("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK string
func (GlideClient) Unlink ¶
Unlink (delete) multiple keys from the database. A key is ignored if it does not exist. This command, similar to Del However, this command does not block the server
Note:
In cluster mode, if keys in keys map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
keys - One or more keys to unlink.
Return value:
Return the number of keys that were unlinked.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.Set("key2", "someValue") result2, err := client.Unlink([]string{"key1", "key2", "key3"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: OK OK 2
func (GlideClient) Wait ¶
Wait blocks the current client until all the previous write commands are successfully transferred and acknowledged by at least the specified number of replicas or if the timeout is reached, whichever is earlier
Parameters:
numberOfReplicas - The number of replicas to reach. timeout - The timeout value specified in milliseconds. A value of `0` will block indefinitely.
Return value:
The number of replicas reached by all the writes performed in the context of the current connection.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.Set("key1", "someValue") result, err := client.Wait(2, 1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } // Wait returns different results each time. Check it is the proper return type instead fmt.Println(result < 10)
Output: true
func (GlideClient) XAck ¶
Returns the number of messages that were successfully acknowledged by the consumer group member of a stream. This command should be called on a pending message so that such message does not get processed again.
See valkey.io for details.
Parameters:
key - The key of the stream. group - he consumer group name. ids - Stream entry IDs to acknowledge and purge messages.
Return value:
The number of messages that were successfully acknowledged.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" group := "g12345" consumer := "c12345" streamId, _ := client.XAdd( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, ) client.XGroupCreate(key, group, "0") client.XGroupCreateConsumer(key, group, consumer) client.XReadGroup(group, consumer, map[string]string{key: ">"}) count, err := client.XAck(key, group, []string{streamId.Value()}) // ack the message and remove it from the pending list if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(count)
Output: 1
func (GlideClient) XAdd ¶
Adds an entry to the specified stream stored at `key`. If the `key` doesn't exist, the stream is created.
See valkey.io for details.
Parameters:
key - The key of the stream. values - Field-value pairs to be added to the entry.
Return value:
The id of the added entry.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.XAdd("mystream", [][]string{ {"key1", "value1"}, {"key2", "value2"}, }) if err != nil { fmt.Println("Glide example failed with an error: ", err) } matches, _ := regexp.Match( `^\d{13}-0$`, []byte(result.Value()), ) // matches a number that is 13 digits long followed by "-0" fmt.Println(matches)
Output: true
func (GlideClient) XAddWithOptions ¶
func (client GlideClient) XAddWithOptions( key string, values [][]string, options options.XAddOptions, ) (Result[string], error)
Adds an entry to the specified stream stored at `key`. If the `key` doesn't exist, the stream is created.
See valkey.io for details.
Parameters:
key - The key of the stream. values - Field-value pairs to be added to the entry. options - Stream add options.
Return value:
The id of the added entry.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function options := options.NewXAddOptions(). SetId("1000-50") values := [][]string{ {"key1", "value1"}, {"key2", "value2"}, } result, err := client.XAddWithOptions("mystream", values, *options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.Value())
Output: 1000-50
func (GlideClient) XAutoClaim ¶
func (client GlideClient) XAutoClaim( key string, group string, consumer string, minIdleTime int64, start string, ) (XAutoClaimResponse, error)
Transfers ownership of pending stream entries that match the specified criteria.
Since:
Valkey 6.2.0 and above.
See valkey.io for more details.
Parameters:
key - The key of the stream. group - The consumer group name. consumer - The group consumer. minIdleTime - The minimum idle time for the message to be claimed. start - Filters the claimed entries to those that have an ID equal or greater than the specified value.
Return value:
An object containing the following elements: - A stream ID to be used as the start argument for the next call to `XAUTOCLAIM`. This ID is equivalent to the next ID in the stream after the entries that were scanned, or "0-0" if the entire stream was scanned. - A map of the claimed entries. - If you are using Valkey 7.0.0 or above, the response will also include an array containing the message IDs that were in the Pending Entries List but no longer exist in the stream. These IDs are deleted from the Pending Entries List.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := uuid.NewString() group := uuid.NewString() consumer := uuid.NewString() client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId("0-1"), ) client.XAddWithOptions( key, [][]string{{"entry2_field1", "entry2_value1"}}, *options.NewXAddOptions().SetId("0-2"), ) client.XReadGroup(group, consumer, map[string]string{key: ">"}) response, err := client.XAutoClaim(key, group, consumer, 0, "0-1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: {0-0 map[0-1:[[entry1_field1 entry1_value1] [entry1_field2 entry1_value2]] 0-2:[[entry2_field1 entry2_value1]]] []}
func (GlideClient) XAutoClaimJustId ¶
func (client GlideClient) XAutoClaimJustId( key string, group string, consumer string, minIdleTime int64, start string, ) (XAutoClaimJustIdResponse, error)
Transfers ownership of pending stream entries that match the specified criteria.
Since:
Valkey 6.2.0 and above.
See valkey.io for more details.
Parameters:
key - The key of the stream. group - The consumer group name. consumer - The group consumer. minIdleTime - The minimum idle time for the message to be claimed. start - Filters the claimed entries to those that have an ID equal or greater than the specified value.
Return value:
An object containing the following elements: - A stream ID to be used as the start argument for the next call to `XAUTOCLAIM`. This ID is equivalent to the next ID in the stream after the entries that were scanned, or "0-0" if the entire stream was scanned. - An array of IDs for the claimed entries. - If you are using Valkey 7.0.0 or above, the response will also include an array containing the message IDs that were in the Pending Entries List but no longer exist in the stream. These IDs are deleted from the Pending Entries List.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := uuid.NewString() group := uuid.NewString() consumer := uuid.NewString() client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId("0-1"), ) client.XAddWithOptions( key, [][]string{{"entry2_field1", "entry2_value1"}}, *options.NewXAddOptions().SetId("0-2"), ) client.XReadGroup(group, consumer, map[string]string{key: ">"}) response, err := client.XAutoClaimJustId(key, group, consumer, 0, "0-0") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: {0-0 [0-1 0-2] []}
func (GlideClient) XAutoClaimJustIdWithOptions ¶
func (client GlideClient) XAutoClaimJustIdWithOptions( key string, group string, consumer string, minIdleTime int64, start string, opts options.XAutoClaimOptions, ) (XAutoClaimJustIdResponse, error)
Transfers ownership of pending stream entries that match the specified criteria.
Since:
Valkey 6.2.0 and above.
See valkey.io for more details.
Parameters:
key - The key of the stream. group - The consumer group name. consumer - The group consumer. minIdleTime - The minimum idle time for the message to be claimed. start - Filters the claimed entries to those that have an ID equal or greater than the specified value. opts - Options detailing how to read the stream.
Return value:
An object containing the following elements: - A stream ID to be used as the start argument for the next call to `XAUTOCLAIM`. This ID is equivalent to the next ID in the stream after the entries that were scanned, or "0-0" if the entire stream was scanned. - An array of IDs for the claimed entries. - If you are using Valkey 7.0.0 or above, the response will also include an array containing the message IDs that were in the Pending Entries List but no longer exist in the stream. These IDs are deleted from the Pending Entries List.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := uuid.NewString() group := uuid.NewString() consumer := uuid.NewString() client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId("0-1"), ) client.XAddWithOptions( key, [][]string{{"entry2_field1", "entry2_value1"}}, *options.NewXAddOptions().SetId("0-2"), ) client.XReadGroup(group, consumer, map[string]string{key: ">"}) options := options.NewXAutoClaimOptions().SetCount(1) response, err := client.XAutoClaimJustIdWithOptions(key, group, consumer, 0, "0-1", *options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: {0-2 [0-1] []}
func (GlideClient) XAutoClaimWithOptions ¶
func (client GlideClient) XAutoClaimWithOptions( key string, group string, consumer string, minIdleTime int64, start string, options options.XAutoClaimOptions, ) (XAutoClaimResponse, error)
Transfers ownership of pending stream entries that match the specified criteria.
Since:
Valkey 6.2.0 and above.
See valkey.io for more details.
Parameters:
key - The key of the stream. group - The consumer group name. consumer - The group consumer. minIdleTime - The minimum idle time for the message to be claimed. start - Filters the claimed entries to those that have an ID equal or greater than the specified value. options - Options detailing how to read the stream.
Return value:
An object containing the following elements: - A stream ID to be used as the start argument for the next call to `XAUTOCLAIM`. This ID is equivalent to the next ID in the stream after the entries that were scanned, or "0-0" if the entire stream was scanned. - A map of the claimed entries. - If you are using Valkey 7.0.0 or above, the response will also include an array containing the message IDs that were in the Pending Entries List but no longer exist in the stream. These IDs are deleted from the Pending Entries List.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := uuid.NewString() group := uuid.NewString() consumer := uuid.NewString() client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId("0-1"), ) client.XAddWithOptions( key, [][]string{{"entry2_field1", "entry2_value1"}}, *options.NewXAddOptions().SetId("0-2"), ) client.XReadGroup(group, consumer, map[string]string{key: ">"}) options := options.NewXAutoClaimOptions().SetCount(1) response, err := client.XAutoClaimWithOptions(key, group, consumer, 0, "0-1", *options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: {0-2 map[0-1:[[entry1_field1 entry1_value1] [entry1_field2 entry1_value2]]] []}
func (GlideClient) XClaim ¶
func (client GlideClient) XClaim( key string, group string, consumer string, minIdleTime int64, ids []string, ) (map[string][][]string, error)
Changes the ownership of a pending message.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The name of the consumer group. consumer - The name of the consumer. minIdleTime - The minimum idle time in milliseconds. ids - The ids of the entries to claim.
Return value:
A `map of message entries with the format `{"entryId": [["entry", "data"], ...], ...}` that were claimed by the consumer.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" streamId := "12345-1" group := "g12345" consumer1 := "c12345-1" consumer2 := "c12345-2" client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer1) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) client.XReadGroup(group, consumer1, map[string]string{key: ">"}) result, err := client.XPendingWithOptions( key, group, *options.NewXPendingOptions("-", "+", 10).SetConsumer(consumer1), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } if len(result) == 0 { fmt.Println("No pending messages") return } response, err := client.XClaim(key, group, consumer2, result[0].IdleTime, []string{result[0].Id}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Printf("Claimed %d message\n", len(response))
Output: Claimed 1 message
func (GlideClient) XClaimJustId ¶
func (client GlideClient) XClaimJustId( key string, group string, consumer string, minIdleTime int64, ids []string, ) ([]string, error)
Changes the ownership of a pending message. This function returns an `array` with only the message/entry IDs, and is equivalent to using `JUSTID` in the Valkey API.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The name of the consumer group. consumer - The name of the consumer. minIdleTime - The minimum idle time in milliseconds. ids - The ids of the entries to claim. options - Stream claim options.
Return value:
An array of the ids of the entries that were claimed by the consumer.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" streamId := "12345-1" group := "g12345" consumer1 := "c12345-1" consumer2 := "c12345-2" client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer1) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) client.XReadGroup(group, consumer1, map[string]string{key: ">"}) result, err := client.XPendingWithOptions( key, group, *options.NewXPendingOptions("-", "+", 10).SetConsumer(consumer1), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } if len(result) == 0 { fmt.Println("No pending messages") return } response, err := client.XClaimJustId(key, group, consumer2, result[0].IdleTime, []string{result[0].Id}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: [12345-1]
func (GlideClient) XClaimJustIdWithOptions ¶
func (client GlideClient) XClaimJustIdWithOptions( key string, group string, consumer string, minIdleTime int64, ids []string, opts options.XClaimOptions, ) ([]string, error)
Changes the ownership of a pending message. This function returns an `array` with only the message/entry IDs, and is equivalent to using `JUSTID` in the Valkey API.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The name of the consumer group. consumer - The name of the consumer. minIdleTime - The minimum idle time in milliseconds. ids - The ids of the entries to claim. options - Stream claim options.
Return value:
An array of the ids of the entries that were claimed by the consumer.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" streamId := "12345-1" group := "g12345" consumer1 := "c12345-1" consumer2 := "c12345-2" client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer1) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) client.XReadGroup(group, consumer1, map[string]string{key: ">"}) result, err := client.XPendingWithOptions( key, group, *options.NewXPendingOptions("-", "+", 10).SetConsumer(consumer1), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } if len(result) == 0 { fmt.Println("No pending messages") return } opts := options.NewXClaimOptions().SetRetryCount(3) response, err := client.XClaimJustIdWithOptions(key, group, consumer2, result[0].IdleTime, []string{result[0].Id}, *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: [12345-1]
func (GlideClient) XClaimWithOptions ¶
func (client GlideClient) XClaimWithOptions( key string, group string, consumer string, minIdleTime int64, ids []string, opts options.XClaimOptions, ) (map[string][][]string, error)
Changes the ownership of a pending message.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The name of the consumer group. consumer - The name of the consumer. minIdleTime - The minimum idle time in milliseconds. ids - The ids of the entries to claim. options - Stream claim options.
Return value:
A `map` of message entries with the format `{"entryId": [["entry", "data"], ...], ...}` that were claimed by the consumer.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" streamId := "12345-1" group := "g12345" consumer1 := "c12345-1" consumer2 := "c12345-2" client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer1) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) client.XReadGroup(group, consumer1, map[string]string{key: ">"}) result, err := client.XPendingWithOptions( key, group, *options.NewXPendingOptions("-", "+", 10).SetConsumer(consumer1), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } if len(result) == 0 { fmt.Println("No pending messages") return } opts := options.NewXClaimOptions().SetRetryCount(3) response, err := client.XClaimWithOptions(key, group, consumer2, result[0].IdleTime, []string{result[0].Id}, *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Printf("Claimed %d message\n", len(response))
Output: Claimed 1 message
func (GlideClient) XDel ¶
Removes the specified entries by id from a stream, and returns the number of entries deleted.
See valkey.io for details.
Parameters:
key - The key of the stream. ids - An array of entry ids.
Return value:
The number of entries removed from the stream. This number may be less than the number of entries in `ids`, if the specified `ids` don't exist in the stream.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" client.XAddWithOptions( key, [][]string{{"field1", "value1"}, {"field2", "value2"}}, *options.NewXAddOptions().SetId("0-1"), ) count, err := client.XDel(key, []string{"0-1", "0-2", "0-3"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(count)
Output: 1
func (GlideClient) XGroupCreate ¶
Creates a new consumer group uniquely identified by `group` for the stream stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The newly created consumer group name. id - Stream entry ID that specifies the last delivered entry in the stream from the new group’s perspective. The special ID `"$"` can be used to specify the last entry in the stream.
Return value:
`"OK"`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" streamId := "12345-1" group := "g12345" client.XAddWithOptions( key, [][]string{{"field1", "value1"}, {"field2", "value2"}}, *options.NewXAddOptions().SetId(streamId), ) // This will create the stream if it does not exist response, err := client.XGroupCreate(key, group, "0") // create the group (no MKSTREAM needed) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: OK
func (GlideClient) XGroupCreateConsumer ¶
func (client GlideClient) XGroupCreateConsumer( key string, group string, consumer string, ) (bool, error)
XGroupCreateConsumer creates a consumer named `consumer` in the consumer group `group` for the stream stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The consumer group name. consumer - The newly created consumer.
Return value:
Returns `true` if the consumer is created. Otherwise, returns `false`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" group := "g12345" consumer := "c12345" opts := options.NewXGroupCreateOptions().SetMakeStream() client.XGroupCreateWithOptions(key, group, "0", *opts) // create the group (no MKSTREAM needed) success, err := client.XGroupCreateConsumer(key, group, consumer) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(success)
Output: true
func (GlideClient) XGroupCreateWithOptions ¶
func (client GlideClient) XGroupCreateWithOptions( key string, group string, id string, opts options.XGroupCreateOptions, ) (string, error)
Creates a new consumer group uniquely identified by `group` for the stream stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The newly created consumer group name. id - Stream entry ID that specifies the last delivered entry in the stream from the new group's perspective. The special ID `"$"` can be used to specify the last entry in the stream. opts - The options for the command. See [options.XGroupCreateOptions] for details.
Return value:
`"OK"`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" group := "g12345" opts := options.NewXGroupCreateOptions().SetMakeStream() response, err := client.XGroupCreateWithOptions(key, group, "0", *opts) // create the group (no MKSTREAM needed) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: OK
func (GlideClient) XGroupDelConsumer ¶
func (client GlideClient) XGroupDelConsumer( key string, group string, consumer string, ) (int64, error)
XGroupDelConsumer deletes a consumer named `consumer` in the consumer group `group`.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The consumer group name. consumer - The consumer to delete.
Return value:
The number of pending messages the `consumer` had before it was deleted.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" group := "g12345" consumer := "c12345" streamId := "12345-1" client.XAddWithOptions( key, [][]string{{"field1", "value1"}, {"field2", "value2"}}, *options.NewXAddOptions().SetId(streamId), ) client.XGroupCreate(key, group, "0") client.XGroupCreateConsumer(key, group, consumer) client.XReadGroup(group, consumer, map[string]string{key: ">"}) count, err := client.XGroupDelConsumer(key, group, consumer) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println("Consumer deleted. Messages pending:", count)
Output: Consumer deleted. Messages pending: 1
func (GlideClient) XGroupDestroy ¶
Destroys the consumer group `group` for the stream stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The consumer group name to delete.
Return value:
`true` if the consumer group is destroyed. Otherwise, `false`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" group := "g12345" opts := options.NewXGroupCreateOptions().SetMakeStream() client.XGroupCreateWithOptions(key, group, "0", *opts) // create the group (no MKSTREAM needed) success, err := client.XGroupDestroy(key, group) // destroy the group if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(success)
Output: true
func (GlideClient) XGroupSetId ¶
Sets the last delivered ID for a consumer group.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The consumer group name. id - The stream entry ID that should be set as the last delivered ID for the consumer group.
Return value:
`"OK"`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" streamId := "12345-1" group := "g12345" consumer := "c12345" client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) client.XReadGroup(group, consumer, map[string]string{key: ">"}) client.XAck(key, group, []string{streamId}) // ack the message and remove it from the pending list client.XGroupSetId(key, group, "0-0") // reset the last acknowledged message to 0-0 client.XReadGroup(group, consumer, map[string]string{key: ">"}) // read the group again summary, err := client.XPending(key, group) // get the pending messages, which should include the entry we previously acked if err != nil { fmt.Println("Glide example failed with an error: ", err) } jsonSummary, _ := json.Marshal(summary) fmt.Println(string(jsonSummary))
Output: {"NumOfMessages":1,"StartId":{},"EndId":{},"ConsumerMessages":[{"ConsumerName":"c12345","MessageCount":1}]}
func (GlideClient) XGroupSetIdWithOptions ¶
func (client GlideClient) XGroupSetIdWithOptions( key string, group string, id string, opts options.XGroupSetIdOptions, ) (string, error)
Sets the last delivered ID for a consumer group.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The consumer group name. id - The stream entry ID that should be set as the last delivered ID for the consumer group. opts - The options for the command. See [options.XGroupSetIdOptions] for details.
Return value:
`"OK"`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" streamId1 := "12345-1" streamId2 := "12345-2" group := "g12345" consumer := "c12345" client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"field1", "value1"}, {"field2", "value2"}}, *options.NewXAddOptions().SetId(streamId1), ) client.XAddWithOptions( key, [][]string{{"field3", "value3"}, {"field4", "value4"}}, *options.NewXAddOptions().SetId(streamId2), ) client.XReadGroup(group, consumer, map[string]string{key: ">"}) client.XAck(key, group, []string{streamId1, streamId2}) // ack the message and remove it from the pending list opts := options.NewXGroupSetIdOptionsOptions().SetEntriesRead(1) client.XGroupSetIdWithOptions(key, group, "0-0", *opts) // reset the last acknowledged message to 0-0 client.XReadGroup(group, consumer, map[string]string{key: ">"}) // read the group again summary, err := client.XPending(key, group) // get the pending messages, which should include the entry we previously acked if err != nil { fmt.Println("Glide example failed with an error: ", err) } jsonSummary, _ := json.Marshal(summary) fmt.Println(string(jsonSummary))
Output: {"NumOfMessages":2,"StartId":{},"EndId":{},"ConsumerMessages":[{"ConsumerName":"c12345","MessageCount":2}]}
func (GlideClient) XLen ¶
Returns the number of entries in the stream stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the stream.
Return value:
The number of entries in the stream. If `key` does not exist, return 0.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.XAdd("mystream", [][]string{{"field1", "foo4"}, {"field2", "bar4"}}) count, err := client.XLen("mystream") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(count)
Output: 1
func (GlideClient) XPending ¶
func (client GlideClient) XPending(key string, group string) (XPendingSummary, error)
Returns stream message summary information for pending messages matching a stream and group.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The consumer group name.
Return value:
An XPendingSummary struct that includes a summary with the following fields:
NumOfMessages - The total number of pending messages for this consumer group. StartId - The smallest ID among the pending messages or nil if no pending messages exist. EndId - The greatest ID among the pending messages or nil if no pending messages exists. GroupConsumers - An array of ConsumerPendingMessages with the following fields: ConsumerName - The name of the consumer. MessageCount - The number of pending messages for this consumer.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" streamId := "12345-1" group := "g12345" consumer := "c12345" client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) client.XReadGroup(group, consumer, map[string]string{key: ">"}) summary, err := client.XPending(key, group) if err != nil { fmt.Println("Glide example failed with an error: ", err) } jsonSummary, _ := json.Marshal(summary) fmt.Println(string(jsonSummary))
Output: {"NumOfMessages":1,"StartId":{},"EndId":{},"ConsumerMessages":[{"ConsumerName":"c12345","MessageCount":1}]}
func (GlideClient) XPendingWithOptions ¶
func (client GlideClient) XPendingWithOptions( key string, group string, opts options.XPendingOptions, ) ([]XPendingDetail, error)
Returns stream message summary information for pending messages matching a given range of IDs.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The consumer group name. opts - The options for the command. See [options.XPendingOptions] for details.
Return value:
A slice of XPendingDetail structs, where each detail struct includes the following fields:
Id - The ID of the pending message. ConsumerName - The name of the consumer that fetched the message and has still to acknowledge it. IdleTime - The time in milliseconds since the last time the message was delivered to the consumer. DeliveryCount - The number of times this message was delivered.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" streamId := "12345-1" group := "g12345" consumer := "c12345" client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) client.XReadGroup(group, consumer, map[string]string{key: ">"}) details, err := client.XPendingWithOptions( key, group, *options.NewXPendingOptions("-", "+", 10).SetConsumer(consumer), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } jsonDetails, _ := json.Marshal(details) // Since IdleTime can vary, check that output has all fields fields := []string{"\"Id\"", "\"ConsumerName\"", "\"IdleTime\"", "\"DeliveryCount\""} hasFields := true jsonStr := string(jsonDetails) for _, field := range fields { hasFields = strings.Contains(jsonStr, field) if !hasFields { break } } fmt.Println(hasFields)
Output: true
func (GlideClient) XRange ¶
func (client GlideClient) XRange( key string, start options.StreamBoundary, end options.StreamBoundary, ) ([]XRangeResponse, error)
Returns stream entries matching a given range of IDs.
See valkey.io for details.
Parameters:
key - The key of the stream. start - The start position. Use `options.NewStreamBoundary()` to specify a stream entry ID and its inclusive/exclusive status. Use `options.NewInfiniteStreamBoundary()` to specify an infinite stream boundary. end - The end position. Use `options.NewStreamBoundary()` to specify a stream entry ID and its inclusive/exclusive status. Use `options.NewInfiniteStreamBoundary()` to specify an infinite stream boundary.
Return value:
An `array` of stream entry data, where entry data is an array of pairings with format `[[field, entry], [field, entry], ...]`. Returns `nil` if `count` is non-positive. fmt.Println(res) // map[key:[["field1", "entry1"], ["field2", "entry2"]]] fmt.Println(res) // map[key:[["field1", "entry1"]]
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" client.XAdd(key, [][]string{{"field1", "value1"}}) client.XAdd(key, [][]string{{"field2", "value2"}}) response, err := client.XRange(key, options.NewInfiniteStreamBoundary(options.NegativeInfinity), options.NewInfiniteStreamBoundary(options.PositiveInfinity)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(len(response))
Output: 2
func (GlideClient) XRangeWithOptions ¶
func (client GlideClient) XRangeWithOptions( key string, start options.StreamBoundary, end options.StreamBoundary, opts options.XRangeOptions, ) ([]XRangeResponse, error)
Returns stream entries matching a given range of IDs.
See valkey.io for details.
Parameters:
key - The key of the stream. start - The start position. Use `options.NewStreamBoundary()` to specify a stream entry ID and its inclusive/exclusive status. Use `options.NewInfiniteStreamBoundary()` to specify an infinite stream boundary. end - The end position. Use `options.NewStreamBoundary()` to specify a stream entry ID and its inclusive/exclusive status. Use `options.NewInfiniteStreamBoundary()` to specify an infinite stream boundary. opts - Stream range options.
Return value:
An `array` of stream entry data, where entry data is an array of pairings with format `[[field, entry], [field, entry], ...]`. Returns `nil` if `count` is non-positive.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" streamId1, _ := client.XAdd(key, [][]string{{"field1", "value1"}}) streamId2, _ := client.XAdd(key, [][]string{{"field2", "value2"}}) response, err := client.XRangeWithOptions(key, options.NewStreamBoundary(streamId1.Value(), true), options.NewStreamBoundary(streamId2.Value(), true), *options.NewXRangeOptions().SetCount(1)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(len(response))
Output: 1
func (GlideClient) XRead ¶
func (client GlideClient) XRead(keysAndIds map[string]string) (map[string]map[string][][]string, error)
Reads entries from the given streams.
Note:
When in cluster mode, all keys in `keysAndIds` must map to the same hash slot.
See valkey.io for details.
Parameters:
keysAndIds - A map of keys and entry IDs to read from.
Return value:
A `map[string]map[string][][]string` of stream keys to a map of stream entry IDs mapped to an array entries or `nil` if a key does not exist or does not contain requiested entries.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" streamId := "12345-1" client.XAddWithOptions( key, [][]string{{"field1", "value1"}, {"field2", "value2"}}, *options.NewXAddOptions().SetId(streamId), ) response, err := client.XRead(map[string]string{key: "0-0"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: map[12345:map[12345-1:[[field1 value1] [field2 value2]]]]
func (GlideClient) XReadGroup ¶
func (client GlideClient) XReadGroup( group string, consumer string, keysAndIds map[string]string, ) (map[string]map[string][][]string, error)
Reads entries from the given streams owned by a consumer group.
Note:
When in cluster mode, all keys in `keysAndIds` must map to the same hash slot.
See valkey.io for details.
Parameters:
group - The consumer group name. consumer - The group consumer. keysAndIds - A map of keys and entry IDs to read from.
Return value:
A `map[string]map[string][][]string` of stream keys to a map of stream entry IDs mapped to an array entries or `nil` if a key does not exist or does not contain requested entries.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" streamId := "12345-1" group := uuid.NewString() consumer := uuid.NewString() client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) response, err := client.XReadGroup(group, consumer, map[string]string{key: "0"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: map[12345:map[]]
func (GlideClient) XReadGroupWithOptions ¶
func (client GlideClient) XReadGroupWithOptions( group string, consumer string, keysAndIds map[string]string, opts options.XReadGroupOptions, ) (map[string]map[string][][]string, error)
Reads entries from the given streams owned by a consumer group.
Note:
When in cluster mode, all keys in `keysAndIds` must map to the same hash slot.
See valkey.io for details.
Parameters:
group - The consumer group name. consumer - The group consumer. keysAndIds - A map of keys and entry IDs to read from. opts - Options detailing how to read the stream.
Return value:
A `map[string]map[string][][]string` of stream keys to a map of stream entry IDs mapped to an array entries or `nil` if a key does not exist or does not contain requiested entries.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" streamId := "12345-1" group := uuid.NewString() consumer := uuid.NewString() client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) options := options.NewXReadGroupOptions().SetNoAck() response, err := client.XReadGroupWithOptions(group, consumer, map[string]string{key: ">"}, *options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: map[12345:map[12345-1:[[entry1_field1 entry1_value1] [entry1_field2 entry1_value2]]]]
func (GlideClient) XReadWithOptions ¶
func (client GlideClient) XReadWithOptions( keysAndIds map[string]string, opts options.XReadOptions, ) (map[string]map[string][][]string, error)
Reads entries from the given streams.
Note:
When in cluster mode, all keys in `keysAndIds` must map to the same hash slot.
See valkey.io for details.
Parameters:
keysAndIds - A map of keys and entry IDs to read from. opts - Options detailing how to read the stream.
Return value:
A `map[string]map[string][][]string` of stream keys to a map of stream entry IDs mapped to an array entries or `nil` if a key does not exist or does not contain requiested entries.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" streambase := 1 genStreamId := func(key string, base int, offset int) string { return fmt.Sprintf("%s-%d", key, base+offset) } // helper function to generate stream ids client.XAddWithOptions( key, [][]string{{"field1", "value1"}, {"field2", "value2"}}, *options.NewXAddOptions().SetId(genStreamId(key, streambase, 0)), ) client.XAddWithOptions( key, [][]string{{"field3", "value3"}, {"field4", "value4"}}, *options.NewXAddOptions().SetId(genStreamId(key, streambase, 1)), ) response, err := client.XReadWithOptions( map[string]string{key: genStreamId(key, streambase, 0)}, *options.NewXReadOptions().SetCount(1), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: map[12345:map[12345-2:[[field3 value3] [field4 value4]]]]
func (GlideClient) XRevRange ¶
func (client GlideClient) XRevRange( key string, start options.StreamBoundary, end options.StreamBoundary, ) ([]XRangeResponse, error)
Returns stream entries matching a given range of IDs in reverse order. Equivalent to `XRange` but returns entries in reverse order.
See valkey.io for details.
Parameters:
key - The key of the stream. start - The start position. Use `options.NewStreamBoundary()` to specify a stream entry ID and its inclusive/exclusive status. Use `options.NewInfiniteStreamBoundary()` to specify an infinite stream boundary. end - The end position. Use `options.NewStreamBoundary()` to specify a stream entry ID and its inclusive/exclusive status. Use `options.NewInfiniteStreamBoundary()` to specify an infinite stream boundary.
Return value:
An `array` of stream entry data, where entry data is an array of pairings with format `[[field, entry], [field, entry], ...]`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" streamId1 := "12345-1" streamId2 := "12345-2" client.XAddWithOptions(key, [][]string{{"field1", "value1"}}, *options.NewXAddOptions().SetId(streamId1)) client.XAddWithOptions(key, [][]string{{"field2", "value2"}}, *options.NewXAddOptions().SetId(streamId2)) response, err := client.XRevRange(key, options.NewStreamBoundary(streamId2, true), options.NewStreamBoundary(streamId1, true)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: [{12345-2 [[field2 value2]]} {12345-1 [[field1 value1]]}]
func (GlideClient) XRevRangeWithOptions ¶
func (client GlideClient) XRevRangeWithOptions( key string, start options.StreamBoundary, end options.StreamBoundary, opts options.XRangeOptions, ) ([]XRangeResponse, error)
Returns stream entries matching a given range of IDs in reverse order. Equivalent to `XRange` but returns entries in reverse order.
See valkey.io for details.
Parameters:
key - The key of the stream. start - The start position. Use `options.NewStreamBoundary()` to specify a stream entry ID and its inclusive/exclusive status. Use `options.NewInfiniteStreamBoundary()` to specify an infinite stream boundary. end - The end position. Use `options.NewStreamBoundary()` to specify a stream entry ID and its inclusive/exclusive status. Use `options.NewInfiniteStreamBoundary()` to specify an infinite stream boundary. opts - Stream range options.
Return value:
An `array` of stream entry data, where entry data is an array of pairings with format `[[field, entry], [field, entry], ...]`. Returns `nil` if `count` is non-positive.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function key := "12345" streamId1 := "12345-1" streamId2 := "12345-2" client.XAddWithOptions(key, [][]string{{"field1", "value1"}}, *options.NewXAddOptions().SetId(streamId1)) client.XAddWithOptions(key, [][]string{{"field2", "value2"}}, *options.NewXAddOptions().SetId(streamId2)) response, err := client.XRevRangeWithOptions(key, options.NewStreamBoundary(streamId2, true), options.NewStreamBoundary(streamId1, true), *options.NewXRangeOptions().SetCount(2)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: [{12345-2 [[field2 value2]]} {12345-1 [[field1 value1]]}]
func (GlideClient) XTrim ¶
func (client GlideClient) XTrim(key string, options options.XTrimOptions) (int64, error)
Trims the stream by evicting older entries.
See valkey.io for details.
Parameters:
key - The key of the stream. options - Stream trim options
Return value:
The number of entries deleted from the stream.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.XAdd("mystream", [][]string{{"field1", "foo4"}, {"field2", "bar4"}}) client.XAdd("mystream", [][]string{{"field3", "foo4"}, {"field4", "bar4"}}) count, err := client.XTrim("mystream", *options.NewXTrimOptionsWithMaxLen(0).SetExactTrimming()) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(count)
Output: 2
func (GlideClient) ZAdd ¶
Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
See valkey.io for details.
Parameters:
key - The key of the set. membersScoreMap - A map of members to their scores.
Return value:
The number of members added to the set.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 3
func (GlideClient) ZAddIncr ¶
func (client GlideClient) ZAddIncr( key string, member string, increment float64, ) (Result[float64], error)
Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
See valkey.io for details.
Parameters:
key - The key of the set. member - The member to add to. increment - The increment to add to the member's score.
Return value:
Result[float64] - The new score of the member.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAddIncr("key1", "one", 1.0) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: {1 false}
func (GlideClient) ZAddIncrWithOptions ¶
func (client GlideClient) ZAddIncrWithOptions( key string, member string, increment float64, opts options.ZAddOptions, ) (Result[float64], error)
Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
See valkey.io for details.
Parameters:
key - The key of the set. member - The member to add to. increment - The increment to add to the member's score. opts - The options for the command. See [ZAddOptions] for details.
Return value:
The new score of the member. If there was a conflict with the options, the operation aborts and `nil` is returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function opts, err := options.NewZAddOptions().SetChanged(true) // should return an error result, err := client.ZAddIncrWithOptions("key1", "one", 1.0, *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: Glide example failed with an error: incr cannot be set when changed is true {0 true}
func (GlideClient) ZAddWithOptions ¶
func (client GlideClient) ZAddWithOptions( key string, membersScoreMap map[string]float64, opts options.ZAddOptions, ) (int64, error)
Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
See valkey.io for details.
Parameters:
key - The key of the set. membersScoreMap - A map of members to their scores. opts - The options for the command. See [ZAddOptions] for details.
Return value:
The number of members added to the set. If `CHANGED` is set, the number of members that were updated.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function opts, err := options.NewZAddOptions().SetChanged(true) result, err := client.ZAddWithOptions( "key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}, *opts, ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 3
func (GlideClient) ZCard ¶
Returns the cardinality (number of elements) of the sorted set stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the set.
Return value:
The number of elements in the sorted set. If `key` does not exist, it is treated as an empty sorted set, and this command returns `0`. If `key` holds a value that is not a sorted set, an error is returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) result1, err := client.ZCard("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 3
func (GlideClient) ZCount ¶
func (client GlideClient) ZCount(key string, rangeOptions options.ZCountRange) (int64, error)
Returns the number of members in the sorted set stored at `key` with scores between `min` and `max` score.
See valkey.io for details.
Parameters:
key - The key of the set. rangeOptions - Contains `min` and `max` score. `min` contains the minimum score to count from. `max` contains the maximum score to count up to. Can be positive/negative infinity, or specific score and inclusivity.
Return value:
The number of members in the specified score range.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function zCountRange := options.NewZCountRange( options.NewInclusiveScoreBoundary(2.0), options.NewInfiniteScoreBoundary(options.PositiveInfinity), ) result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0, "four": 4.0}) result1, err := client.ZCount("key1", *zCountRange) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 3
func (GlideClient) ZDiff ¶
Returns the difference between the first sorted set and all the successive sorted sets. To get the elements with their scores, see `ZDiffWithScores`
Note:
When in cluster mode, all `keys` must map to the same hash slot.
Available for Valkey 6.2 and above.
See valkey.io for details.
Parameters:
keys - The keys of the sorted sets.
Return value:
An array of elements representing the difference between the sorted sets. If the first `key` does not exist, it is treated as an empty sorted set, and the command returns an empty array.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.5, "c": 3.0, "d": 4.0}) client.ZAdd("key2", map[string]float64{"b": 1.0, "c": 2.5, "d": 3.0, "e": 4.0}) result, err := client.ZDiff([]string{"key1", "key2"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: [a]
func (GlideClient) ZDiffStore ¶
Calculates the difference between the first sorted set and all the successive sorted sets at `keys` and stores the difference as a sorted set to `destination`, overwriting it if it already exists. Non-existent keys are treated as empty sets.
Note:
When in cluster mode, `destination` and all `keys` must map to the same hash slot.
Available for Valkey 6.2 and above.
See valkey.io for details.
Parameters:
destination - The key for the resulting sorted set. keys - The keys of the sorted sets to compare.
Return value:
The number of members in the resulting sorted set stored at `destination`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.5, "c": 3.0, "d": 4.0}) client.ZAdd("key2", map[string]float64{"b": 1.0, "c": 2.5, "d": 3.0, "e": 4.0}) result, err := client.ZDiffStore("dest", []string{"key1", "key2"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 1
func (GlideClient) ZDiffWithScores ¶
Returns the difference between the first sorted set and all the successive sorted sets. When in cluster mode, all `keys` must map to the same hash slot. Available for Valkey 6.2 and above.
See valkey.io for details.
Parameters:
keys - The keys of the sorted sets.
Return value:
A `Map` of elements and their scores representing the difference between the sorted sets. If the first `key` does not exist, it is treated as an empty sorted set, and the command returns an empty `Map`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.5, "c": 3.0, "d": 4.0}) client.ZAdd("key2", map[string]float64{"b": 1.0, "c": 2.5, "d": 3.0, "e": 4.0}) result, err := client.ZDiffWithScores([]string{"key1", "key2"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: map[a:1]
func (GlideClient) 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. If key does not exist, a new sorted set with the specified member as its sole member is created.
See valkey.io for details.
Parameters:
key - The key of the sorted set. increment - The score increment. member - A member of the sorted set.
Return value:
The new score of member.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) result1, err := client.ZIncrBy("key1", 3.0, "two") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 5
func (GlideClient) ZInter ¶
Returns the intersection of members from sorted sets specified by the given `keys`. To get the elements with their scores, see [ZInterWithScores].
Note:
When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
keys - The keys of the sorted sets, see - [options.KeyArray].
Return value:
The resulting sorted set from the intersection.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.5, "c": 3.0, "d": 4.0}) client.ZAdd("key2", map[string]float64{"b": 1.0, "c": 2.5, "d": 3.0, "e": 4.0}) result, err := client.ZInter(options.KeyArray{ Keys: []string{"key1", "key2"}, }) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: [b c d]
func (GlideClient) ZInterStore ¶
func (client GlideClient) ZInterStore(destination string, keysOrWeightedKeys options.KeysOrWeightedKeys) (int64, error)
Computes the intersection of sorted sets given by the specified `keysOrWeightedKeys` and stores the result in `destination`. If `destination` already exists, it is overwritten. Otherwise, a new sorted set will be created.
Note:
When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
destination - The destination key for the result. keysOrWeightedKeys - The keys or weighted keys of the sorted sets, see - [options.KeysOrWeightedKeys]. - Use `options.NewKeyArray()` for keys only. - Use `options.NewWeightedKeys()` for weighted keys with score multipliers.
Return value:
The number of elements in the resulting sorted set stored at <code>destination</code>.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.5, "c": 3.0, "d": 4.0}) client.ZAdd("key2", map[string]float64{"b": 1.0, "c": 2.5, "d": 3.0, "e": 4.0}) result, err := client.ZInterStore("dest", options.KeyArray{ Keys: []string{"key1", "key2"}, }) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 3
func (GlideClient) ZInterStoreWithOptions ¶
func (client GlideClient) ZInterStoreWithOptions( destination string, keysOrWeightedKeys options.KeysOrWeightedKeys, zInterOptions options.ZInterOptions, ) (int64, error)
Computes the intersection of sorted sets given by the specified `keysOrWeightedKeys` and stores the result in `destination`. If `destination` already exists, it is overwritten. Otherwise, a new sorted set will be created.
Note:
When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
destination - The destination key for the result. keysOrWeightedKeys - The keys or weighted keys of the sorted sets, see - [options.KeysOrWeightedKeys]. - Use `options.NewKeyArray()` for keys only. - Use `options.NewWeightedKeys()` for weighted keys with score multipliers. options - The options for the ZInterStore command, see - [options.ZInterOptions]. Optional `aggregate` option specifies the aggregation strategy to apply when combining the scores of elements.
Return value:
The number of elements in the resulting sorted set stored at <code>destination</code>.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.5, "c": 3.0, "d": 4.0}) client.ZAdd("key2", map[string]float64{"b": 1.0, "c": 2.5, "d": 3.0, "e": 4.0}) result, err := client.ZInterStoreWithOptions( "dest", options.KeyArray{ Keys: []string{"key1", "key2"}, }, *options.NewZInterOptions().SetAggregate(options.AggregateSum), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 3
func (GlideClient) ZInterWithScores ¶
func (client GlideClient) ZInterWithScores( keysOrWeightedKeys options.KeysOrWeightedKeys, zInterOptions options.ZInterOptions, ) (map[string]float64, error)
Returns the intersection of members and their scores from sorted sets specified by the given `keysOrWeightedKeys`.
Note:
When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
keysOrWeightedKeys - The keys or weighted keys of the sorted sets, see - [options.KeysOrWeightedKeys]. - Use `options.NewKeyArray()` for keys only. - Use `options.NewWeightedKeys()` for weighted keys with score multipliers. options - The options for the ZInter command, see - [options.ZInterOptions]. Optional `aggregate` option specifies the aggregation strategy to apply when combining the scores of elements.
Return value:
A map of members to their scores.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.5, "c": 3.0, "d": 4.0}) client.ZAdd("key2", map[string]float64{"b": 1.0, "c": 2.5, "d": 3.0, "e": 4.0}) result, err := client.ZInterWithScores( options.KeyArray{ Keys: []string{"key1", "key2"}, }, *options.NewZInterOptions().SetAggregate(options.AggregateSum), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: map[b:3.5 c:5.5 d:7]
func (GlideClient) ZMScore ¶
Returns the scores associated with the specified `members` in the sorted set stored at `key`.
Since:
Valkey 6.2.0 and above.
Parameters:
key - The key of the sorted set. members - A list of members in the sorted set.
Return value:
An array of scores corresponding to `members`. If a member does not exist in the sorted set, the corresponding value in the list will be `nil`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.5, "c": 3.0, "d": 4.0}) result, err := client.ZMScore("key1", []string{"c", "b", "e"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } // If the key does not exist, an empty string is returned fmt.Println(result)
Output: [{3 false} {2.5 false} {0 true}]
func (GlideClient) ZPopMax ¶
Removes and returns the member with the highest score from the sorted set stored at the specified `key`.
see valkey.io for details.
Parameters:
key - The key of the sorted set.
Return value:
A map containing the removed member and its corresponding score. If `key` doesn't exist, it will be treated as an empty sorted set and the command returns an empty map.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) result1, err := client.ZPopMax("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 map[three:3]
func (GlideClient) ZPopMaxWithOptions ¶
func (client GlideClient) ZPopMaxWithOptions(key string, options options.ZPopOptions) (map[string]float64, error)
Removes and returns up to `count` members with the highest scores from the sorted set stored at the specified `key`.
see valkey.io for details.
Parameters:
key - The key of the sorted set. count - The number of members to remove.
Return value:
A map containing the removed members and their corresponding scores. If `key` doesn't exist, it will be treated as an empty sorted set and the command returns an empty map.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) opts := options.NewZPopOptions().SetCount(2) result1, err := client.ZPopMaxWithOptions("key1", *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 map[three:3 two:2]
func (GlideClient) ZPopMin ¶
Removes and returns the member with the lowest score from the sorted set stored at the specified `key`.
see valkey.io for details.
Parameters:
key - The key of the sorted set.
Return value:
A map containing the removed member and its corresponding score. If `key` doesn't exist, it will be treated as an empty sorted set and the command returns an empty map.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) result1, err := client.ZPopMin("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 map[one:1]
func (GlideClient) ZPopMinWithOptions ¶
func (client GlideClient) ZPopMinWithOptions(key string, options options.ZPopOptions) (map[string]float64, error)
Removes and returns up to `count` members with the lowest scores from the sorted set stored at the specified `key`.
see valkey.io for details.
Parameters:
key - The key of the sorted set. count - The number of members to remove.
Return value:
A map containing the removed members and their corresponding scores. If `key` doesn't exist, it will be treated as an empty sorted set and the command returns an empty map.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) opts := options.NewZPopOptions().SetCount(2) result1, err := client.ZPopMinWithOptions("key1", *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 map[one:1 two:2]
func (GlideClient) ZRandMember ¶
Returns a random member from the sorted set stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the sorted set.
Return value:
A string representing a random member from the sorted set. If the sorted set does not exist or is empty, the response will be `nil`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) result, err := client.ZRandMember("key2") if err != nil { fmt.Println("Glide example failed with an error: ", err) } // If the key does not exist, an empty string is returned fmt.Println(result.Value() == "")
Output: true
func (GlideClient) ZRandMemberWithCount ¶
Returns a random member from the sorted set stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the sorted set. count - The number of field names to return. If `count` is positive, returns unique elements. If negative, allows for duplicates.
Return value:
An array of members from the sorted set. If the sorted set does not exist or is empty, the response will be an empty array.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) result, err := client.ZRandMemberWithCount("key1", 4) if err != nil { fmt.Println("Glide example failed with an error: ", err) } // If the key does not exist, an empty string is returned fmt.Println(result)
Output: [d c b a]
func (GlideClient) ZRandMemberWithCountWithScores ¶
func (client GlideClient) ZRandMemberWithCountWithScores(key string, count int64) ([]MemberAndScore, error)
Returns a random member from the sorted set stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the sorted set. count - The number of field names to return. If `count` is positive, returns unique elements. If negative, allows for duplicates.
Return value:
An array of `MemberAndScore` objects, which store member names and their respective scores. If the sorted set does not exist or is empty, the response will be an empty array.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) result, err := client.ZRandMemberWithCountWithScores("key1", 4) if err != nil { fmt.Println("Glide example failed with an error: ", err) } // If the key does not exist, an empty string is returned fmt.Println(result)
Output: [{d 4} {c 3} {b 2} {a 1}]
func (GlideClient) ZRange ¶
func (client GlideClient) ZRange(key string, rangeQuery options.ZRangeQuery) ([]string, error)
Returns 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.
To get the elements with their scores, see [ZRangeWithScores].
See valkey.io for more details.
Parameters:
key - The key of the sorted set. rangeQuery - The range query object representing the type of range query to perform. - For range queries by index (rank), use [RangeByIndex]. - For range queries by lexicographical order, use [RangeByLex]. - For range queries by score, use [RangeByScore].
Return value:
An array of elements within the specified range. If `key` does not exist, it is treated as an empty sorted set, and the command returns an empty array.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) result1, err := client.ZRange("key1", options.NewRangeByIndexQuery(0, -1)) // Ascending order // Retrieve members within a score range in descending order query := options.NewRangeByScoreQuery( options.NewScoreBoundary(3, false), options.NewInfiniteScoreBoundary(options.NegativeInfinity)).SetReverse() result2, err := client.ZRange("key1", query) // `result` contains members which have scores within the range of negative infinity to 3, in descending order if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 3 [one two three] [two one]
func (GlideClient) ZRangeWithScores ¶
func (client GlideClient) ZRangeWithScores( key string, rangeQuery options.ZRangeQueryWithScores, ) ([]MemberAndScore, error)
Returns the specified range of elements with their scores 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.
See valkey.io for more details.
Parameters:
key - The key of the sorted set. rangeQuery - The range query object representing the type of range query to perform. - For range queries by index (rank), use [RangeByIndex]. - For range queries by score, use [RangeByScore].
Return value:
An array of elements and their scores within the specified range. If `key` does not exist, it is treated as an empty sorted set, and the command returns an empty array.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) result1, err := client.ZRangeWithScores("key1", options.NewRangeByIndexQuery(0, -1)) query := options.NewRangeByScoreQuery( options.NewScoreBoundary(3, false), options.NewInfiniteScoreBoundary(options.NegativeInfinity)).SetReverse() result2, err := client.ZRangeWithScores("key1", query) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 3 [{one 1} {two 2} {three 3}] [{two 2} {one 1}]
func (GlideClient) ZRank ¶
Returns the rank of `member` in the sorted set stored at `key`, with scores ordered from low to high, starting from `0`. To get the rank of `member` with its score, see [ZRankWithScore].
See valkey.io for details.
Parameters:
key - The key of the sorted set. member - The member to get the rank of.
Return value:
The rank of `member` in the sorted set. If `key` doesn't exist, or if `member` is not present in the set, `nil` will be returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) result1, err := client.ZRank("key1", "two") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 {1 false}
func (GlideClient) ZRankWithScore ¶
func (client GlideClient) ZRankWithScore(key string, member string) (Result[int64], Result[float64], error)
Returns the rank of `member` in the sorted set stored at `key` with its score, where scores are ordered from the lowest to highest, starting from `0`.
See valkey.io for details.
Parameters:
key - The key of the sorted set. member - The member to get the rank of.
Return value:
A tuple containing the rank of `member` and its score. If `key` doesn't exist, or if `member` is not present in the set, `nil` will be returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) resRank, resScore, err := client.ZRankWithScore("key1", "two") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(resRank) fmt.Println(resScore)
Output: 3 {1 false} {2 false}
func (GlideClient) ZRem ¶
Removes the specified members from the sorted set stored at `key`. Specified members that are not a member of this set are ignored.
See valkey.io for details.
Parameters:
key - The key of the sorted set. members - The members to remove.
Return value:
The number of members that were removed from the sorted set, not including non-existing members. If `key` does not exist, it is treated as an empty sorted set, and this command returns `0`.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) result1, err := client.ZRem("key1", []string{"one", "two", "nonMember"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 2
func (GlideClient) ZRemRangeByLex ¶
func (client GlideClient) ZRemRangeByLex(key string, rangeQuery options.RangeByLex) (int64, error)
Removes all elements in the sorted set stored at `key` with a lexicographical order between `rangeQuery.Start` and `rangeQuery.End`.
See valkey.io for details.
Parameters:
key - The key of the sorted set. rangeQuery - The range query object representing the minimum and maximum bound of the lexicographical range.
Return value:
The number of members removed from the sorted set. If `key` does not exist, it is treated as an empty sorted set, and the command returns `0`. If `rangeQuery.Start` is greater than `rangeQuery.End`, `0` is returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) result1, err := client.ZRemRangeByLex( "key1", *options.NewRangeByLexQuery(options.NewLexBoundary("a", false), options.NewLexBoundary("c", true)), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 2
func (GlideClient) ZRemRangeByRank ¶
Removes all elements in the sorted set stored at `key` with a rank between `start` and `stop`.
See valkey.io for details.
Parameters:
key - The key of the sorted set. start - The start rank. stop - The stop rank.
Return value:
The number of members removed from the sorted set. If `key` does not exist, it is treated as an empty sorted set, and the command returns `0`. If `start` is greater than `stop`, `0` is returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) result1, err := client.ZRemRangeByRank("key1", 1, 3) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 3
func (GlideClient) ZRemRangeByScore ¶
func (client GlideClient) ZRemRangeByScore(key string, rangeQuery options.RangeByScore) (int64, error)
Removes all elements in the sorted set stored at `key` with a score between `rangeQuery.Start` and `rangeQuery.End`.
See valkey.io for details.
Parameters:
key - The key of the sorted set. rangeQuery - The range query object representing the minimum and maximum bound of the score range. can be an implementation of [options.RangeByScore].
Return value:
The number of members removed from the sorted set. If `key` does not exist, it is treated as an empty sorted set, and the command returns `0`. If `rangeQuery.Start` is greater than `rangeQuery.End`, `0` is returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) result1, err := client.ZRemRangeByScore("key1", *options.NewRangeByScoreQuery( options.NewInfiniteScoreBoundary(options.NegativeInfinity), options.NewInfiniteScoreBoundary(options.PositiveInfinity), )) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 4
func (GlideClient) ZRevRank ¶
Returns the rank of `member` in the sorted set stored at `key`, where scores are ordered from the highest to lowest, starting from `0`. To get the rank of `member` with its score, see [ZRevRankWithScore].
See valkey.io for details.
Parameters:
key - The key of the sorted set. member - The member to get the rank of.
Return value:
The rank of `member` in the sorted set, where ranks are ordered from high to low based on scores. If `key` doesn't exist, or if `member` is not present in the set, `nil` will be returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0, "four": 4.0}) result1, err := client.ZRevRank("key1", "two") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 {2 false}
func (GlideClient) ZRevRankWithScore ¶
func (client GlideClient) ZRevRankWithScore(key string, member string) (Result[int64], Result[float64], error)
Returns the rank of `member` in the sorted set stored at `key`, where scores are ordered from the highest to lowest, starting from `0`. To get the rank of `member` with its score, see [ZRevRankWithScore].
See valkey.io for details.
Parameters:
key - The key of the sorted set. member - The member to get the rank of.
Return value:
A tuple containing the rank of `member` and its score. If `key` doesn't exist, or if `member` is not present in the set, `nil` will be returned.s
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0, "four": 4.0}) resRank, resScore, err := client.ZRevRankWithScore("key1", "two") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(resRank) fmt.Println(resScore)
Output: 4 {2 false} {2 false}
func (GlideClient) ZScan ¶
Iterates incrementally over a sorted set.
See valkey.io for details.
Parameters:
key - The key of the sorted set. cursor - The cursor that points to the next iteration of results. A value of `"0"` indicates the start of the search. For Valkey 8.0 and above, negative cursors are treated like the initial cursor("0").
Return value:
The first return value is the `cursor` for the next iteration of results. `"0"` will be the `cursor` returned on the last iteration of the sorted set. The second return value is always an array of the subset of the sorted set held in `key`. The array is a flattened series of `string` pairs, where the value is at even indices and the score is at odd indices.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0, "four": 4.0}) resCursor, resCol, err := client.ZScan("key1", "0") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(resCursor) fmt.Println(resCol)
Output: 4 0 [one 1 two 2 three 3 four 4]
func (GlideClient) ZScanWithOptions ¶
func (client GlideClient) ZScanWithOptions( key string, cursor string, options options.ZScanOptions, ) (string, []string, error)
Iterates incrementally over a sorted set.
See valkey.io for details.
Parameters:
key - The key of the sorted set. cursor - The cursor that points to the next iteration of results. options - The options for the command. See [options.ZScanOptions] for details.
Return value:
The first return value is the `cursor` for the next iteration of results. `"0"` will be the `cursor` returned on the last iteration of the sorted set. The second return value is always an array of the subset of the sorted set held in `key`. The array is a flattened series of `string` pairs, where the value is at even indices and the score is at odd indices. If [ZScanOptions.noScores] is to `true`, the second return value will only contain the members without scores.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0, "four": 4.0}) resCursor, resCol, err := client.ZScanWithOptions("key1", "0", *options.NewZScanOptions().SetMatch("*")) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(resCursor) fmt.Println(resCol)
Output: 4 0 [one 1 two 2 three 3 four 4]
func (GlideClient) ZScore ¶
Returns the score of `member` in the sorted set stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the sorted set. member - The member whose score is to be retrieved.
Return value:
The score of the member. If `member` does not exist in the sorted set, `nil` is returned. If `key` does not exist, `nil` is returned.
Example ¶
var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0, "four": 4.0}) result1, err := client.ZScore("key1", "three") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 {3 false}
type GlideClientCommands ¶
type GlideClientCommands interface { BaseClient GenericCommands ServerManagementCommands BitmapCommands ConnectionManagementCommands }
GlideClientCommands is a client used for connection in Standalone mode.
func NewGlideClient ¶
func NewGlideClient(config *GlideClientConfiguration) (GlideClientCommands, error)
NewGlideClient creates a GlideClientCommands in standalone mode using the given GlideClientConfiguration.
type GlideClientConfiguration ¶
type GlideClientConfiguration struct {
// contains filtered or unexported fields
}
GlideClientConfiguration represents the configuration settings for a Standalone client.
func NewGlideClientConfiguration ¶
func NewGlideClientConfiguration() *GlideClientConfiguration
NewGlideClientConfiguration returns a GlideClientConfiguration with default configuration settings. For further configuration, use the GlideClientConfiguration With* methods.
func (*GlideClientConfiguration) WithAddress ¶
func (config *GlideClientConfiguration) WithAddress(address *NodeAddress) *GlideClientConfiguration
WithAddress adds an address for a known node in the cluster to this configuration's list of addresses. WithAddress can be called multiple times to add multiple addresses to the list. If the server is in cluster mode the list can be partial, as the client will attempt to map out the cluster and find all nodes. If the server is in standalone mode, only nodes whose addresses were provided will be used by the client.
For example:
config := NewGlideClientConfiguration(). WithAddress(&NodeAddress{ Host: "sample-address-0001.use1.cache.amazonaws.com", Port: api.DefaultPost}). WithAddress(&NodeAddress{ Host: "sample-address-0002.use1.cache.amazonaws.com", Port: api.DefaultPost})
func (*GlideClientConfiguration) WithClientName ¶
func (config *GlideClientConfiguration) WithClientName(clientName string) *GlideClientConfiguration
WithClientName sets the client name to be used for the client. Will be used with CLIENT SETNAME command during connection establishment.
func (*GlideClientConfiguration) WithCredentials ¶
func (config *GlideClientConfiguration) WithCredentials(credentials *ServerCredentials) *GlideClientConfiguration
WithCredentials sets the credentials for the authentication process. If none are set, the client will not authenticate itself with the server.
func (*GlideClientConfiguration) WithDatabaseId ¶
func (config *GlideClientConfiguration) WithDatabaseId(id int) *GlideClientConfiguration
WithDatabaseId sets the index of the logical database to connect to.
func (*GlideClientConfiguration) WithReadFrom ¶
func (config *GlideClientConfiguration) WithReadFrom(readFrom ReadFrom) *GlideClientConfiguration
WithReadFrom sets the client's ReadFrom strategy. If not set, Primary will be used.
func (*GlideClientConfiguration) WithReconnectStrategy ¶
func (config *GlideClientConfiguration) WithReconnectStrategy(strategy *BackoffStrategy) *GlideClientConfiguration
WithReconnectStrategy sets the BackoffStrategy used to determine how and when to reconnect, in case of connection failures. If not set, a default backoff strategy will be used.
func (*GlideClientConfiguration) WithRequestTimeout ¶
func (config *GlideClientConfiguration) WithRequestTimeout(requestTimeout int) *GlideClientConfiguration
WithRequestTimeout sets the duration in milliseconds that the client should wait for a request to complete. This duration encompasses sending the request, awaiting for a response from the server, and any required reconnections or retries. If the specified timeout is exceeded for a pending request, it will result in a timeout error. If not set, a default value will be used.
func (*GlideClientConfiguration) WithUseTLS ¶
func (config *GlideClientConfiguration) WithUseTLS(useTLS bool) *GlideClientConfiguration
WithUseTLS configures the TLS settings for this configuration. Set to true if communication with the cluster should use Transport Level Security. This setting should match the TLS configuration of the server/cluster, otherwise the connection attempt will fail.
type GlideClusterClient ¶
type GlideClusterClient struct {
// contains filtered or unexported fields
}
GlideClusterClient implements cluster mode operations by extending baseClient functionality.
func (GlideClusterClient) Append ¶
Appends a value to a key. 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.
See valkey.io for details.
Parameters:
key - The key of the string. value - The value to append.
Return value:
The length of the string after appending the value.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Set("my_key", "my_valu") result, err := client.Append("my_key", "e") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) value, _ := client.Get("my_key") fmt.Println(value.Value())
Output: 8 my_value
func (GlideClusterClient) BLMPop ¶
func (client GlideClusterClient) BLMPop( keys []string, listDirection options.ListDirection, timeoutSecs float64, ) (map[string][]string, error)
Blocks the connection until it pops one element from the first non-empty list from the provided keys. BLMPop is the blocking variant of api.LMPop.
Note:
- When in cluster mode, all keys must map to the same hash slot.
- BLMPop is a client blocking command, see Blocking Commands for more details and best practices.
Since:
Valkey 7.0 and above.
See valkey.io for details.
Parameters:
keys - An array of keys to lists. listDirection - The direction based on which elements are popped from - see [options.ListDirection]. timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of 0 will block indefinitely.
Return value:
A map of key name mapped array of popped element. If no member could be popped and the timeout expired, returns nil.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.LPush("my_list", []string{"one", "two", "three"}) result1, err := client.BLMPop([]string{"my_list"}, options.Left, 0.1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 map[my_list:[three]]
func (GlideClusterClient) BLMPopCount ¶
func (client GlideClusterClient) BLMPopCount( keys []string, listDirection options.ListDirection, count int64, timeoutSecs float64, ) (map[string][]string, error)
Blocks the connection until it pops one or more elements from the first non-empty list from the provided keys. BLMPopCount is the blocking variant of api.LMPopCount.
Note:
- When in cluster mode, all keys must map to the same hash slot.
- BLMPopCount is a client blocking command, see Blocking Commands for more details and best practices.
Since:
Valkey 7.0 and above.
See valkey.io for details.
Parameters:
keys - An array of keys to lists. listDirection - The direction based on which elements are popped from - see [options.ListDirection]. count - The maximum number of popped elements. timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of 0 will block
indefinitely.
Return value:
A map of key name mapped array of popped element. If no member could be popped and the timeout expired, returns nil.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.LPush("my_list", []string{"one", "two", "three"}) result1, err := client.BLMPopCount([]string{"my_list"}, options.Left, 2, 0.1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 map[my_list:[three two]]
func (GlideClusterClient) BLMove ¶
func (client GlideClusterClient) BLMove( source string, destination string, whereFrom options.ListDirection, whereTo options.ListDirection, timeoutSecs float64, ) (Result[string], error)
Blocks the connection until it pops atomically and removes the left/right-most element to the list stored at source depending on whereFrom, and pushes the element at the first/last element of the list stored at <destination depending on wherefrom. BLMove is the blocking variant of api.LMove.
Note:
- When in cluster mode, all source and destination must map to the same hash slot.
- BLMove is a client blocking command, see Blocking Commands for more details and best practices.
Since:
Valkey 6.2.0 and above.
See valkey.io for details.
Parameters:
source - The key to the source list. destination - The key to the destination list. wherefrom - The ListDirection the element should be removed from. whereto - The ListDirection the element should be added to. timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of 0 will block indefinitely.
Return value:
A Result[string] containing the popped element or api.CreateNilStringResult() if source does not exist or if the operation timed-out.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.LPush("{list}-1", []string{"two", "one"}) result1, err := client.LPush("{list}-2", []string{"four", "three"}) result2, err := client.BLMove("{list}-1", "{list}-2", options.Left, options.Left, 0.1) result3, err := client.LRange("{list}-1", 0, -1) result4, err := client.LRange("{list}-2", 0, -1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2) fmt.Println(result3) fmt.Println(result4)
Output: 2 2 {one false} [two] [one three four]
func (GlideClusterClient) BLPop ¶
Pops an element from the head of the first list that is non-empty, with the given keys being checked in the order that they are given. Blocks the connection when there are no elements to pop from any of the given lists.
Note:
- When in cluster mode, all keys must map to the same hash slot.
- BLPop is a client blocking command, see Blocking Commands for more details and best practices.
See valkey.io for details.
Parameters:
keys - The keys of the lists to pop from. timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of 0 will block indefinitely.
Return value:
A two-element array containing the key from which the element was popped and the value of the popped element, formatted as [key, value]. If no element could be popped and the timeout expired, returns `nil`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.RPush("{list}-a", []string{"a", "b", "c", "d", "e"}) result1, err := client.RPush("{list}-b", []string{"f", "g", "h", "i", "j"}) result2, err := client.BLPop([]string{"{list}-a", "{list}-b"}, 0.5) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 5 5 [{list}-a a]
func (GlideClusterClient) BRPop ¶
Pops an element from the tail of the first list that is non-empty, with the given keys being checked in the order that they are given. Blocks the connection when there are no elements to pop from any of the given lists.
Note:
- When in cluster mode, all keys must map to the same hash slot.
- BRPop is a client blocking command, see Blocking Commands for more details and best practices.
See valkey.io for details.
Parameters:
keys - The keys of the lists to pop from. timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of 0 will block indefinitely.
Return value:
A two-element array containing the key from which the element was popped and the value of the popped element, formatted as [key, value]. If no element could be popped and the timeoutSecs expired, returns `nil`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Del([]string{"my_list", "{list}-a", "{list}-b"}) result, err := client.RPush("{list}-a", []string{"a", "b", "c", "d", "e"}) result1, err := client.RPush("{list}-b", []string{"f", "g", "h", "i", "j"}) result2, err := client.BRPop([]string{"{list}-a", "{list}-b"}, 0.5) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 5 5 [{list}-a e]
func (GlideClusterClient) BZMPop ¶
func (client GlideClusterClient) BZMPop( keys []string, scoreFilter options.ScoreFilter, timeoutSecs float64, ) (Result[KeyWithArrayOfMembersAndScores], error)
Blocks the connection until it pops and returns a member-score pair from the first non-empty sorted set, with the given keys being checked in the order they are provided. BZMPop is the blocking variant of [baseClient.ZMPop].
Note:
- When in cluster mode, all keys must map to the same hash slot.
- BZMPop is a client blocking command, see Blocking Commands for more details and best practices.
Since:
Valkey 7.0 and above.
See valkey.io for details.
Parameters:
keys - An array of keys to lists. scoreFilter - The element pop criteria - either [options.MIN] or [options.MAX] to pop members with the lowest/highest scores accordingly. timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of `0` will block indefinitely.
Return value:
An object containing the following elements: - The key name of the set from which the element was popped. - An array of member scores of the popped elements. Returns `nil` if no member could be popped and the timeout expired.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) result, err := client.BZMPop([]string{"key1"}, options.MAX, float64(0.5)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } jsonSummary, _ := json.Marshal(result.Value()) fmt.Println(string(jsonSummary))
Output: {"Key":"key1","MembersAndScores":[{"Member":"d","Score":4}]}
func (GlideClusterClient) BZMPopWithOptions ¶
func (client GlideClusterClient) BZMPopWithOptions( keys []string, scoreFilter options.ScoreFilter, timeoutSecs float64, opts options.ZMPopOptions, ) (Result[KeyWithArrayOfMembersAndScores], error)
Blocks the connection until it pops and returns a member-score pair from the first non-empty sorted set, with the given keys being checked in the order they are provided. BZMPop is the blocking variant of [baseClient.ZMPop].
Note:
- When in cluster mode, all keys must map to the same hash slot.
- BZMPop is a client blocking command, see Blocking Commands for more details and best practices.
Since:
Valkey 7.0 and above.
See valkey.io for details.
Parameters:
keys - An array of keys to lists. scoreFilter - The element pop criteria - either [options.MIN] or [options.MAX] to pop members with the lowest/highest scores accordingly. count - The maximum number of popped elements. timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of `0` will block indefinitely. opts - Pop options, see [options.ZMPopOptions].
Return value:
An object containing the following elements: - The key name of the set from which the element was popped. - An array of member scores of the popped elements. Returns `nil` if no member could be popped and the timeout expired.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) result, err := client.BZMPopWithOptions([]string{"key1"}, options.MAX, 0.1, *options.NewZMPopOptions().SetCount(1)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } jsonSummary, _ := json.Marshal(result.Value()) fmt.Println(string(jsonSummary))
Output: {"Key":"key1","MembersAndScores":[{"Member":"d","Score":4}]}
func (GlideClusterClient) BZPopMin ¶
func (client GlideClusterClient) BZPopMin(keys []string, timeoutSecs float64) (Result[KeyWithMemberAndScore], error)
Blocks the connection until it removes and returns a member with the lowest score from the first non-empty sorted set, with the given `keys` being checked in the order they are provided. `BZPOPMIN` is the blocking variant of `ZPOPMIN`.
Note:
- When in cluster mode, all `keys` must map to the same hash slot.
- `BZPOPMIN` is a client blocking command, see [Blocking Commands] for more details and best practices.
See valkey.io for more details.
Parameters:
keys - The keys of the sorted sets. timeout - The number of seconds to wait for a blocking operation to complete. A value of `0` will block indefinitely.
Return value:
A `KeyWithMemberAndScore` struct containing the key where the member was popped out, the member itself, and the member score. If no member could be popped and the `timeout` expired, returns `nil`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function zaddResult1, err := client.ZAdd("{key}1", map[string]float64{"a": 1.0, "b": 1.5}) zaddResult2, err := client.ZAdd("{key}2", map[string]float64{"c": 2.0}) result1, err := client.BZPopMin([]string{"{key}1", "{key}2"}, 0.5) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(zaddResult1) fmt.Println(zaddResult2) fmt.Println(result1)
Output: 2 1 {{{key}1 a 1} false}
func (GlideClusterClient) BitCount ¶
Counts the number of set bits (population counting) in a string stored at key.
Parameters:
key - The key for the string to count the set bits of.
Return value:
The number of set bits in the string. Returns zero if the key is missing as it is treated as an empty string.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.SetBit("my_key", 1, 1) client.SetBit("my_key", 2, 1) result, err := client.BitCount("my_key") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 2
func (GlideClusterClient) BitCountWithOptions ¶
func (client GlideClusterClient) BitCountWithOptions(key string, opts options.BitCountOptions) (int64, error)
Counts the number of set bits (population counting) in a string stored at key. The offsets start and end are zero-based indexes, with `0` being the first element 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, with `-1` being the last element of the list, `-2` being the penultimate, and so on.
Parameters:
key - The key for the string to count the set bits of. options - The offset options - see [options.BitOffsetOptions].
Return value:
The number of set bits in the string interval specified by start, end, and options. Returns zero if the key is missing as it is treated as an empty string.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function options := options.NewBitCountOptions(). SetStart(1). SetEnd(1). SetBitmapIndexType(options.BYTE) result, err := client.BitCountWithOptions("my_key", *options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 0
func (GlideClusterClient) BitField ¶
func (client GlideClusterClient) BitField(key string, subCommands []options.BitFieldSubCommands) ([]Result[int64], error)
Reads or modifies the array of bits representing the string that is held at key based on the specified sub commands.
See valkey.io for details.
Parameters:
key - The key of the string. subCommands - The subCommands to be performed on the binary value of the string at key, which could be any of the following: - [BitFieldGet]. - [BitFieldSet]. - [BitFieldIncrby]. - [BitFieldOverflow]. Use `options.NewBitFieldGet()` to specify a BitField GET command. Use `options.NewBitFieldSet()` to specify a BitField SET command. Use `options.NewBitFieldIncrby()` to specify a BitField INCRYBY command. Use `options.BitFieldOverflow()` to specify a BitField OVERFLOW command.
Return value:
Result from the executed subcommands. - BitFieldGet returns the value in the binary representation of the string. - BitFieldSet returns the previous value before setting the new value in the binary representation. - BitFieldIncrBy returns the updated value after increasing or decreasing the bits. - BitFieldOverflow controls the behavior of subsequent operations and returns a result based on the specified overflow type (WRAP, SAT, FAIL).
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function commands := []options.BitFieldSubCommands{ options.NewBitFieldGet(options.SignedInt, 8, 16), options.NewBitFieldOverflow(options.SAT), options.NewBitFieldSet(options.UnsignedInt, 4, 0, 7), options.NewBitFieldIncrBy(options.SignedInt, 5, 100, 1), } result, err := client.BitField("mykey", commands) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: [{0 false} {0 false} {1 false}]
func (GlideClusterClient) BitFieldRO ¶
func (client GlideClusterClient) BitFieldRO(key string, commands []options.BitFieldROCommands) ([]Result[int64], error)
Reads the array of bits representing the string that is held at key based on the specified sub commands.
See valkey.io for details.
Parameters:
key - The key of the string. subCommands - The read-only subCommands to be performed on the binary value of the string at key, which could be: - [BitFieldGet]. Use `options.NewBitFieldGet()` to specify a BitField GET command.
Return value:
Result from the executed GET subcommands. - BitFieldGet returns the value in the binary representation of the string.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "mykey" bfcommands := []options.BitFieldSubCommands{ options.NewBitFieldSet(options.UnsignedInt, 8, 0, 24), } client.BitField(key, bfcommands) commands := []options.BitFieldROCommands{ options.NewBitFieldGet(options.UnsignedInt, 8, 0), } result, err := client.BitFieldRO(key, commands) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: [{24 false}]
func (GlideClusterClient) Close ¶
func (client GlideClusterClient) Close()
Close terminates the client by closing all associated resources.
func (GlideClusterClient) Copy ¶
Copies the value stored at the source to the destination key if the destination key does not yet exist.
Note:
When in cluster mode, both source and destination must map to the same hash slot.
Parameters:
source - The key to the source value. destination - The key where the value should be copied to.
Return value:
`true` if source was copied, `false` if source was not copied.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("{key}1", "someValue") result1, err := client.Copy("{key}1", "{key}2") result2, err := client.Get("{key}2") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: OK true {someValue false}
func (GlideClusterClient) CopyWithOptions ¶
func (client GlideClusterClient) CopyWithOptions( source string, destination string, options options.CopyOptions, ) (bool, error)
Copies the value stored at the source to the destination key. When replace is true, removes the destination key first if it already exists, otherwise performs no action.
Note:
When in cluster mode, both source and destination must map to the same hash slot.
Parameters:
source - The key to the source value. destination - The key where the value should be copied to. copyOptions - Set copy options with replace and DB destination-db
Return value:
`true` if source was copied, `false` if source was not copied.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Set("{key}1", "someValue") opts := options.NewCopyOptions().SetReplace() client.CopyWithOptions("{key}1", "{key}2", *opts) result, err := client.Get("{key}2") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.Value())
Output: someValue
func (*GlideClusterClient) CustomCommand ¶
func (client *GlideClusterClient) CustomCommand(args []string) (ClusterValue[interface{}], error)
CustomCommand executes a single command, specified by args, without checking inputs. Every part of the command, including the command name and subcommands, should be added as a separate value in args. The returning value depends on the executed command.
The command will be routed automatically based on the passed command's default request policy.
See Valkey GLIDE Wiki for details on the restrictions and limitations of the custom command API.
This function should only be used for single-response commands. Commands that don't return complete response and awaits (such as SUBSCRIBE), or that return potentially more than a single response (such as XREAD), or that change the client's behavior (such as entering pub/sub mode on RESP2 connections) shouldn't be called using this function.
Parameters:
args - Arguments for the custom command including the command name.
Return value:
The returned value for the custom command.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.CustomCommand([]string{"ping"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.SingleValue().(string))
Output: PONG
func (*GlideClusterClient) CustomCommandWithRoute ¶
func (client *GlideClusterClient) CustomCommandWithRoute( args []string, route config.Route, ) (ClusterValue[interface{}], error)
CustomCommandWithRoute executes a single command, specified by args, without checking inputs. Every part of the command, including the command name and subcommands, should be added as a separate value in args. The returning value depends on the executed command.
See Valkey GLIDE Wiki for details on the restrictions and limitations of the custom command API.
Parameters:
args - Arguments for the custom command including the command name. route - Specifies the routing configuration for the command. The client will route the command to the nodes defined by route.
Return value:
The returning value depends on the executed command and route.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function route := config.SimpleNodeRoute(config.RandomRoute) result, _ := client.CustomCommandWithRoute([]string{"ping"}, route) fmt.Println(result.SingleValue().(string))
Output: PONG
func (*GlideClusterClient) DBSizeWithOptions ¶
func (client *GlideClusterClient) DBSizeWithOptions(opts options.RouteOption) (int64, error)
Returns the number of keys in the database.
Parameters:
options - The [RouteOption] type.
Return value:
The number of keys in the database.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function route := config.SimpleNodeRoute(config.RandomRoute) opts := options.RouteOption{ Route: route, } result, err := client.DBSizeWithOptions(opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 0
func (GlideClusterClient) Decr ¶
Decrements the number stored at key by one. If key does not exist, it is set to 0 before performing the operation.
See valkey.io for details.
Parameters:
key - The key to decrement its value.
Return value:
The value of `key` after the decrement.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Set("my_key", "0") result, err := client.Decr("my_key") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: -1
func (GlideClusterClient) DecrBy ¶
Decrements the number stored at code by amount. If key does not exist, it is set to 0 before performing the operation.
See valkey.io for details.
Parameters:
key - The key to decrement its value. amount - The amount to decrement.
Return value:
The value of `key` after the decrement.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Set("my_key", "20") result, err := client.DecrBy("my_key", 5) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 15
func (GlideClusterClient) Del ¶
Del removes the specified keys from the database. A key is ignored if it does not exist.
Note:
In cluster mode, if keys in `keyValueMap` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
keys - One or more keys to delete.
Return value:
Returns the number of keys that were removed.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.Set("key2", "someValue") result2, err := client.Del([]string{"key1", "key2", "key3"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: OK OK 2
func (GlideClusterClient) Dump ¶
Serialize the value stored at key in a Valkey-specific format and return it to the user.
Parameters:
The key to serialize.
Return value:
The serialized value of the data stored at key. If key does not exist, null will be returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.Dump("key1") // Contains serialized value of the data stored at key1 if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1.IsNil())
Output: OK false
func (GlideClusterClient) Echo ¶
Echo the provided message back. The command will be routed a random node.
Parameters:
message - The provided message.
Return value:
The provided message
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Echo("Hello") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: {Hello false}
func (*GlideClusterClient) EchoWithOptions ¶
func (client *GlideClusterClient) EchoWithOptions(echoOptions options.ClusterEchoOptions) (ClusterValue[string], error)
Echo the provided message back. The command will be routed a random node, unless `Route` in `echoOptions` is provided.
Parameters:
echoOptions - The [ClusterEchoOptions] type.
Return value:
A map where each address is the key and its corresponding node response is the information for the default sections.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function opts := options.ClusterEchoOptions{ EchoOptions: &options.EchoOptions{ Message: "Hello World", }, RouteOption: &options.RouteOption{Route: nil}, } result, err := client.EchoWithOptions(opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.singleValue)
Output: Hello World
func (GlideClusterClient) Exists ¶
Exists returns the number of keys that exist in the database
Note:
In cluster mode, if keys in `keyValueMap` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
keys - One or more keys to check if they exist.
Return value:
Returns the number of existing keys.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.Set("key2", "someValue") result2, err := client.Exists([]string{"key1", "key2", "key3"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: OK OK 2
func (GlideClusterClient) Expire ¶
Expire sets a timeout on key. After the timeout has expired, the key will automatically be deleted.
If key already has an existing expire set, the time to live is updated to the new value. If seconds is a non-positive number, the key will be deleted rather than expired. The timeout will only be cleared by commands that delete or overwrite the contents of key.
Parameters:
key - The key to expire. seconds - Time in seconds for the key to expire
Return value:
`true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.ExpireAt("key", time.Now().Unix()+1) result2, err := client.Expire("key", 1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: OK true true
func (GlideClusterClient) ExpireAt ¶
ExpireAt sets a timeout on key. It takes an absolute Unix timestamp (seconds since January 1, 1970) instead of specifying the number of seconds. A timestamp in the past will delete the key immediately. After the timeout has expired, the key will automatically be deleted. If key already has an existing expire set, the time to live is updated to the new value. The timeout will only be cleared by commands that delete or overwrite the contents of key If key already has an existing expire set, the time to live is updated to the new value. If seconds is a non-positive number, the key will be deleted rather than expired. The timeout will only be cleared by commands that delete or overwrite the contents of key
Parameters:
key - The key to expire. unixTimestampInSeconds - Absolute Unix timestamp
Return value:
`true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.ExpireAt("key", time.Now().Unix()+1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK true
func (GlideClusterClient) ExpireAtWithOptions ¶
func (client GlideClusterClient) ExpireAtWithOptions( key string, unixTimestampInSeconds int64, expireCondition options.ExpireCondition, ) (bool, error)
ExpireAt sets a timeout on key. It takes an absolute Unix timestamp (seconds since January 1, 1970) instead of specifying the number of seconds. A timestamp in the past will delete the key immediately. After the timeout has expired, the key will automatically be deleted. If key already has an existing expire set, the time to live is updated to the new value. The timeout will only be cleared by commands that delete or overwrite the contents of key If key already has an existing expire set, the time to live is updated to the new value. If seconds is a non-positive number, the key will be deleted rather than expired. The timeout will only be cleared by commands that delete or overwrite the contents of key
Parameters: key - The key to expire. unixTimestampInSeconds - Absolute Unix timestamp. option - The option to set expiry - see options.ExpireCondition.
Return value:
`true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.ExpireAtWithOptions("key", time.Now().Unix()+1, options.HasNoExpiry) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK true
func (GlideClusterClient) ExpireTime ¶
Expire Time returns the absolute Unix timestamp (since January 1, 1970) at which the given key will expire, in seconds.
Parameters:
key - The key to determine the expiration value of.
Return value:
The expiration Unix timestamp in seconds. `-2` if key does not exist or `-1` is key exists but has no associated expiration.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.ExpireTime("key") _, err = client.ExpireAt("key", time.Now().Unix()*1000) // ExpireTime("key") returns proper unix timestamp in seconds if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK -1
func (GlideClusterClient) ExpireWithOptions ¶
func (client GlideClusterClient) ExpireWithOptions(key string, seconds int64, expireCondition options.ExpireCondition) (bool, error)
Expire sets a timeout on key. After the timeout has expired, the key will automatically be deleted
If key already has an existing expire set, the time to live is updated to the new value. If seconds is a non-positive number, the key will be deleted rather than expired. The timeout will only be cleared by commands that delete or overwrite the contents of key
Parameters: key - The key to expire. seconds - Time in seconds for the key to expire. option - The option to set expiry, see options.ExpireCondition.
Return value:
`true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.ExpireWithOptions("key", 1, options.HasNoExpiry) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK true
func (GlideClusterClient) Get ¶
Get string value associated with the given key, or api.CreateNilStringResult() is returned if no such value exists.
See valkey.io for details.
Parameters:
key - The key to be retrieved from the database.
Return value:
If key exists, returns the value of key as a String. Otherwise, return [api.CreateNilStringResult()].
Example (Keyexists) ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Set("my_key", "my_value") result, err := client.Get("my_key") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.Value())
Output: my_value
Example (Keynotexists) ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Get("my_key") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.IsNil()) // missing key returns nil result
Output: true
func (GlideClusterClient) GetBit ¶
Returns the bit value at offset in the string value stored at key.
offset should be greater than or equal to zero.
Parameters:
key - The key of the string. offset - The index of the bit to return.
Return value:
The bit at offset of the string. Returns zero if the key is empty or if the positive offset exceeds the length of the string.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.SetBit("my_key", 1, 1) client.SetBit("my_key", 1, 1) result, err := client.GetBit("my_key", 1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 1
func (GlideClusterClient) GetDel ¶
GetDel gets the value associated with the given key and deletes the key.
Parameters:
key - The key to get and delete.
Return value:
If key exists, returns the value of the key as a String and deletes the key. If key does not exist, returns a [api.NilResult[string]] (api.CreateNilStringResult()).
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Set("my_key", "my_value") result, err := client.GetDel("my_key") // return value and delete key if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.Value()) value, _ := client.Get("my_key") // key should be missing fmt.Println(value.IsNil())
Output: my_value true
func (GlideClusterClient) GetEx ¶
Get string value associated with the given key, or an empty string is returned [api.CreateNilStringResult()] if no such value exists.
See valkey.io for details.
Parameters:
key - The key to be retrieved from the database.
Return value:
If key exists, returns the value of key as a Result[string]. Otherwise, return [api.CreateNilStringResult()].
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Set("my_key", "my_value") result, err := client.GetEx("my_key") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.Value()) ttl, _ := client.TTL("my_key") fmt.Println(ttl)
Output: my_value -1
func (GlideClusterClient) GetExWithOptions ¶
func (client GlideClusterClient) GetExWithOptions(key string, options options.GetExOptions) (Result[string], error)
Get string value associated with the given key and optionally sets the expiration of the key.
See valkey.io for details.
Parameters:
key - The key to be retrieved from the database. options - The [options.GetExOptions].
Return value:
If key exists, returns the value of key as a Result[string]. Otherwise, return [api.CreateNilStringResult()].
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Set("my_key", "my_value") options := options.NewGetExOptions(). SetExpiry(options.NewExpiry(). SetType(options.Seconds). SetCount(uint64(5))) result, err := client.GetExWithOptions("my_key", *options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.Value()) ttl, _ := client.TTL("my_key") fmt.Println(ttl)
Output: my_value 5
func (GlideClusterClient) GetRange ¶
Returns the substring of the string value stored at key, determined by the byte's 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.
See valkey.io for details.
Parameters:
key - The key of the string. start - The starting offset. end - The ending offset.
Return value:
A substring extracted from the value stored at key. Returns empty string if the offset is out of bounds.
Example (One) ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Set("my_key", "Welcome to Valkey Glide!") result, err := client.GetRange("my_key", 0, 7) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: Welcome
Example (Two) ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Set("my_key", "愛") fmt.Println([]byte("愛")) // "愛" is a single character in UTF-8, but 3 bytes long result, err := client.GetRange("my_key", 0, 1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println([]byte(result))
Output: [230 132 155] [230 132]
func (GlideClusterClient) HDel ¶
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.
See valkey.io for details.
Parameters:
key - The key of the hash. fields - The fields to remove from the hash stored at key.
Return value:
The number of fields that were removed from the hash, not including specified but non-existing fields.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) result1, err := client.HDel("my_hash", []string{"field1", "field2"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 2 2
func (GlideClusterClient) HExists ¶
HExists returns if field is an existing field in the hash stored at key.
See valkey.io for details.
Parameters:
key - The key of the hash. field - The field to check in the hash stored at key.
Return value:
A bool containing true if the hash contains the specified field. false if the hash does not contain the field, or if the key does not exist.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) result1, err := client.HExists("my_hash", "field1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 2 true
func (GlideClusterClient) HGet ¶
HGet returns the value associated with field in the hash stored at key.
See valkey.io for details.
Parameters:
key - The key of the hash. field - The field in the hash stored at key to retrieve from the database.
Return value:
The Result[string] associated with field, or [api.NilResult[string]](api.CreateNilStringResult()) when field is not present in the hash or key does not exist.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) payload, err := client.HGet("my_hash", "field1") payload2, err := client.HGet("my_hash", "nonexistent_field") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(payload) fmt.Println(payload2.IsNil())
Output: 2 {someValue false} true
func (GlideClusterClient) HGetAll ¶
HGetAll returns all fields and values of the hash stored at key.
See valkey.io for details.
Parameters:
key - The key of the hash.
Return value:
A map of all fields and their values as Result[string] in the hash, or an empty map when key does not exist.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) payload, err := client.HGetAll("my_hash") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(payload["field1"]) fmt.Println(payload["field2"]) fmt.Println(payload["notExistentField"]) // prints nothing
Output: 2 someValue someOtherValue
func (GlideClusterClient) HIncrBy ¶
Increments the number stored at `field` in the hash stored at `key` by increment. By using a negative increment value, the value stored at `field` in the hash stored at `key` is decremented. If `field` or `key` does not exist, it is set to 0 before performing the operation.
See valkey.io for details.
Parameters:
key - The key of the hash. field - The field in the hash stored at `key` to increment its value. increment - The amount to increment.
Return value:
The value of `field` in the hash stored at `key` after the increment.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function fields := map[string]string{ "field1": "10", "field2": "14", } result, err := client.HSet("my_hash", fields) result1, err := client.HIncrBy("my_hash", "field1", 1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 2 11
func (GlideClusterClient) HIncrByFloat ¶
func (client GlideClusterClient) HIncrByFloat(key string, field string, increment float64) (float64, error)
Increments the string representing a floating point number stored at `field` in the hash stored at `key` by increment. By using a negative increment value, the value stored at `field` in the hash stored at `key` is decremented. If `field` or `key` does not exist, it is set to `0` before performing the operation.
See valkey.io for details.
Parameters:
key - The key of the hash. field - The field in the hash stored at `key` to increment its value. increment - The amount to increment.
Return value:
The value of `field` in the hash stored at `key` after the increment.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function fields := map[string]string{ "field1": "10", "field2": "14", } result, err := client.HSet("my_hash", fields) result1, err := client.HIncrByFloat("my_hash", "field1", 1.5) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 2 11.5
func (GlideClusterClient) HKeys ¶
HKeys returns all field names in the hash stored at key.
See valkey.io for details.
Parameters:
key - The key of the hash.
Return value:
A slice containing all the field names in the hash, or an empty slice when key does not exist.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function fields := map[string]string{ "field1": "someValue", } client.HSet("my_hash", fields) result, err := client.HKeys("my_hash") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: [field1]
func (GlideClusterClient) HLen ¶
HLen returns the number of fields contained in the hash stored at key.
See valkey.io for details.
Parameters:
key - The key of the hash.
Return value:
The number of fields in the hash, or `0` when key does not exist. If key holds a value that is not a hash, an error is returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) result1, err := client.HLen("my_hash") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 2 2
func (GlideClusterClient) HMGet ¶
HMGet returns the values associated with the specified fields in the hash stored at key.
See valkey.io for details.
Parameters:
key - The key of the hash. fields - The fields in the hash stored at key to retrieve from the database.
Return value:
An array of Result[string]s associated with the given fields, in the same order as they are requested. For every field that does not exist in the hash, a [api.NilResult[string]](api.CreateNilStringResult()) is returned. If key does not exist, returns an empty string array.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) values, err := client.HMGet("my_hash", []string{"field1", "field2"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(values[0]) fmt.Println(values[1])
Output: 2 {someValue false} {someOtherValue false}
func (GlideClusterClient) HRandField ¶
Returns a random field name from the hash value stored at `key`.
Since:
Valkey 6.2.0 and above.
See valkey.io for details.
Parameters:
key - The key of the hash.
Return value:
A random field name from the hash stored at `key`, or `nil` when the key does not exist.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function // For this example we only use 1 field to ensure consistent output fields := map[string]string{ "field1": "someValue", // other fields here... } client.HSet("my_hash", fields) result, err := client.HRandField("my_hash") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: {field1 false}
func (GlideClusterClient) HRandFieldWithCount ¶
Retrieves up to `count` random field names from the hash value stored at `key`.
Since:
Valkey 6.2.0 and above.
See valkey.io for details.
Parameters:
key - The key of the hash. count - The number of field names to return. If `count` is positive, returns unique elements. If negative, allows for duplicates.
Return value:
An array of random field names from the hash stored at `key`, or an empty array when the key does not exist.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } client.HSet("my_hash", fields) result, err := client.HRandFieldWithCount("my_hash", 2) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(len(result) == 2)
Output: true
func (GlideClusterClient) HRandFieldWithCountWithValues ¶
func (client GlideClusterClient) HRandFieldWithCountWithValues(key string, count int64) ([][]string, error)
Retrieves up to `count` random field names along with their values from the hash value stored at `key`.
Since:
Valkey 6.2.0 and above.
See valkey.io for details.
Parameters:
key - The key of the hash. count - The number of field names to return. If `count` is positive, returns unique elements. If negative, allows for duplicates.
Return value:
A 2D `array` of `[field, value]` arrays, where `field` is a random field name from the hash and `value` is the associated value of the field name. If the hash does not exist or is empty, the response will be an empty array.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } client.HSet("my_hash", fields) result, err := client.HRandFieldWithCountWithValues("my_hash", 2) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(len(result) == 2)
Output: true
func (GlideClusterClient) HScan ¶
Iterates fields of Hash types and their associated values. This definition of HSCAN command does not include the optional arguments of the command.
See valkey.io for details.
Parameters:
key - The key of the hash. cursor - The cursor that points to the next iteration of results. A value of "0" indicates the start of the search.
Return value:
An array of the cursor and the subset of the hash held by `key`. The first element is always the `cursor` for the next iteration of results. The `cursor` will be `"0"` on the last iteration of the subset. The second element is always an array of the subset of the set held in `key`. The array in the second element is always a flattened series of String pairs, where the key is at even indices and the value is at odd indices.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function // For this example we only use 1 field to ensure a consistent output fields := map[string]string{ "field1": "someValue", // other fields here } result, err := client.HSet("my_hash", fields) resCursor, resCollection, err := client.HScan("my_hash", "0") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(resCursor) fmt.Println(resCollection)
Output: 1 0 [field1 someValue]
func (GlideClusterClient) HScanWithOptions ¶
func (client GlideClusterClient) HScanWithOptions( key string, cursor string, options options.HashScanOptions, ) (string, []string, error)
Iterates fields of Hash types and their associated values. This definition of HSCAN includes optional arguments of the command.
See valkey.io for details.
Parameters:
key - The key of the hash. cursor - The cursor that points to the next iteration of results. A value of "0" indicates the start of the search. options - The [options.HashScanOptions].
Return value:
An array of the cursor and the subset of the hash held by `key`. The first element is always the `cursor` for the next iteration of results. The `cursor` will be `"0"` on the last iteration of the subset. The second element is always an array of the subset of the set held in `key`. The array in the second element is always a flattened series of String pairs, where the key is at even indices and the value is at odd indices.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function fields := map[string]string{ "a": "1", "b": "2", } result, err := client.HSet("my_hash", fields) opts := options.NewHashScanOptions().SetMatch("a") resCursor, resCollection, err := client.HScanWithOptions("my_hash", "0", *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(resCursor) fmt.Println( resCollection, ) // The resCollection only contains the hash map entry that matches with the match option provided with the command
Output: 2 0 [a 1]
func (GlideClusterClient) HSet ¶
HSet sets the specified fields to their respective values in the hash stored at key. This command overwrites the values of specified fields that exist in the hash. If key doesn't exist, a new key holding a hash is created.
See valkey.io for details.
Parameters:
key - The key of the hash. values - A map of field-value pairs to set in the hash.
Return value:
The number of fields that were added or updated.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) result1, err := client.HGet("my_hash", "field1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 2 {someValue false}
func (GlideClusterClient) HSetNX ¶
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.
See valkey.io for details.
Parameters:
key - The key of the hash. field - The field to set. value - The value to set.
Return value:
A bool containing true if field is a new field in the hash and value was set. false if field already exists in the hash and no operation was performed.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) result1, err := client.HSetNX("my_hash", "field3", "value") payload, err := client.HGet("my_hash", "field3") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(payload)
Output: 2 true {value false}
func (GlideClusterClient) HStrLen ¶
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.
See valkey.io for details.
Parameters:
key - The key of the hash. field - The field to get the string length of its value.
Return value:
The length of the string value associated with field, or `0` when field or key do not exist.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function fields := map[string]string{ "field1": "someValue", "field2": "someOtherValue", } result, err := client.HSet("my_hash", fields) result1, err := client.HStrLen("my_hash", "field1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 2 9
func (GlideClusterClient) HVals ¶
HVals returns all values in the hash stored at key.
See valkey.io for details.
Parameters:
key - The key of the hash.
Return value:
A slice containing all the values in the hash, or an empty slice when key does not exist.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function // For this example, we only use 1 field for consistent output fields := map[string]string{ "field1": "someValue", // other fields here } result, err := client.HSet("my_hash", fields) result1, err := client.HVals("my_hash") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 1 [someValue]
func (GlideClusterClient) Incr ¶
Increments the number stored at key by one. If key does not exist, it is set to 0 before performing the operation.
See valkey.io for details.
Parameters:
key - The key to increment its value.
Return value:
The value of `key` after the increment.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Set("my_key", "1") result, err := client.Incr("my_key") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 2
func (GlideClusterClient) IncrBy ¶
Increments the number stored at key by amount. If key does not exist, it is set to 0 before performing the operation.
See valkey.io for details.
Parameters:
key - The key to increment its value. amount - The amount to increment.
Return value:
The value of `key` after the increment.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Set("my_key", "5") result, err := client.IncrBy("my_key", 5) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 10
func (GlideClusterClient) IncrByFloat ¶
Increments the string representing a floating point number stored at key by amount. By using a negative increment value, the result is that the value stored at key is decremented. If key does not exist, it is set to `0` before performing the operation.
See valkey.io for details.
Parameters:
key - The key to increment its value. amount - The amount to increment.
Return value:
The value of key after the increment.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Set("my_key", "1") result, err := client.IncrByFloat("my_key", 5.5) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 6.5
func (*GlideClusterClient) Info ¶
func (client *GlideClusterClient) Info() (map[string]string, error)
Gets information and statistics about the server.
The command will be routed to all primary nodes.
See valkey.io for details.
Return value:
A map where each address is the key and its corresponding node response is the information for the default sections.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function response, err := client.Info() if err != nil { fmt.Println("Glide example failed with an error: ", err) } for _, data := range response { if strings.Contains(data, "cluster_enabled:1") { fmt.Println("OK") break } }
Output: OK
func (*GlideClusterClient) InfoWithOptions ¶
func (client *GlideClusterClient) InfoWithOptions(options options.ClusterInfoOptions) (ClusterValue[string], error)
Gets information and statistics about the server.
The command will be routed to all primary nodes, unless `route` in [ClusterInfoOptions] is provided.
See valkey.io for details.
Parameters:
options - Additional command parameters, see [ClusterInfoOptions] for more details.
Return value:
When specifying a route other than a single node or when route is not given, it returns a map where each address is the key and its corresponding node response is the value. When a single node route is given, command returns a string containing the information for the sections requested.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function opts := options.ClusterInfoOptions{ InfoOptions: &options.InfoOptions{Sections: []options.Section{options.Cluster}}, } response, err := client.InfoWithOptions(opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } for _, data := range response.MultiValue() { if strings.Contains(data, "cluster_enabled:1") { fmt.Println("OK") break } }
Output: OK
func (GlideClusterClient) LCS ¶
Returns the longest common subsequence between strings stored at key1 and key2.
Since:
Valkey 7.0 and above.
Note:
In cluster mode, if keys in `keyValueMap` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
key1 - The key that stores the first string. key2 - The key that stores the second string.
Return value:
The longest common subsequence between the 2 strings. An empty string is returned if the keys do not exist or have no common subsequences.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.MSet(map[string]string{"{my_key}1": "oh my gosh", "{my_key}2": "hello world"}) result, err := client.LCS("{my_key}1", "{my_key}2") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: h o
func (GlideClusterClient) LIndex ¶
Returns the element at index from 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.
See valkey.io for details.
Parameters:
key - The key of the list. index - The index of the element in the list to retrieve.
Return value:
The Result[string] containing element at index in the list stored at key. If index is out of range or if key does not exist, [api.CreateNilStringResult()] is returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.LIndex("my_list", 3) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 7 {d false}
func (GlideClusterClient) LInsert ¶
func (client GlideClusterClient) LInsert( key string, insertPosition options.InsertPosition, pivot string, element string, ) (int64, error)
Inserts element in the list at key either before or after the pivot.
See valkey.io for details.
Parameters:
key - The key of the list. insertPosition - The relative position to insert into - either options.Before or options.After the pivot. pivot - An element of the list. element - The new element to insert.
Return value:
The list length after a successful insert operation. If the `key` doesn't exist returns `-1`. If the `pivot` wasn't found, returns `0`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Del([]string{"my_list"}) result, err := client.RPush("my_list", []string{"hello", "world"}) result1, err := client.LInsert("my_list", options.Before, "world", "there") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 2 3
func (GlideClusterClient) LLen ¶
Returns the length of the list stored at key.
See valkey.io for details.
Parameters:
key - The key of the list.
Return value:
The length of the list at `key`. If `key` does not exist, it is interpreted as an empty list and `0` is returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.LLen("my_list") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 7 7
func (GlideClusterClient) LMPop ¶
func (client GlideClusterClient) LMPop(keys []string, listDirection options.ListDirection) (map[string][]string, error)
Pops one element from the first non-empty list from the provided keys.
Since:
Valkey 7.0 and above.
See valkey.io for details.
Parameters:
keys - An array of keys to lists. listDirection - The direction based on which elements are popped from - see [options.ListDirection].
Return value:
A map of key name mapped array of popped element.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.LPush("my_list", []string{"one", "two", "three"}) result1, err := client.LMPop([]string{"my_list"}, options.Left) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 map[my_list:[three]]
func (GlideClusterClient) LMPopCount ¶
func (client GlideClusterClient) LMPopCount( keys []string, listDirection options.ListDirection, count int64, ) (map[string][]string, error)
Pops one or more elements from the first non-empty list from the provided keys.
Since:
Valkey 7.0 and above.
See valkey.io for details.
Parameters:
keys - An array of keys to lists. listDirection - The direction based on which elements are popped from - see [options.ListDirection]. count - The maximum number of popped elements.
Return value:
A map of key name mapped array of popped elements.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.LPush("my_list", []string{"one", "two", "three"}) result1, err := client.LMPopCount([]string{"my_list"}, options.Left, 2) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 map[my_list:[three two]]
func (GlideClusterClient) LMove ¶
func (client GlideClusterClient) LMove( source string, destination string, whereFrom options.ListDirection, whereTo options.ListDirection, ) (Result[string], error)
Atomically pops and removes the left/right-most element to the list stored at source depending on whereFrom, and pushes the element at the first/last element of the list stored at destination depending on whereTo.
See valkey.io for details.
Parameters:
source - The key to the source list. destination - The key to the destination list. wherefrom - The ListDirection the element should be removed from. whereto - The ListDirection the element should be added to.
Return value:
A Result[string] containing the popped element or api.CreateNilStringResult() if source does not exist.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.LPush("{list}-1", []string{"two", "one"}) result1, err := client.LPush("{list}-2", []string{"four", "three"}) result2, err := client.LMove("{list}-1", "{list}-2", options.Left, options.Left) result3, err := client.LRange("{list}-1", 0, -1) result4, err := client.LRange("{list}-2", 0, -1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2) fmt.Println(result3) fmt.Println(result4)
Output: 2 2 {one false} [two] [one three four]
func (GlideClusterClient) LPop ¶
Removes and returns the first elements of the list stored at key. The command pops a single element from the beginning of the list.
See valkey.io for details.
Parameters:
key - The key of the list.
Return value:
The Result[string] containing the value of the first element. If key does not exist, [api.CreateNilStringResult()] will be returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.LPush("my_list", []string{"value1", "value2"}) result1, err := client.LPop("my_list") result2, err := client.LPop("non_existent") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2.IsNil())
Output: 2 {value2 false} true
func (GlideClusterClient) LPopCount ¶
Removes and returns up to count elements of the list stored at key, depending on the list's length.
See valkey.io for details.
Parameters:
key - The key of the list. count - The count of the elements to pop from the list.
Return value:
An array of the popped elements as strings will be returned depending on the list's length If key does not exist, nil will be returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.LPush("my_list", []string{"value1", "value2"}) result1, err := client.LPopCount("my_list", 2) result2, err := client.LPop("non_existent") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2.IsNil())
Output: 2 [value2 value1] true
func (GlideClusterClient) LPos ¶
Returns the index of the first occurrence of element inside the list specified by key. If no match is found, [api.CreateNilInt64Result()] is returned.
See valkey.io for details.
Parameters:
key - The name of the list. element - The value to search for within the list.
Return value:
The Result[int64] containing the index of the first occurrence of element, or [api.CreateNilInt64Result()] if element is not in the list.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e"}) result1, err := client.LPos("my_list", "e") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 6 {4 false}
func (GlideClusterClient) LPosCount ¶
func (client GlideClusterClient) LPosCount(key string, element string, count int64) ([]int64, error)
Returns an array of indices of matching elements within a list.
See valkey.io for details.
Parameters:
key - The name of the list. element - The value to search for within the list. count - The number of matches wanted.
Return value:
An array that holds the indices of the matching elements within the list.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.LPosCount("my_list", "e", 3) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 7 [4 5 6]
func (GlideClusterClient) LPosCountWithOptions ¶
func (client GlideClusterClient) LPosCountWithOptions( key string, element string, count int64, opts options.LPosOptions, ) ([]int64, error)
Returns an array of indices of matching elements within a list based on the given options. If no match is found, an empty array is returned.
See valkey.io for details.
Parameters:
key - The name of the list. element - The value to search for within the list. count - The number of matches wanted. opts - The LPos options.
Return value:
An array that holds the indices of the matching elements within the list.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.LPosCountWithOptions("my_list", "e", 1, *options.NewLPosOptions().SetRank(2)) result2, err := client.LPosCountWithOptions("my_list", "e", 3, *options.NewLPosOptions().SetRank(2).SetMaxLen(1000)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 7 [5] [5 6]
func (GlideClusterClient) LPosWithOptions ¶
func (client GlideClusterClient) LPosWithOptions(key string, element string, options options.LPosOptions) (Result[int64], error)
Returns the index of an occurrence of element within a list based on the given options. If no match is found, [api.CreateNilInt64Result()] is returned.
See valkey.io for details.
Parameters:
key - The name of the list. element - The value to search for within the list. options - The LPos options.
Return value:
The Result[int64] containing the index of element, or [api.CreateNilInt64Result()] if element is not in the list.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e"}) result1, err := client.LPosWithOptions( "my_list", "e", *options.NewLPosOptions().SetRank(2), ) // (Returns the second occurrence of the element "e") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 6 {5 false}
func (GlideClusterClient) LPush ¶
Inserts all the specified values at the head of the list stored at key. elements are inserted one after the other to the head of the list, from the leftmost element to the rightmost element. If key does not exist, it is created as an empty list before performing the push operation.
See valkey.io for details.
Parameters:
key - The key of the list. elements - The elements to insert at the head of the list stored at key.
Return value:
The length of the list after the push operation.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.LPush("my_list", []string{"value1", "value2"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 2
func (GlideClusterClient) LPushX ¶
Inserts all the specified values at the head of the list stored at key, only if key exists and holds a list. If key is not a list, this performs no operation.
See valkey.io for details.
Parameters:
key - The key of the list. elements - The elements to insert at the head of the list stored at key.
Return value:
The length of the list after the push operation.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.RPush("my_list", []string{"value1"}) result1, err := client.LPushX("my_list", []string{"value2", "value3"}) result2, err := client.LRange("my_list", 0, -1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 1 3 [value3 value2 value1]
func (GlideClusterClient) LRange ¶
Returns the specified elements of the list stored at key. The offsets start and end are zero-based indexes, with 0 being the first element 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, with -1 being the last element of the list, -2 being the penultimate, and so on.
See valkey.io for details.
Parameters:
key - The key of the list. start - The starting point of the range. end - The end of the range.
Return value:
Array of elements as Result[string] in the specified range. If start exceeds the end of the list, or if start is greater than end, an empty array will be returned. If end exceeds the actual end of the list, the range will stop at the actual end of the list. If key does not exist an empty array will be returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.LRange("my_list", 0, 2) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 7 [a b c]
func (GlideClusterClient) LRem ¶
Removes the first count occurrences of elements equal to element from the list stored at key. If count is positive: Removes elements equal to element moving from head to tail. If count is negative: Removes elements equal to element moving from tail to head. If count is 0 or count is greater than the occurrences of elements equal to element, it removes all elements equal to element.
See valkey.io for details.
Parameters:
key - The key of the list. count - The count of the occurrences of elements equal to element to remove. element - The element to remove from the list.
Return value:
The number of the removed elements. If `key` does not exist, `0` is returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.LRem("my_list", 2, "e") result2, err := client.LRange("my_list", 0, -1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 7 2 [a b c d e]
func (GlideClusterClient) LSet ¶
Sets the list element at index to element. 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.
See valkey.io for details.
Parameters:
key - The key of the list. index - The index of the element in the list to be set. element - The element to be set.
Return value:
`"OK"`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.LPush("my_list", []string{"one", "two", "three"}) result1, err := client.LSet("my_list", 1, "someOtherValue") result2, err := client.LRange("my_list", 0, -1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 3 OK [three someOtherValue one]
func (GlideClusterClient) LTrim ¶
Trims an existing list so that it will contain only the specified range of elements specified. The offsets start and end are zero-based indexes, with 0 being the first element 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, with -1 being the last element of the list, -2 being the penultimate, and so on.
See valkey.io for details.
Parameters:
key - The key of the list. start - The starting point of the range. end - The end of the range.
Return value:
Always `"OK"`. If start exceeds the end of the list, or if start is greater than end, the result will be an empty list (which causes key to be removed). If end exceeds the actual end of the list, it will be treated like the last element of the list. If key does not exist, `"OK"` will be returned without changes to the database.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.LTrim("my_list", 0, 4) result2, err := client.LRange("my_list", 0, -1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 7 OK [a b c d e]
func (GlideClusterClient) MGet ¶
Retrieves the values of multiple keys.
Note:
In cluster mode, if keys in `keys` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
keys - A list of keys to retrieve values for.
Return value:
An array of values corresponding to the provided keys. If a key is not found, its corresponding value in the list will be a [api.CreateNilStringResult()]
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.MSet(map[string]string{"my_key1": "my_value1", "my_key2": "my_value2", "my_key3": "my_value3"}) keys := []string{"my_key1", "my_key2", "my_key3"} result, err := client.MGet(keys) if err != nil { fmt.Println("Glide example failed with an error: ", err) } for _, res := range result { fmt.Println(res.Value()) }
Output: my_value1 my_value2 my_value3
func (GlideClusterClient) MSet ¶
Sets multiple keys to multiple values in a single operation.
Note:
In cluster mode, if keys in `keyValueMap` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
keyValueMap - A key-value map consisting of keys and their respective values to set.
Return value:
`"OK"` on success.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function keyValueMap := map[string]string{ "key1": "value1", "key2": "value2", } result, err := client.MSet(keyValueMap) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: OK
func (GlideClusterClient) MSetNX ¶
Sets multiple keys to values if the key does not exist. The operation is atomic, and if one or more keys already exist, the entire operation fails.
Note:
In cluster mode, if keys in `keyValueMap` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
keyValueMap - A key-value map consisting of keys and their respective values to set.
Return value:
A bool containing true, if all keys were set. false, if no key was set.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function keyValueMap := map[string]string{"{my_key}1": "my_value1", "{my_key}2": "my_value2"} result, err := client.MSetNX(keyValueMap) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) client.Set("{my_key}3", "my_value3") result, _ = client.MSetNX(map[string]string{"{my_key}3": "my_value3"}) fmt.Println(result)
Output: true false
func (GlideClusterClient) ObjectEncoding ¶
Returns the internal encoding for the Valkey object stored at key.
Note:
When in cluster mode, both key and newkey must map to the same hash slot.
Parameters:
The key of the object to get the internal encoding of.
Return value:
If key exists, returns the internal encoding of the object stored at key as a String. Otherwise, returns `null`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.ObjectEncoding("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK {embstr false}
func (GlideClusterClient) ObjectFreq ¶
Returns the logarithmic access frequency counter of a Valkey object stored at key.
Parameters:
key - The key of the object to get the logarithmic access frequency counter of.
Return value:
If key exists, returns the logarithmic access frequency counter of the object stored at key as a long. Otherwise, returns `nil`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function // TODO: Once ConfigSet and ConfigGet are implemented, replace CustomCommand client.CustomCommand([]string{"CONFIG", "SET", "maxmemory-policy", "allkeys-lfu"}) result, err := client.Set("key1", "someValue") _, err = client.Set("key1", "someOtherValue") result1, err := client.ObjectFreq("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK {6 false}
func (GlideClusterClient) ObjectIdleTime ¶
Returns the logarithmic access frequency counter of a Valkey object stored at key.
Parameters:
key - The key of the object to get the logarithmic access frequency counter of.
Return value:
If key exists, returns the idle time in seconds. Otherwise, returns `nil`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function // TODO: Once ConfigSet and ConfigGet are implemented, replace CustomCommand client.CustomCommand([]string{"CONFIG", "SET", "maxmemory-policy", "allkeys-lru"}) result, err := client.Set("key1", "someValue") result1, err := client.ObjectIdleTime("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK {0 false}
func (GlideClusterClient) ObjectRefCount ¶
Returns the reference count of the object stored at key.
Parameters:
key - The key of the object to get the reference count of.
Return value:
If key exists, returns the reference count of the object stored at key. Otherwise, returns `nil`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.CustomCommand([]string{"CONFIG", "SET", "maxmemory-policy", "allkeys-lru"}) result, err := client.Set("key1", "someValue") result1, err := client.ObjectRefCount("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK {1 false}
func (GlideClusterClient) PExpire ¶
Parameters:
key - The key to set timeout on it. milliseconds - The timeout in milliseconds.
Return value:
`true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.PExpire("key", int64(5*1000)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK true
func (GlideClusterClient) PExpireAt ¶
func (client GlideClusterClient) PExpireAt(key string, unixTimestampInMilliSeconds int64) (bool, error)
Sets a timeout on key. It takes an absolute Unix timestamp (milliseconds since January 1, 1970) instead of specifying the number of milliseconds. A timestamp in the past will delete the key immediately. After the timeout has expired, the key will automatically be deleted If key already has an existing expire set, the time to live is updated to the new value/ The timeout will only be cleared by commands that delete or overwrite the contents of key
Parameters:
key - The key to set timeout on it. unixMilliseconds - The timeout in an absolute Unix timestamp.
Return value:
`true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.PExpireAt("key", time.Now().Unix()*1000) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK true
func (GlideClusterClient) PExpireAtWithOptions ¶
func (client GlideClusterClient) PExpireAtWithOptions( key string, unixTimestampInMilliSeconds int64, expireCondition options.ExpireCondition, ) (bool, error)
Sets a timeout on key. It takes an absolute Unix timestamp (milliseconds since January 1, 1970) instead of specifying the number of milliseconds. A timestamp in the past will delete the key immediately. After the timeout has expired, the key will automatically be deleted. If key already has an existing expire set, the time to live is updated to the new value. The timeout will only be cleared by commands that delete or overwrite the contents of key
Parameters:
key - The key to set timeout on it. unixMilliseconds - The timeout in an absolute Unix timestamp. option - The option to set expiry, see [options.ExpireCondition].
Return value:
`true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.PExpireAtWithOptions("key", time.Now().Unix()*1000, options.HasNoExpiry) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK true
func (GlideClusterClient) PExpireTime ¶
PExpire Time returns the absolute Unix timestamp (since January 1, 1970) at which the given key will expire, in milliseconds.
Parameters:
key - The key to determine the expiration value of.
Return value:
The expiration Unix timestamp in milliseconds. `-2` if key does not exist or `-1` is key exists but has no associated expiration.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.PExpireTime("key") _, err = client.PExpireAt("key", time.Now().Unix()*1000) // PExpireTime("key") returns proper unix time in milliseconds if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK -1
func (GlideClusterClient) PExpireWithOptions ¶
func (client GlideClusterClient) PExpireWithOptions( key string, milliseconds int64, expireCondition options.ExpireCondition, ) (bool, error)
Sets a timeout on key in milliseconds. After the timeout has expired, the key will automatically be deleted. If key already has an existing expire set, the time to live is updated to the new value. If milliseconds is a non-positive number, the key will be deleted rather than expired The timeout will only be cleared by commands that delete or overwrite the contents of key.
Parameters:
key - The key to set timeout on it. milliseconds - The timeout in milliseconds. option - The option to set expiry, see [options.ExpireCondition].
Return value:
`true` if the timeout was set. `false` if the timeout was not set. e.g. key doesn't exist, or operation skipped due to the provided arguments.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.PExpireWithOptions("key", int64(5*1000), options.HasNoExpiry) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK true
func (GlideClusterClient) PTTL ¶
PTTL returns the remaining time to live of key that has a timeout, in milliseconds.
Parameters:
key - The key to return its timeout.
Return value:
Returns TTL in milliseconds, `-2` if key does not exist, or `-1` if key exists but has no associated expiration.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.PTTL("key") _, err = client.PExpireAt("key", time.Now().Unix()*100000) // PTTL("key") returns proper TTL in milliseconds if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK -1
func (GlideClusterClient) 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).
Parameters:
key - The key to remove the existing timeout on.
Return value:
`false` if key does not exist or does not have an associated timeout, `true` if the timeout has been removed.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.ExpireAt("key1", time.Now().Unix()*1000) result2, err := client.Persist("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: OK true true
func (GlideClusterClient) PfAdd ¶
PfAdd adds all elements to the HyperLogLog data structure stored at the specified key. Creates a new structure if the key does not exist. When no elements are provided, and key exists and is a HyperLogLog, then no operation is performed. If key does not exist, then the HyperLogLog structure is created.
Parameters:
key - The key of the HyperLogLog data structure to add elements into. elements - An array of members to add to the HyperLogLog stored at key.
Return value:
If the HyperLogLog is newly created, or if the HyperLogLog approximated cardinality is altered, then returns `1`. Otherwise, returns `0`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.PfAdd(uuid.New().String(), []string{"value1", "value2", "value3"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 1
func (GlideClusterClient) PfCount ¶
Estimates the cardinality of the data stored in a HyperLogLog structure for a single key or calculates the combined cardinality of multiple keys by merging their HyperLogLogs temporarily.
Note:
In cluster mode, if keys in `keyValueMap` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
key - The keys of the HyperLogLog data structures to be analyzed.
Return value:
The approximated cardinality of given HyperLogLog data structures. The cardinality of a key that does not exist is `0`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := uuid.New().String() result, err := client.PfAdd(key, []string{"value1", "value2", "value3"}) result1, err := client.PfCount([]string{key}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 1 3
func (*GlideClusterClient) Ping ¶
func (client *GlideClusterClient) Ping() (string, error)
Pings the server. The command will be routed to all primary nodes.
Return value:
Returns "PONG".
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Ping() if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: PONG
func (*GlideClusterClient) PingWithOptions ¶
func (client *GlideClusterClient) PingWithOptions(pingOptions options.ClusterPingOptions) (string, error)
Pings the server. The command will be routed to all primary nodes, unless `Route` is provided in `pingOptions`.
Parameters:
pingOptions - The [ClusterPingOptions] type.
Return value:
Returns the copy of message.
For example:
route := options.RouteOption{config.RandomRoute} opts := options.ClusterPingOptions{ &options.PingOptions{ "Hello" }, &route } result, err := clusterClient.PingWithOptions(opts) fmt.Println(result) // Output: Hello
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function options := options.ClusterPingOptions{ PingOptions: &options.PingOptions{ Message: "hello", }, RouteOption: nil, } result, err := client.PingWithOptions(options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: hello
func (GlideClusterClient) RPop ¶
Removes and returns the last elements of the list stored at key. The command pops a single element from the end of the list.
See valkey.io for details.
Parameters:
key - The key of the list.
Return value:
The Result[string] containing the value of the last element. If key does not exist, [api.CreateNilStringResult()] will be returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.RPop("my_list") result2, err := client.RPop("non_existing_key") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2.IsNil())
Output: 7 {e false} true
func (GlideClusterClient) RPopCount ¶
Removes and returns up to count elements from the list stored at key, depending on the list's length.
See valkey.io for details.
Parameters:
key - The key of the list. count - The count of the elements to pop from the list.
Return value:
An array of popped elements as strings will be returned depending on the list's length. If key does not exist, nil will be returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) result1, err := client.RPopCount("my_list", 4) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 7 [e e e d]
func (GlideClusterClient) RPush ¶
Inserts all the specified values at the tail of the list stored at key. elements are inserted one after the other to the tail of the list, from the leftmost element to the rightmost element. If key does not exist, it is created as an empty list before performing the push operation.
See valkey.io for details.
Parameters:
key - The key of the list. elements - The elements to insert at the tail of the list stored at key.
Return value:
The length of the list after the push operation.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 7
func (GlideClusterClient) RPushX ¶
Inserts all the specified values at the tail of the list stored at key, only if key exists and holds a list. If key is not a list, this performs no operation.
See valkey.io for details.
Parameters:
key - The key of the list. elements - The elements to insert at the tail of the list stored at key.
Return value:
The length of the list after the push operation.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.RPush("my_list", []string{"value1"}) result1, err := client.RPushX("my_list", []string{"value2", "value3"}) result2, err := client.LRange("my_list", 0, -1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 1 3 [value1 value2 value3]
func (GlideClusterClient) Rename ¶
Renames key to new key.
If new Key already exists it is overwritten.
Note:
When in cluster mode, both key and newKey must map to the same hash slot.
Parameters:
key - The key to rename. newKey - The new name of the key.
Return value:
If the key was successfully renamed, return "OK". If key does not exist, an error is thrown.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("{key}1", "someValue") result1, err := client.Rename("{key}1", "{key}2") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK OK
func (GlideClusterClient) RenameNX ¶
Renames key to newkey if newKey does not yet exist.
Note:
When in cluster mode, both key and newkey must map to the same hash slot.
Parameters:
key - The key to rename. newKey - The new name of the key.
Return value:
`true` if key was renamed to `newKey`, `false` if `newKey` already exists.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("{key}1", "someValue") result1, err := client.RenameNX("{key}1", "{key}2") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK true
func (GlideClusterClient) Restore ¶
func (client GlideClusterClient) Restore(key string, ttl int64, value string) (Result[string], error)
Create a key associated with a value that is obtained by deserializing the provided serialized value (obtained via valkey.io: Https://valkey.io/commands/dump/).
Parameters:
key - The key to create. ttl - The expiry time (in milliseconds). If 0, the key will persist. value - The serialized value to deserialize and assign to key.
Return value:
Return OK if successfully create a key with a value </code>.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key1", "someValue") dump, err := client.Dump("key1") result1, err := client.Del([]string{"key1"}) result2, err := client.Restore("key1", 0, dump.Value()) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2.Value())
Output: OK 1 OK
func (GlideClusterClient) RestoreWithOptions ¶
func (client GlideClusterClient) RestoreWithOptions(key string, ttl int64, value string, options options.RestoreOptions, ) (Result[string], error)
Create a key associated with a value that is obtained by deserializing the provided serialized value (obtained via valkey.io: Https://valkey.io/commands/dump/).
Parameters:
key - The key to create. ttl - The expiry time (in milliseconds). If 0, the key will persist. value - The serialized value to deserialize and assign to key. restoreOptions - Set restore options with replace and absolute TTL modifiers, object idletime and frequency.
Return value:
Return OK if successfully create a key with a value.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key1", "someValue") dump, err := client.Dump("key1") result1, err := client.Del([]string{"key1"}) opts := options.NewRestoreOptions().SetReplace().SetABSTTL().SetEviction(options.FREQ, 10) result2, err := client.RestoreWithOptions("key1", 0, dump.Value(), *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2.Value())
Output: OK 1 OK
func (GlideClusterClient) SAdd ¶
SAdd adds specified members to the set stored at key.
See valkey.io for details.
Parameters:
key - The key where members will be added to its set. members - A list of members to add to the set stored at key.
Return value:
The number of members that were added to the set, excluding members already present.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "my_set" result, err := client.SAdd(key, []string{"member1", "member2"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 2
func (GlideClusterClient) SCard ¶
SCard retrieves the set cardinality (number of elements) of the set stored at key.
See valkey.io for details.
Parameters:
key - The key from which to retrieve the number of set members.
Return value:
The cardinality (number of elements) of the set, or `0` if the key does not exist.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "my_set" client.SAdd(key, []string{"member1", "member2"}) result, err := client.SCard(key) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 2
func (GlideClusterClient) SDiff ¶
SDiff computes the difference between the first set and all the successive sets in keys.
Note: When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
keys - The keys of the sets to diff.
Return value:
A `map[string]struct{}` representing the difference between the sets. If a key does not exist, it is treated as an empty set.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key1 := "{set}1" key2 := "{set}2" client.SAdd(key1, []string{"member1", "member2"}) client.SAdd(key2, []string{"member2"}) result, err := client.SDiff([]string{key1, key2}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: map[member1:{}]
func (GlideClusterClient) SDiffStore ¶
SDiffStore stores the difference between the first set and all the successive sets in keys into a new set at destination.
Note: When in cluster mode, destination and all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
destination - The key of the destination set. keys - The keys of the sets to diff.
Return value:
The number of elements in the resulting set.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key1 := "{set}1" key2 := "{set}2" destination := "{set}3" client.SAdd(key1, []string{"member1", "member2"}) client.SAdd(key2, []string{"member2"}) result, err := client.SDiffStore(destination, []string{key1, key2}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 1
func (GlideClusterClient) SInter ¶
SInter gets the intersection of all the given sets.
Note: When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
keys - The keys of the sets to intersect.
Return value:
A `map[string]struct{}` containing members which are present in all given sets. If one or more sets do not exist, an empty collection will be returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key1 := "{set}1" key2 := "{set}2" client.SAdd(key1, []string{"member1", "member2"}) client.SAdd(key2, []string{"member2"}) result, err := client.SInter([]string{key1, key2}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: map[member2:{}]
func (GlideClusterClient) SInterCard ¶
SInterCard gets the cardinality of the intersection of all the given sets.
Since:
Valkey 7.0 and above.
Note: When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
keys - The keys of the sets to intersect.
Return value:
The cardinality of the intersection result. If one or more sets do not exist, `0` is returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key1 := "{set}1" key2 := "{set}2" client.SAdd(key1, []string{"member1", "member2"}) client.SAdd(key2, []string{"member2"}) result, err := client.SInterCard([]string{key1, key2}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 1
func (GlideClusterClient) SInterCardLimit ¶
SInterCardLimit gets the cardinality of the intersection of all the given sets, up to the specified limit.
Since:
Valkey 7.0 and above.
Note: When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
keys - The keys of the sets to intersect. limit - The limit for the intersection cardinality value.
Return value:
The cardinality of the intersection result, or the limit if reached. If one or more sets do not exist, `0` is returned. If the intersection cardinality reaches 'limit' partway through the computation, returns 'limit' as the cardinality.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key1 := "{set}1" key2 := "{set}2" limit := int64(1) client.SAdd(key1, []string{"member1", "member2", "member3"}) client.SAdd(key2, []string{"member2", "member3"}) result, err := client.SInterCardLimit([]string{key1, key2}, limit) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 1
func (GlideClusterClient) SInterStore ¶
Stores the members of the intersection of all given sets specified by `keys` into a new set at `destination`
Note: When in cluster mode, `destination` and all `keys` must map to the same hash slot.
See valkey.io for details.
Parameters:
destination - The key of the destination set. keys - The keys from which to retrieve the set members.
Return value:
The number of elements in the resulting set.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key1 := "{set}1" key2 := "{set}2" destination := "{set}3" client.SAdd(key1, []string{"member1", "member2"}) client.SAdd(key2, []string{"member2"}) result, err := client.SInterStore(destination, []string{key1, key2}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 1
func (GlideClusterClient) SIsMember ¶
SIsMember returns if member is a member of the set stored at key.
See valkey.io for details.
Parameters:
key - The key of the set. member - The member to check for existence in the set.
Return value:
A bool containing true if the member exists in the set, false otherwise. If key doesn't exist, it is treated as an empty set and the method returns false.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "my_set" client.SAdd(key, []string{"member1", "member2"}) result, err := client.SIsMember(key, "member1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: true
func (GlideClusterClient) SMIsMember ¶
SMIsMember returns whether each member is a member of the set stored at key.
See valkey.io for details.
Parameters:
key - The key of the set.
Return value:
A []bool containing whether each member is a member of the set stored at key.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "my_set" members := []string{"member1", "member2"} client.SAdd(key, members) memberTest := []string{"member1", "member2", "member3"} result, err := client.SMIsMember(key, memberTest) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: [true true false]
func (GlideClusterClient) SMembers ¶
SMembers retrieves all the members of the set value stored at key.
See valkey.io for details.
Parameters:
key - The key from which to retrieve the set members.
Return value:
A `map[string]struct{}` containing all members of the set. Returns an empty collection if key does not exist.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "my_set" client.SAdd(key, []string{"member1", "member2"}) result, err := client.SMembers(key) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: map[member1:{} member2:{}]
func (GlideClusterClient) SMove ¶
func (client GlideClusterClient) SMove(source string, destination string, member string) (bool, error)
Moves `member` from the set at `source` to the set at `destination`, removing it from the source set. Creates a new destination set if needed. The operation is atomic.
Note: When in cluster mode, `source` and `destination` must map to the same hash slot.
See valkey.io for details.
Parameters:
source - The key of the set to remove the element from. destination - The key of the set to add the element to. member - The set element to move.
Return value:
`true` on success, or `false` if the `source` set does not exist or the element is not a member of the source set.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function source := "{set}1" destination := "{set}2" member := "member1" client.SAdd(source, []string{member}) result, err := client.SMove(source, destination, member) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: true
func (GlideClusterClient) SPop ¶
SPop removes and returns one random member from the set stored at key.
See valkey.io for details.
Parameters:
key - The key of the set.
Return value:
A Result[string] containing the value of the popped member. Returns a NilResult if key does not exist.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "my_set" client.SAdd(key, []string{"member1", "member2"}) result, err := client.SPop(key) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.IsNil())
Output: false
func (GlideClusterClient) SRandMember ¶
SRandMember returns a random element from the set value stored at key.
See valkey.io for details.
Parameters:
key - The key from which to retrieve the set member.
Return value:
A Result[string] containing a random element from the set. Returns api.CreateNilStringResult() if key does not exist.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "my_set" client.SAdd(key, []string{"member1", "member2"}) result, err := client.SRandMember(key) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.IsNil()) // Unable to test for a random value so just check if it is not nil
Output: false
func (GlideClusterClient) SRem ¶
SRem removes specified members from the set stored at key.
See valkey.io for details.
Parameters:
key - The key from which members will be removed. members - A list of members to remove from the set stored at key.
Return value:
The number of members that were removed from the set, excluding non-existing members.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "my_set" client.SAdd(key, []string{"member1", "member2", "member3", "member4", "member5"}) result, err := client.SRem(key, []string{"member1", "member2"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 2
func (GlideClusterClient) SScan ¶
Iterates incrementally over a set.
Note: When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
key - The key of the set. cursor - The cursor that points to the next iteration of results. A value of `"0"` indicates the start of the search. For Valkey 8.0 and above, negative cursors are treated like the initial cursor("0").
Return value:
An array of the cursor and the subset of the set held by `key`. The first element is always the `cursor` and for the next iteration of results. The `cursor` will be `"0"` on the last iteration of the set. The second element is always an array of the subset of the set held in `key`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "my_set" client.SAdd(key, []string{"member1", "member2"}) cursor := "0" result, nextCursor, err := client.SScan(key, cursor) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result, nextCursor)
Output: 0 [member1 member2]
func (GlideClusterClient) SScanWithOptions ¶
func (client GlideClusterClient) SScanWithOptions( key string, cursor string, options options.BaseScanOptions, ) (string, []string, error)
Iterates incrementally over a set.
Note: When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
key - The key of the set. cursor - The cursor that points to the next iteration of results. A value of `"0"` indicates the start of the search. For Valkey 8.0 and above, negative cursors are treated like the initial cursor("0"). options - [options.BaseScanOptions]
Return value:
An array of the cursor and the subset of the set held by `key`. The first element is always the `cursor` and for the next iteration of results. The `cursor` will be `"0"` on the last iteration of the set. The second element is always an array of the subset of the set held in `key`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "my_set" client.SAdd(key, []string{"member1", "member2", "item3"}) cursor := "0" options := options.NewBaseScanOptions().SetMatch("mem*") result, nextCursor, err := client.SScanWithOptions(key, cursor, *options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result, nextCursor)
Output: 0 [member1 member2]
func (GlideClusterClient) SUnion ¶
SUnion gets the union of all the given sets.
Note: When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
keys - The keys of the sets.
Return value:
A `map[string]struct{}` of members which are present in at least one of the given sets. If none of the sets exist, an empty collection will be returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key1 := "{set}1" key2 := "{set}2" client.SAdd(key1, []string{"member1", "member2"}) client.SAdd(key2, []string{"member2", "member3"}) result, err := client.SUnion([]string{key1, key2}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: map[member1:{} member2:{} member3:{}]
func (GlideClusterClient) SUnionStore ¶
SUnionStore stores the members of the union of all given sets specified by `keys` into a new set at `destination`.
Note: When in cluster mode, `destination` and all `keys` must map to the same hash slot.
See valkey.io for details.
Parameters:
destination - The key of the destination set. keys - The keys from which to retrieve the set members.
Return value:
The number of elements in the resulting set.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key1 := "{set}1" key2 := "{set}2" destination := "{set}3" client.SAdd(key1, []string{"member1", "member2"}) client.SAdd(key2, []string{"member2", "member3"}) result, err := client.SUnionStore(destination, []string{key1, key2}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 3
func (GlideClusterClient) Set ¶
Set the given key with the given value. The return value is a response from Valkey containing the string "OK".
See valkey.io for details.
Parameters:
key - The key to store. value - The value to store with the given key.
Return value:
`"OK"` response on success.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("my_key", "my_value") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: OK
func (GlideClusterClient) SetBit ¶
Sets or clears the bit at offset in the string value stored at key. The offset is a zero-based index, with `0` being the first element of the list, `1` being the next element, and so on. The offset must be less than `2^32` and greater than or equal to `0` If a key is non-existent then the bit at offset is set to value and the preceding bits are set to `0`.
Parameters:
key - The key of the string. offset - The index of the bit to be set. value - The bit value to set at offset The value must be `0` or `1`.
Return value:
The bit value that was previously stored at offset.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.SetBit("my_key", 1, 1) // initialize bit 1 with a value of 1 result, err := client.SetBit("my_key", 1, 1) // set bit should return the previous value of bit 1 if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 1
func (GlideClusterClient) SetRange ¶
Overwrites part of the string stored at key, starting at the specified byte's 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. Creates the key if it doesn't exist.
See valkey.io for details.
Parameters:
key - The key of the string to update. offset - The position in the string where value should be written. value - The string written with offset.
Return value:
The length of the string stored at `key` after it was modified.
Example (One) ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Set("my_key", "my_value") result, err := client.SetRange("my_key", 3, "example") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) value, _ := client.Get("my_key") fmt.Println(value.Value())
Output: 10 my_example
Example (Two) ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Set("my_key", "愛") // "愛" is a single character in UTF-8, but 3 bytes long result, err := client.SetRange("my_key", 1, "a") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 3
func (GlideClusterClient) SetWithOptions ¶
func (client GlideClusterClient) SetWithOptions(key string, value string, options options.SetOptions) (Result[string], error)
SetWithOptions sets the given key with the given value using the given options. The return value is dependent on the passed options. If the value is successfully set, "OK" is returned. If value isn't set because of [OnlyIfExists] or [OnlyIfDoesNotExist] conditions, api.CreateNilStringResult() is returned. If [SetOptions#ReturnOldValue] is set, the old value is returned.
See valkey.io for details.
Parameters:
key - The key to store. value - The value to store with the given key. options - The [api.SetOptions].
Return value:
If the value is successfully set, return api.Result[string] containing "OK". If value isn't set because of ConditionalSet.OnlyIfExists or ConditionalSet.OnlyIfDoesNotExist conditions, return api.CreateNilStringResult(). If SetOptions.returnOldValue is set, return the old value as a String.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function options := options.NewSetOptions(). SetExpiry(options.NewExpiry(). SetType(options.Seconds). SetCount(uint64(5))) result, err := client.SetWithOptions("my_key", "my_value", *options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.Value())
Output: OK
func (GlideClusterClient) Sort ¶
Sorts the elements in the list, set, or sorted set at key and returns the result. The sort command can be used to sort elements based on different criteria and apply transformations on sorted elements. To store the result into a new key, see the sortStore function.
Parameters:
key - The key of the list, set, or sorted set to be sorted.
Return value:
An Array of sorted elements.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.LPush("key1", []string{"1", "3", "2", "4"}) result1, err := client.Sort("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 [{1 false} {2 false} {3 false} {4 false}]
func (GlideClusterClient) SortReadOnly ¶
Sorts the elements in the list, set, or sorted set at key and returns the result. The sortReadOnly command can be used to sort elements based on different criteria and apply transformations on sorted elements. This command is routed depending on the client's ReadFrom strategy.
Parameters:
key - The key of the list, set, or sorted set to be sorted.
Return value:
An Array of sorted elements.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.LPush("key1", []string{"1", "3", "2", "4"}) result1, err := client.SortReadOnly("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 [{1 false} {2 false} {3 false} {4 false}]
func (GlideClusterClient) SortReadOnlyWithOptions ¶
func (client GlideClusterClient) SortReadOnlyWithOptions(key string, options options.SortOptions) ([]Result[string], error)
Sorts the elements in the list, set, or sorted set at key and returns the result. The sort command can be used to sort elements based on different criteria and apply transformations on sorted elements. This command is routed depending on the client's ReadFrom strategy.
Note:
In cluster mode, if `key` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity. The use of SortOptions.byPattern and SortOptions.getPatterns in cluster mode is supported since Valkey version 8.0.
Parameters:
key - The key of the list, set, or sorted set to be sorted. sortOptions - The SortOptions type.
Return value:
An Array of sorted elements.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function opts := options.NewSortOptions().SetIsAlpha(false).SetOrderBy(options.ASC) result, err := client.LPush("key1", []string{"3", "1", "2"}) result1, err := client.SortReadOnlyWithOptions("key1", *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 [{1 false} {2 false} {3 false}]
func (GlideClusterClient) SortStore ¶
Sorts the elements in the list, set, or sorted set at key and stores the result in destination. The sort command can be used to sort elements based on different criteria, apply transformations on sorted elements, and store the result in a new key. The sort command can be used to sort elements based on different criteria and apply transformations on sorted elements. To get the sort result without storing it into a key, see the sort or sortReadOnly function.
Note:
In cluster mode, if `key` and `destination` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
key - The key of the list, set, or sorted set to be sorted. destination - The key where the sorted result will be stored.
Return value:
The number of elements in the sorted key stored at destination.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.LPush("{key}1", []string{"1", "3", "2", "4"}) result1, err := client.SortStore("{key}1", "{key}2") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 4
func (GlideClusterClient) SortStoreWithOptions ¶
func (client GlideClusterClient) SortStoreWithOptions( key string, destination string, opts options.SortOptions, ) (int64, error)
Sorts the elements in the list, set, or sorted set at key and stores the result in destination. The sort command can be used to sort elements based on different criteria, apply transformations on sorted elements, and store the result in a new key. The sort command can be used to sort elements based on different criteria and apply transformations on sorted elements. To get the sort result without storing it into a key, see the sort or sortReadOnly function.
Note:
In cluster mode, if `key` and `destination` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity. The use of SortOptions.byPattern and SortOptions.getPatterns in cluster mode is supported since Valkey version 8.0.
Parameters: key - The key of the list, set, or sorted set to be sorted. destination - The key where the sorted result will be stored. opts - The options.SortOptions type.
Return value:
The number of elements in the sorted key stored at destination.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function opts := options.NewSortOptions().SetIsAlpha(false).SetOrderBy(options.ASC) result, err := client.LPush("{key}1", []string{"3", "1", "2"}) result1, err := client.SortStoreWithOptions("{key}1", "{key}2", *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 3
func (GlideClusterClient) SortWithOptions ¶
func (client GlideClusterClient) SortWithOptions(key string, options options.SortOptions) ([]Result[string], error)
Sorts the elements in the list, set, or sorted set at key and returns the result. The sort command can be used to sort elements based on different criteria and apply transformations on sorted elements. To store the result into a new key, see the sortStore function.
Note:
In cluster mode, if `key` map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity. The use of SortOptions.byPattern and SortOptions.getPatterns in cluster mode is supported since Valkey version 8.0.
Parameters:
key - The key of the list, set, or sorted set to be sorted. sortOptions - The SortOptions type.
Return value:
An Array of sorted elements.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function opts := options.NewSortOptions().SetIsAlpha(false).SetOrderBy(options.ASC) result, err := client.LPush("key1", []string{"3", "1", "2"}) result1, err := client.SortWithOptions("key1", *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 [{1 false} {2 false} {3 false}]
func (GlideClusterClient) Strlen ¶
Returns the length of the string value stored at key.
See valkey.io for details.
Parameters:
key - The key to check its length.
Return value:
The length of the string value stored at `key`. If key does not exist, it is treated as an empty string, and the command returns `0`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Set("my_key", "my_value") result, err := client.Strlen("my_key") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 8
func (GlideClusterClient) TTL ¶
TTL returns the remaining time to live of key that has a timeout, in seconds.
Parameters:
key - The key to return its timeout.
Return value:
Returns TTL in seconds, `-2` if key does not exist, or `-1` if key exists but has no associated expiration.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key", "someValue") result1, err := client.TTL("key") _, err = client.ExpireAt("key", time.Now().Unix()*1000) // TTL("key") returns proper TTL in seconds if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK -1
func (GlideClusterClient) Time ¶
Returns the server time.
Return value:
The current server time as a String array with two elements: A UNIX TIME and the amount of microseconds already elapsed in the current second. The returned array is in a [UNIX TIME, Microseconds already elapsed] format.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function timeMargin := int64(5) clientTime := time.Now().Unix() result, err := client.Time() if err != nil { fmt.Println("Glide example failed with an error: ", err) } serverTime, _ := strconv.ParseInt(result[0], 10, 64) fmt.Println((serverTime - clientTime) < timeMargin)
Output: true
func (*GlideClusterClient) TimeWithOptions ¶
func (client *GlideClusterClient) TimeWithOptions(opts options.RouteOption) (ClusterValue[[]string], error)
Returns the server time. The command will be routed to a random node, unless Route in opts is provided.
See valkey.io for details.
Parameters:
options - The [RouteOption] type.
Return value:
The current server time as a String array with two elements: A UNIX TIME and the amount of microseconds already elapsed in the current second. The returned array is in a [UNIX TIME, Microseconds already elapsed] format.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function route := config.Route(config.RandomRoute) opts := options.RouteOption{ Route: route, } clusterResponse, err := client.TimeWithOptions(opts) // gives: {1 [1738714595 942076] map[]} if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(len(clusterResponse.SingleValue()) == 2)
Output: true
func (GlideClusterClient) Touch ¶
Alters the last access time of a key(s). A key is ignored if it does not exist.
Note:
In cluster mode, if keys in keys map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
keys - The keys to update last access time.
Return value:
The number of keys that were updated.
[valkey.io]: Https://valkey.io/commands/touch/
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.Set("key2", "someValue") result2, err := client.Touch([]string{"key1", "key2", "key3"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: OK OK 2
func (GlideClusterClient) Type ¶
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.
Parameters:
key - string
Return value:
If the key exists, the type of the stored value is returned. Otherwise, a "none" string is returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.Type("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: OK string
func (GlideClusterClient) Unlink ¶
Unlink (delete) multiple keys from the database. A key is ignored if it does not exist. This command, similar to Del However, this command does not block the server
Note:
In cluster mode, if keys in keys map to different hash slots, the command will be split across these slots and executed separately for each. This means the command is atomic only at the slot level. If one or more slot-specific requests fail, the entire call will return the first encountered error, even though some requests may have succeeded while others did not. If this behavior impacts your application logic, consider splitting the request into sub-requests per slot to ensure atomicity.
Parameters:
keys - One or more keys to unlink.
Return value:
Return the number of keys that were unlinked.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key1", "someValue") result1, err := client.Set("key2", "someValue") result2, err := client.Unlink([]string{"key1", "key2", "key3"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: OK OK 2
func (GlideClusterClient) Wait ¶
Wait blocks the current client until all the previous write commands are successfully transferred and acknowledged by at least the specified number of replicas or if the timeout is reached, whichever is earlier
Parameters:
numberOfReplicas - The number of replicas to reach. timeout - The timeout value specified in milliseconds. A value of `0` will block indefinitely.
Return value:
The number of replicas reached by all the writes performed in the context of the current connection.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.Set("key1", "someValue") result, err := client.Wait(2, 1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result < 10)
Output: true
func (GlideClusterClient) XAck ¶
Returns the number of messages that were successfully acknowledged by the consumer group member of a stream. This command should be called on a pending message so that such message does not get processed again.
See valkey.io for details.
Parameters:
key - The key of the stream. group - he consumer group name. ids - Stream entry IDs to acknowledge and purge messages.
Return value:
The number of messages that were successfully acknowledged.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" group := "g12345" consumer := "c12345" streamId, _ := client.XAdd( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, ) client.XGroupCreate(key, group, "0") client.XGroupCreateConsumer(key, group, consumer) client.XReadGroup(group, consumer, map[string]string{key: ">"}) count, err := client.XAck(key, group, []string{streamId.Value()}) // ack the message and remove it from the pending list if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(count)
Output: 1
func (GlideClusterClient) XAdd ¶
Adds an entry to the specified stream stored at `key`. If the `key` doesn't exist, the stream is created.
See valkey.io for details.
Parameters:
key - The key of the stream. values - Field-value pairs to be added to the entry.
Return value:
The id of the added entry.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.XAdd("mystream", [][]string{ {"key1", "value1"}, {"key2", "value2"}, }) if err != nil { fmt.Println("Glide example failed with an error: ", err) } matches, _ := regexp.Match( `^\d{13}-0$`, []byte(result.Value()), ) // matches a number that is 13 digits long followed by "-0" fmt.Println(matches)
Output: true
func (GlideClusterClient) XAddWithOptions ¶
func (client GlideClusterClient) XAddWithOptions( key string, values [][]string, options options.XAddOptions, ) (Result[string], error)
Adds an entry to the specified stream stored at `key`. If the `key` doesn't exist, the stream is created.
See valkey.io for details.
Parameters:
key - The key of the stream. values - Field-value pairs to be added to the entry. options - Stream add options.
Return value:
The id of the added entry.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function options := options.NewXAddOptions(). SetId("1000-50") values := [][]string{ {"key1", "value1"}, {"key2", "value2"}, } result, err := client.XAddWithOptions("mystream", values, *options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result.Value())
Output: 1000-50
func (GlideClusterClient) XAutoClaim ¶
func (client GlideClusterClient) XAutoClaim( key string, group string, consumer string, minIdleTime int64, start string, ) (XAutoClaimResponse, error)
Transfers ownership of pending stream entries that match the specified criteria.
Since:
Valkey 6.2.0 and above.
See valkey.io for more details.
Parameters:
key - The key of the stream. group - The consumer group name. consumer - The group consumer. minIdleTime - The minimum idle time for the message to be claimed. start - Filters the claimed entries to those that have an ID equal or greater than the specified value.
Return value:
An object containing the following elements: - A stream ID to be used as the start argument for the next call to `XAUTOCLAIM`. This ID is equivalent to the next ID in the stream after the entries that were scanned, or "0-0" if the entire stream was scanned. - A map of the claimed entries. - If you are using Valkey 7.0.0 or above, the response will also include an array containing the message IDs that were in the Pending Entries List but no longer exist in the stream. These IDs are deleted from the Pending Entries List.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := uuid.NewString() group := uuid.NewString() consumer := uuid.NewString() client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId("0-1"), ) client.XAddWithOptions( key, [][]string{{"entry2_field1", "entry2_value1"}}, *options.NewXAddOptions().SetId("0-2"), ) client.XReadGroup(group, consumer, map[string]string{key: ">"}) response, err := client.XAutoClaim(key, group, consumer, 0, "0-1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: {0-0 map[0-1:[[entry1_field1 entry1_value1] [entry1_field2 entry1_value2]] 0-2:[[entry2_field1 entry2_value1]]] []}
func (GlideClusterClient) XAutoClaimJustId ¶
func (client GlideClusterClient) XAutoClaimJustId( key string, group string, consumer string, minIdleTime int64, start string, ) (XAutoClaimJustIdResponse, error)
Transfers ownership of pending stream entries that match the specified criteria.
Since:
Valkey 6.2.0 and above.
See valkey.io for more details.
Parameters:
key - The key of the stream. group - The consumer group name. consumer - The group consumer. minIdleTime - The minimum idle time for the message to be claimed. start - Filters the claimed entries to those that have an ID equal or greater than the specified value.
Return value:
An object containing the following elements: - A stream ID to be used as the start argument for the next call to `XAUTOCLAIM`. This ID is equivalent to the next ID in the stream after the entries that were scanned, or "0-0" if the entire stream was scanned. - An array of IDs for the claimed entries. - If you are using Valkey 7.0.0 or above, the response will also include an array containing the message IDs that were in the Pending Entries List but no longer exist in the stream. These IDs are deleted from the Pending Entries List.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := uuid.NewString() group := uuid.NewString() consumer := uuid.NewString() client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId("0-1"), ) client.XAddWithOptions( key, [][]string{{"entry2_field1", "entry2_value1"}}, *options.NewXAddOptions().SetId("0-2"), ) client.XReadGroup(group, consumer, map[string]string{key: ">"}) response, err := client.XAutoClaimJustId(key, group, consumer, 0, "0-0") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: {0-0 [0-1 0-2] []}
func (GlideClusterClient) XAutoClaimJustIdWithOptions ¶
func (client GlideClusterClient) XAutoClaimJustIdWithOptions( key string, group string, consumer string, minIdleTime int64, start string, opts options.XAutoClaimOptions, ) (XAutoClaimJustIdResponse, error)
Transfers ownership of pending stream entries that match the specified criteria.
Since:
Valkey 6.2.0 and above.
See valkey.io for more details.
Parameters:
key - The key of the stream. group - The consumer group name. consumer - The group consumer. minIdleTime - The minimum idle time for the message to be claimed. start - Filters the claimed entries to those that have an ID equal or greater than the specified value. opts - Options detailing how to read the stream.
Return value:
An object containing the following elements: - A stream ID to be used as the start argument for the next call to `XAUTOCLAIM`. This ID is equivalent to the next ID in the stream after the entries that were scanned, or "0-0" if the entire stream was scanned. - An array of IDs for the claimed entries. - If you are using Valkey 7.0.0 or above, the response will also include an array containing the message IDs that were in the Pending Entries List but no longer exist in the stream. These IDs are deleted from the Pending Entries List.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := uuid.NewString() group := uuid.NewString() consumer := uuid.NewString() client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId("0-1"), ) client.XAddWithOptions( key, [][]string{{"entry2_field1", "entry2_value1"}}, *options.NewXAddOptions().SetId("0-2"), ) client.XReadGroup(group, consumer, map[string]string{key: ">"}) options := options.NewXAutoClaimOptions().SetCount(1) response, err := client.XAutoClaimJustIdWithOptions(key, group, consumer, 0, "0-1", *options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: {0-2 [0-1] []}
func (GlideClusterClient) XAutoClaimWithOptions ¶
func (client GlideClusterClient) XAutoClaimWithOptions( key string, group string, consumer string, minIdleTime int64, start string, options options.XAutoClaimOptions, ) (XAutoClaimResponse, error)
Transfers ownership of pending stream entries that match the specified criteria.
Since:
Valkey 6.2.0 and above.
See valkey.io for more details.
Parameters:
key - The key of the stream. group - The consumer group name. consumer - The group consumer. minIdleTime - The minimum idle time for the message to be claimed. start - Filters the claimed entries to those that have an ID equal or greater than the specified value. options - Options detailing how to read the stream.
Return value:
An object containing the following elements: - A stream ID to be used as the start argument for the next call to `XAUTOCLAIM`. This ID is equivalent to the next ID in the stream after the entries that were scanned, or "0-0" if the entire stream was scanned. - A map of the claimed entries. - If you are using Valkey 7.0.0 or above, the response will also include an array containing the message IDs that were in the Pending Entries List but no longer exist in the stream. These IDs are deleted from the Pending Entries List.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := uuid.NewString() group := uuid.NewString() consumer := uuid.NewString() client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId("0-1"), ) client.XAddWithOptions( key, [][]string{{"entry2_field1", "entry2_value1"}}, *options.NewXAddOptions().SetId("0-2"), ) client.XReadGroup(group, consumer, map[string]string{key: ">"}) options := options.NewXAutoClaimOptions().SetCount(1) response, err := client.XAutoClaimWithOptions(key, group, consumer, 0, "0-1", *options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: {0-2 map[0-1:[[entry1_field1 entry1_value1] [entry1_field2 entry1_value2]]] []}
func (GlideClusterClient) XClaim ¶
func (client GlideClusterClient) XClaim( key string, group string, consumer string, minIdleTime int64, ids []string, ) (map[string][][]string, error)
Changes the ownership of a pending message.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The name of the consumer group. consumer - The name of the consumer. minIdleTime - The minimum idle time in milliseconds. ids - The ids of the entries to claim.
Return value:
A `map of message entries with the format `{"entryId": [["entry", "data"], ...], ...}` that were claimed by the consumer.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" streamId := "12345-1" group := "g12345" consumer1 := "c12345-1" consumer2 := "c12345-2" client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer1) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) client.XReadGroup(group, consumer1, map[string]string{key: ">"}) result, err := client.XPendingWithOptions( key, group, *options.NewXPendingOptions("-", "+", 10).SetConsumer(consumer1), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } if len(result) == 0 { fmt.Println("No pending messages") return } response, err := client.XClaim(key, group, consumer2, result[0].IdleTime, []string{result[0].Id}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Printf("Claimed %d message\n", len(response))
Output: Claimed 1 message
func (GlideClusterClient) XClaimJustId ¶
func (client GlideClusterClient) XClaimJustId( key string, group string, consumer string, minIdleTime int64, ids []string, ) ([]string, error)
Changes the ownership of a pending message. This function returns an `array` with only the message/entry IDs, and is equivalent to using `JUSTID` in the Valkey API.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The name of the consumer group. consumer - The name of the consumer. minIdleTime - The minimum idle time in milliseconds. ids - The ids of the entries to claim. options - Stream claim options.
Return value:
An array of the ids of the entries that were claimed by the consumer.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" streamId := "12345-1" group := "g12345" consumer1 := "c12345-1" consumer2 := "c12345-2" client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer1) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) client.XReadGroup(group, consumer1, map[string]string{key: ">"}) result, err := client.XPendingWithOptions( key, group, *options.NewXPendingOptions("-", "+", 10).SetConsumer(consumer1), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } if len(result) == 0 { fmt.Println("No pending messages") return } response, err := client.XClaimJustId(key, group, consumer2, result[0].IdleTime, []string{result[0].Id}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: [12345-1]
func (GlideClusterClient) XClaimJustIdWithOptions ¶
func (client GlideClusterClient) XClaimJustIdWithOptions( key string, group string, consumer string, minIdleTime int64, ids []string, opts options.XClaimOptions, ) ([]string, error)
Changes the ownership of a pending message. This function returns an `array` with only the message/entry IDs, and is equivalent to using `JUSTID` in the Valkey API.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The name of the consumer group. consumer - The name of the consumer. minIdleTime - The minimum idle time in milliseconds. ids - The ids of the entries to claim. options - Stream claim options.
Return value:
An array of the ids of the entries that were claimed by the consumer.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" streamId := "12345-1" group := "g12345" consumer1 := "c12345-1" consumer2 := "c12345-2" client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer1) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) client.XReadGroup(group, consumer1, map[string]string{key: ">"}) result, err := client.XPendingWithOptions( key, group, *options.NewXPendingOptions("-", "+", 10).SetConsumer(consumer1), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } if len(result) == 0 { fmt.Println("No pending messages") return } opts := options.NewXClaimOptions().SetRetryCount(3) response, err := client.XClaimJustIdWithOptions(key, group, consumer2, result[0].IdleTime, []string{result[0].Id}, *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: [12345-1]
func (GlideClusterClient) XClaimWithOptions ¶
func (client GlideClusterClient) XClaimWithOptions( key string, group string, consumer string, minIdleTime int64, ids []string, opts options.XClaimOptions, ) (map[string][][]string, error)
Changes the ownership of a pending message.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The name of the consumer group. consumer - The name of the consumer. minIdleTime - The minimum idle time in milliseconds. ids - The ids of the entries to claim. options - Stream claim options.
Return value:
A `map` of message entries with the format `{"entryId": [["entry", "data"], ...], ...}` that were claimed by the consumer.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" streamId := "12345-1" group := "g12345" consumer1 := "c12345-1" consumer2 := "c12345-2" client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer1) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) client.XReadGroup(group, consumer1, map[string]string{key: ">"}) result, err := client.XPendingWithOptions( key, group, *options.NewXPendingOptions("-", "+", 10).SetConsumer(consumer1), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } if len(result) == 0 { fmt.Println("No pending messages") return } opts := options.NewXClaimOptions().SetRetryCount(3) response, err := client.XClaimWithOptions(key, group, consumer2, result[0].IdleTime, []string{result[0].Id}, *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Printf("Claimed %d message\n", len(response))
Output: Claimed 1 message
func (GlideClusterClient) XDel ¶
Removes the specified entries by id from a stream, and returns the number of entries deleted.
See valkey.io for details.
Parameters:
key - The key of the stream. ids - An array of entry ids.
Return value:
The number of entries removed from the stream. This number may be less than the number of entries in `ids`, if the specified `ids` don't exist in the stream.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" client.XAddWithOptions( key, [][]string{{"field1", "value1"}, {"field2", "value2"}}, *options.NewXAddOptions().SetId("0-1"), ) count, err := client.XDel(key, []string{"0-1", "0-2", "0-3"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(count)
Output: 1
func (GlideClusterClient) XGroupCreate ¶
Creates a new consumer group uniquely identified by `group` for the stream stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The newly created consumer group name. id - Stream entry ID that specifies the last delivered entry in the stream from the new group’s perspective. The special ID `"$"` can be used to specify the last entry in the stream.
Return value:
`"OK"`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" streamId := "12345-1" group := "g12345" client.XAddWithOptions( key, [][]string{{"field1", "value1"}, {"field2", "value2"}}, *options.NewXAddOptions().SetId(streamId), ) // This will create the stream if it does not exist response, err := client.XGroupCreate(key, group, "0") // create the group (no MKSTREAM needed) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: OK
func (GlideClusterClient) XGroupCreateConsumer ¶
func (client GlideClusterClient) XGroupCreateConsumer( key string, group string, consumer string, ) (bool, error)
XGroupCreateConsumer creates a consumer named `consumer` in the consumer group `group` for the stream stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The consumer group name. consumer - The newly created consumer.
Return value:
Returns `true` if the consumer is created. Otherwise, returns `false`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" group := "g12345" consumer := "c12345" opts := options.NewXGroupCreateOptions().SetMakeStream() client.XGroupCreateWithOptions(key, group, "0", *opts) // create the group (no MKSTREAM needed) success, err := client.XGroupCreateConsumer(key, group, consumer) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(success)
Output: true
func (GlideClusterClient) XGroupCreateWithOptions ¶
func (client GlideClusterClient) XGroupCreateWithOptions( key string, group string, id string, opts options.XGroupCreateOptions, ) (string, error)
Creates a new consumer group uniquely identified by `group` for the stream stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The newly created consumer group name. id - Stream entry ID that specifies the last delivered entry in the stream from the new group's perspective. The special ID `"$"` can be used to specify the last entry in the stream. opts - The options for the command. See [options.XGroupCreateOptions] for details.
Return value:
`"OK"`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" group := "g12345" opts := options.NewXGroupCreateOptions().SetMakeStream() response, err := client.XGroupCreateWithOptions(key, group, "0", *opts) // create the group (no MKSTREAM needed) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: OK
func (GlideClusterClient) XGroupDelConsumer ¶
func (client GlideClusterClient) XGroupDelConsumer( key string, group string, consumer string, ) (int64, error)
XGroupDelConsumer deletes a consumer named `consumer` in the consumer group `group`.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The consumer group name. consumer - The consumer to delete.
Return value:
The number of pending messages the `consumer` had before it was deleted.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" group := "g12345" consumer := "c12345" streamId := "12345-1" client.XAddWithOptions( key, [][]string{{"field1", "value1"}, {"field2", "value2"}}, *options.NewXAddOptions().SetId(streamId), ) client.XGroupCreate(key, group, "0") client.XGroupCreateConsumer(key, group, consumer) client.XReadGroup(group, consumer, map[string]string{key: ">"}) count, err := client.XGroupDelConsumer(key, group, consumer) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println("Consumer deleted. Messages pending:", count)
Output: Consumer deleted. Messages pending: 1
func (GlideClusterClient) XGroupDestroy ¶
Destroys the consumer group `group` for the stream stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The consumer group name to delete.
Return value:
`true` if the consumer group is destroyed. Otherwise, `false`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" group := "g12345" opts := options.NewXGroupCreateOptions().SetMakeStream() client.XGroupCreateWithOptions(key, group, "0", *opts) // create the group (no MKSTREAM needed) success, err := client.XGroupDestroy(key, group) // destroy the group if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(success)
Output: true
func (GlideClusterClient) XGroupSetId ¶
Sets the last delivered ID for a consumer group.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The consumer group name. id - The stream entry ID that should be set as the last delivered ID for the consumer group.
Return value:
`"OK"`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" streamId := "12345-1" group := "g12345" consumer := "c12345" client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) client.XReadGroup(group, consumer, map[string]string{key: ">"}) client.XAck(key, group, []string{streamId}) // ack the message and remove it from the pending list client.XGroupSetId(key, group, "0-0") // reset the last acknowledged message to 0-0 client.XReadGroup(group, consumer, map[string]string{key: ">"}) // read the group again summary, err := client.XPending(key, group) // get the pending messages, which should include the entry we previously acked if err != nil { fmt.Println("Glide example failed with an error: ", err) } jsonSummary, _ := json.Marshal(summary) fmt.Println(string(jsonSummary))
Output: {"NumOfMessages":1,"StartId":{},"EndId":{},"ConsumerMessages":[{"ConsumerName":"c12345","MessageCount":1}]}
func (GlideClusterClient) XGroupSetIdWithOptions ¶
func (client GlideClusterClient) XGroupSetIdWithOptions( key string, group string, id string, opts options.XGroupSetIdOptions, ) (string, error)
Sets the last delivered ID for a consumer group.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The consumer group name. id - The stream entry ID that should be set as the last delivered ID for the consumer group. opts - The options for the command. See [options.XGroupSetIdOptions] for details.
Return value:
`"OK"`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" streamId1 := "12345-1" streamId2 := "12345-2" group := "g12345" consumer := "c12345" client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"field1", "value1"}, {"field2", "value2"}}, *options.NewXAddOptions().SetId(streamId1), ) client.XAddWithOptions( key, [][]string{{"field3", "value3"}, {"field4", "value4"}}, *options.NewXAddOptions().SetId(streamId2), ) client.XReadGroup(group, consumer, map[string]string{key: ">"}) client.XAck(key, group, []string{streamId1, streamId2}) // ack the message and remove it from the pending list opts := options.NewXGroupSetIdOptionsOptions().SetEntriesRead(1) client.XGroupSetIdWithOptions(key, group, "0-0", *opts) // reset the last acknowledged message to 0-0 client.XReadGroup(group, consumer, map[string]string{key: ">"}) // read the group again summary, err := client.XPending(key, group) // get the pending messages, which should include the entry we previously acked if err != nil { fmt.Println("Glide example failed with an error: ", err) } jsonSummary, _ := json.Marshal(summary) fmt.Println(string(jsonSummary))
Output: {"NumOfMessages":2,"StartId":{},"EndId":{},"ConsumerMessages":[{"ConsumerName":"c12345","MessageCount":2}]}
func (GlideClusterClient) XLen ¶
Returns the number of entries in the stream stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the stream.
Return value:
The number of entries in the stream. If `key` does not exist, return 0.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.XAdd("mystream", [][]string{{"field1", "foo4"}, {"field2", "bar4"}}) count, err := client.XLen("mystream") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(count)
Output: 1
func (GlideClusterClient) XPending ¶
func (client GlideClusterClient) XPending(key string, group string) (XPendingSummary, error)
Returns stream message summary information for pending messages matching a stream and group.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The consumer group name.
Return value:
An XPendingSummary struct that includes a summary with the following fields:
NumOfMessages - The total number of pending messages for this consumer group. StartId - The smallest ID among the pending messages or nil if no pending messages exist. EndId - The greatest ID among the pending messages or nil if no pending messages exists. GroupConsumers - An array of ConsumerPendingMessages with the following fields: ConsumerName - The name of the consumer. MessageCount - The number of pending messages for this consumer.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" streamId := "12345-1" group := "g12345" consumer := "c12345" client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) client.XReadGroup(group, consumer, map[string]string{key: ">"}) summary, err := client.XPending(key, group) if err != nil { fmt.Println("Glide example failed with an error: ", err) } jsonSummary, _ := json.Marshal(summary) fmt.Println(string(jsonSummary))
Output: {"NumOfMessages":1,"StartId":{},"EndId":{},"ConsumerMessages":[{"ConsumerName":"c12345","MessageCount":1}]}
func (GlideClusterClient) XPendingWithOptions ¶
func (client GlideClusterClient) XPendingWithOptions( key string, group string, opts options.XPendingOptions, ) ([]XPendingDetail, error)
Returns stream message summary information for pending messages matching a given range of IDs.
See valkey.io for details.
Parameters:
key - The key of the stream. group - The consumer group name. opts - The options for the command. See [options.XPendingOptions] for details.
Return value:
A slice of XPendingDetail structs, where each detail struct includes the following fields:
Id - The ID of the pending message. ConsumerName - The name of the consumer that fetched the message and has still to acknowledge it. IdleTime - The time in milliseconds since the last time the message was delivered to the consumer. DeliveryCount - The number of times this message was delivered.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" streamId := "12345-1" group := "g12345" consumer := "c12345" client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) client.XReadGroup(group, consumer, map[string]string{key: ">"}) details, err := client.XPendingWithOptions( key, group, *options.NewXPendingOptions("-", "+", 10).SetConsumer(consumer), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } jsonDetails, _ := json.Marshal(details) // Since IdleTime can vary, check that output has all fields fields := []string{"\"Id\"", "\"ConsumerName\"", "\"IdleTime\"", "\"DeliveryCount\""} hasFields := true jsonStr := string(jsonDetails) for _, field := range fields { hasFields = strings.Contains(jsonStr, field) if !hasFields { break } } fmt.Println(hasFields)
Output: true
func (GlideClusterClient) XRange ¶
func (client GlideClusterClient) XRange( key string, start options.StreamBoundary, end options.StreamBoundary, ) ([]XRangeResponse, error)
Returns stream entries matching a given range of IDs.
See valkey.io for details.
Parameters:
key - The key of the stream. start - The start position. Use `options.NewStreamBoundary()` to specify a stream entry ID and its inclusive/exclusive status. Use `options.NewInfiniteStreamBoundary()` to specify an infinite stream boundary. end - The end position. Use `options.NewStreamBoundary()` to specify a stream entry ID and its inclusive/exclusive status. Use `options.NewInfiniteStreamBoundary()` to specify an infinite stream boundary.
Return value:
An `array` of stream entry data, where entry data is an array of pairings with format `[[field, entry], [field, entry], ...]`. Returns `nil` if `count` is non-positive. fmt.Println(res) // map[key:[["field1", "entry1"], ["field2", "entry2"]]] fmt.Println(res) // map[key:[["field1", "entry1"]]
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" client.XAdd(key, [][]string{{"field1", "value1"}}) client.XAdd(key, [][]string{{"field2", "value2"}}) response, err := client.XRange(key, options.NewInfiniteStreamBoundary(options.NegativeInfinity), options.NewInfiniteStreamBoundary(options.PositiveInfinity)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(len(response))
Output: 2
func (GlideClusterClient) XRangeWithOptions ¶
func (client GlideClusterClient) XRangeWithOptions( key string, start options.StreamBoundary, end options.StreamBoundary, opts options.XRangeOptions, ) ([]XRangeResponse, error)
Returns stream entries matching a given range of IDs.
See valkey.io for details.
Parameters:
key - The key of the stream. start - The start position. Use `options.NewStreamBoundary()` to specify a stream entry ID and its inclusive/exclusive status. Use `options.NewInfiniteStreamBoundary()` to specify an infinite stream boundary. end - The end position. Use `options.NewStreamBoundary()` to specify a stream entry ID and its inclusive/exclusive status. Use `options.NewInfiniteStreamBoundary()` to specify an infinite stream boundary. opts - Stream range options.
Return value:
An `array` of stream entry data, where entry data is an array of pairings with format `[[field, entry], [field, entry], ...]`. Returns `nil` if `count` is non-positive.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" streamId1, _ := client.XAdd(key, [][]string{{"field1", "value1"}}) streamId2, _ := client.XAdd(key, [][]string{{"field2", "value2"}}) response, err := client.XRangeWithOptions(key, options.NewStreamBoundary(streamId1.Value(), true), options.NewStreamBoundary(streamId2.Value(), true), *options.NewXRangeOptions().SetCount(1)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(len(response))
Output: 1
func (GlideClusterClient) XRead ¶
func (client GlideClusterClient) XRead(keysAndIds map[string]string) (map[string]map[string][][]string, error)
Reads entries from the given streams.
Note:
When in cluster mode, all keys in `keysAndIds` must map to the same hash slot.
See valkey.io for details.
Parameters:
keysAndIds - A map of keys and entry IDs to read from.
Return value:
A `map[string]map[string][][]string` of stream keys to a map of stream entry IDs mapped to an array entries or `nil` if a key does not exist or does not contain requiested entries.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" streamId := "12345-1" client.XAddWithOptions( key, [][]string{{"field1", "value1"}, {"field2", "value2"}}, *options.NewXAddOptions().SetId(streamId), ) response, err := client.XRead(map[string]string{key: "0-0"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: map[12345:map[12345-1:[[field1 value1] [field2 value2]]]]
func (GlideClusterClient) XReadGroup ¶
func (client GlideClusterClient) XReadGroup( group string, consumer string, keysAndIds map[string]string, ) (map[string]map[string][][]string, error)
Reads entries from the given streams owned by a consumer group.
Note:
When in cluster mode, all keys in `keysAndIds` must map to the same hash slot.
See valkey.io for details.
Parameters:
group - The consumer group name. consumer - The group consumer. keysAndIds - A map of keys and entry IDs to read from.
Return value:
A `map[string]map[string][][]string` of stream keys to a map of stream entry IDs mapped to an array entries or `nil` if a key does not exist or does not contain requested entries.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" streamId := "12345-1" group := uuid.NewString() consumer := uuid.NewString() client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) response, err := client.XReadGroup(group, consumer, map[string]string{key: "0"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: map[12345:map[]]
func (GlideClusterClient) XReadGroupWithOptions ¶
func (client GlideClusterClient) XReadGroupWithOptions( group string, consumer string, keysAndIds map[string]string, opts options.XReadGroupOptions, ) (map[string]map[string][][]string, error)
Reads entries from the given streams owned by a consumer group.
Note:
When in cluster mode, all keys in `keysAndIds` must map to the same hash slot.
See valkey.io for details.
Parameters:
group - The consumer group name. consumer - The group consumer. keysAndIds - A map of keys and entry IDs to read from. opts - Options detailing how to read the stream.
Return value:
A `map[string]map[string][][]string` of stream keys to a map of stream entry IDs mapped to an array entries or `nil` if a key does not exist or does not contain requiested entries.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" streamId := "12345-1" group := uuid.NewString() consumer := uuid.NewString() client.XGroupCreateWithOptions(key, group, "0", *options.NewXGroupCreateOptions().SetMakeStream()) client.XGroupCreateConsumer(key, group, consumer) client.XAddWithOptions( key, [][]string{{"entry1_field1", "entry1_value1"}, {"entry1_field2", "entry1_value2"}}, *options.NewXAddOptions().SetId(streamId), ) options := options.NewXReadGroupOptions().SetNoAck() response, err := client.XReadGroupWithOptions(group, consumer, map[string]string{key: ">"}, *options) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: map[12345:map[12345-1:[[entry1_field1 entry1_value1] [entry1_field2 entry1_value2]]]]
func (GlideClusterClient) XReadWithOptions ¶
func (client GlideClusterClient) XReadWithOptions( keysAndIds map[string]string, opts options.XReadOptions, ) (map[string]map[string][][]string, error)
Reads entries from the given streams.
Note:
When in cluster mode, all keys in `keysAndIds` must map to the same hash slot.
See valkey.io for details.
Parameters:
keysAndIds - A map of keys and entry IDs to read from. opts - Options detailing how to read the stream.
Return value:
A `map[string]map[string][][]string` of stream keys to a map of stream entry IDs mapped to an array entries or `nil` if a key does not exist or does not contain requiested entries.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" streambase := 1 genStreamId := func(key string, base int, offset int) string { return fmt.Sprintf("%s-%d", key, base+offset) } // helper function to generate stream ids client.XAddWithOptions( key, [][]string{{"field1", "value1"}, {"field2", "value2"}}, *options.NewXAddOptions().SetId(genStreamId(key, streambase, 0)), ) client.XAddWithOptions( key, [][]string{{"field3", "value3"}, {"field4", "value4"}}, *options.NewXAddOptions().SetId(genStreamId(key, streambase, 1)), ) response, err := client.XReadWithOptions( map[string]string{key: genStreamId(key, streambase, 0)}, *options.NewXReadOptions().SetCount(1), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: map[12345:map[12345-2:[[field3 value3] [field4 value4]]]]
func (GlideClusterClient) XRevRange ¶
func (client GlideClusterClient) XRevRange( key string, start options.StreamBoundary, end options.StreamBoundary, ) ([]XRangeResponse, error)
Returns stream entries matching a given range of IDs in reverse order. Equivalent to `XRange` but returns entries in reverse order.
See valkey.io for details.
Parameters:
key - The key of the stream. start - The start position. Use `options.NewStreamBoundary()` to specify a stream entry ID and its inclusive/exclusive status. Use `options.NewInfiniteStreamBoundary()` to specify an infinite stream boundary. end - The end position. Use `options.NewStreamBoundary()` to specify a stream entry ID and its inclusive/exclusive status. Use `options.NewInfiniteStreamBoundary()` to specify an infinite stream boundary.
Return value:
An `array` of stream entry data, where entry data is an array of pairings with format `[[field, entry], [field, entry], ...]`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" streamId1 := "12345-1" streamId2 := "12345-2" client.XAddWithOptions(key, [][]string{{"field1", "value1"}}, *options.NewXAddOptions().SetId(streamId1)) client.XAddWithOptions(key, [][]string{{"field2", "value2"}}, *options.NewXAddOptions().SetId(streamId2)) response, err := client.XRevRange(key, options.NewStreamBoundary(streamId2, true), options.NewStreamBoundary(streamId1, true)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: [{12345-2 [[field2 value2]]} {12345-1 [[field1 value1]]}]
func (GlideClusterClient) XRevRangeWithOptions ¶
func (client GlideClusterClient) XRevRangeWithOptions( key string, start options.StreamBoundary, end options.StreamBoundary, opts options.XRangeOptions, ) ([]XRangeResponse, error)
Returns stream entries matching a given range of IDs in reverse order. Equivalent to `XRange` but returns entries in reverse order.
See valkey.io for details.
Parameters:
key - The key of the stream. start - The start position. Use `options.NewStreamBoundary()` to specify a stream entry ID and its inclusive/exclusive status. Use `options.NewInfiniteStreamBoundary()` to specify an infinite stream boundary. end - The end position. Use `options.NewStreamBoundary()` to specify a stream entry ID and its inclusive/exclusive status. Use `options.NewInfiniteStreamBoundary()` to specify an infinite stream boundary. opts - Stream range options.
Return value:
An `array` of stream entry data, where entry data is an array of pairings with format `[[field, entry], [field, entry], ...]`. Returns `nil` if `count` is non-positive.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function key := "12345" streamId1 := "12345-1" streamId2 := "12345-2" client.XAddWithOptions(key, [][]string{{"field1", "value1"}}, *options.NewXAddOptions().SetId(streamId1)) client.XAddWithOptions(key, [][]string{{"field2", "value2"}}, *options.NewXAddOptions().SetId(streamId2)) response, err := client.XRevRangeWithOptions(key, options.NewStreamBoundary(streamId2, true), options.NewStreamBoundary(streamId1, true), *options.NewXRangeOptions().SetCount(2)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(response)
Output: [{12345-2 [[field2 value2]]} {12345-1 [[field1 value1]]}]
func (GlideClusterClient) XTrim ¶
func (client GlideClusterClient) XTrim(key string, options options.XTrimOptions) (int64, error)
Trims the stream by evicting older entries.
See valkey.io for details.
Parameters:
key - The key of the stream. options - Stream trim options
Return value:
The number of entries deleted from the stream.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.XAdd("mystream", [][]string{{"field1", "foo4"}, {"field2", "bar4"}}) client.XAdd("mystream", [][]string{{"field3", "foo4"}, {"field4", "bar4"}}) count, err := client.XTrim("mystream", *options.NewXTrimOptionsWithMaxLen(0).SetExactTrimming()) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(count)
Output: 2
func (GlideClusterClient) ZAdd ¶
func (client GlideClusterClient) ZAdd( key string, membersScoreMap map[string]float64, ) (int64, error)
Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
See valkey.io for details.
Parameters:
key - The key of the set. membersScoreMap - A map of members to their scores.
Return value:
The number of members added to the set.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 3
func (GlideClusterClient) ZAddIncr ¶
func (client GlideClusterClient) ZAddIncr( key string, member string, increment float64, ) (Result[float64], error)
Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
See valkey.io for details.
Parameters:
key - The key of the set. member - The member to add to. increment - The increment to add to the member's score.
Return value:
Result[float64] - The new score of the member.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAddIncr("key1", "one", 1.0) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: {1 false}
func (GlideClusterClient) ZAddIncrWithOptions ¶
func (client GlideClusterClient) ZAddIncrWithOptions( key string, member string, increment float64, opts options.ZAddOptions, ) (Result[float64], error)
Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
See valkey.io for details.
Parameters:
key - The key of the set. member - The member to add to. increment - The increment to add to the member's score. opts - The options for the command. See [ZAddOptions] for details.
Return value:
The new score of the member. If there was a conflict with the options, the operation aborts and `nil` is returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function opts, err := options.NewZAddOptions().SetChanged(true) // should return an error result, err := client.ZAddIncrWithOptions("key1", "one", 1.0, *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: Glide example failed with an error: incr cannot be set when changed is true {0 true}
func (GlideClusterClient) ZAddWithOptions ¶
func (client GlideClusterClient) ZAddWithOptions( key string, membersScoreMap map[string]float64, opts options.ZAddOptions, ) (int64, error)
Adds one or more members to a sorted set, or updates their scores. Creates the key if it doesn't exist.
See valkey.io for details.
Parameters:
key - The key of the set. membersScoreMap - A map of members to their scores. opts - The options for the command. See [ZAddOptions] for details.
Return value:
The number of members added to the set. If `CHANGED` is set, the number of members that were updated.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function opts, err := options.NewZAddOptions().SetChanged(true) result, err := client.ZAddWithOptions( "key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}, *opts, ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 3
func (GlideClusterClient) ZCard ¶
Returns the cardinality (number of elements) of the sorted set stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the set.
Return value:
The number of elements in the sorted set. If `key` does not exist, it is treated as an empty sorted set, and this command returns `0`. If `key` holds a value that is not a sorted set, an error is returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) result1, err := client.ZCard("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 3
func (GlideClusterClient) ZCount ¶
func (client GlideClusterClient) ZCount(key string, rangeOptions options.ZCountRange) (int64, error)
Returns the number of members in the sorted set stored at `key` with scores between `min` and `max` score.
See valkey.io for details.
Parameters:
key - The key of the set. rangeOptions - Contains `min` and `max` score. `min` contains the minimum score to count from. `max` contains the maximum score to count up to. Can be positive/negative infinity, or specific score and inclusivity.
Return value:
The number of members in the specified score range.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function zCountRange := options.NewZCountRange( options.NewInclusiveScoreBoundary(2.0), options.NewInfiniteScoreBoundary(options.PositiveInfinity), ) result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0, "four": 4.0}) result1, err := client.ZCount("key1", *zCountRange) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 3
func (GlideClusterClient) ZDiff ¶
Returns the difference between the first sorted set and all the successive sorted sets. To get the elements with their scores, see `ZDiffWithScores`
Note:
When in cluster mode, all `keys` must map to the same hash slot.
Available for Valkey 6.2 and above.
See valkey.io for details.
Parameters:
keys - The keys of the sorted sets.
Return value:
An array of elements representing the difference between the sorted sets. If the first `key` does not exist, it is treated as an empty sorted set, and the command returns an empty array.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.ZAdd("{key}1", map[string]float64{"a": 1.0, "b": 2.5, "c": 3.0, "d": 4.0}) client.ZAdd("{key}2", map[string]float64{"b": 1.0, "c": 2.5, "d": 3.0, "e": 4.0}) result, err := client.ZDiff([]string{"{key}1", "{key}2"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: [a]
func (GlideClusterClient) ZDiffStore ¶
Calculates the difference between the first sorted set and all the successive sorted sets at `keys` and stores the difference as a sorted set to `destination`, overwriting it if it already exists. Non-existent keys are treated as empty sets.
Note:
When in cluster mode, `destination` and all `keys` must map to the same hash slot.
Available for Valkey 6.2 and above.
See valkey.io for details.
Parameters:
destination - The key for the resulting sorted set. keys - The keys of the sorted sets to compare.
Return value:
The number of members in the resulting sorted set stored at `destination`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.ZAdd("{key}1", map[string]float64{"a": 1.0, "b": 2.5, "c": 3.0, "d": 4.0}) client.ZAdd("{key}2", map[string]float64{"b": 1.0, "c": 2.5, "d": 3.0, "e": 4.0}) result, err := client.ZDiffStore("{key}dest", []string{"{key}1", "{key}2"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 1
func (GlideClusterClient) ZDiffWithScores ¶
Returns the difference between the first sorted set and all the successive sorted sets. When in cluster mode, all `keys` must map to the same hash slot. Available for Valkey 6.2 and above.
See valkey.io for details.
Parameters:
keys - The keys of the sorted sets.
Return value:
A `Map` of elements and their scores representing the difference between the sorted sets. If the first `key` does not exist, it is treated as an empty sorted set, and the command returns an empty `Map`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.ZAdd("{key}1", map[string]float64{"a": 1.0, "b": 2.5, "c": 3.0, "d": 4.0}) client.ZAdd("{key}2", map[string]float64{"b": 1.0, "c": 2.5, "d": 3.0, "e": 4.0}) result, err := client.ZDiffWithScores([]string{"{key}1", "{key}2"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: map[a:1]
func (GlideClusterClient) ZIncrBy ¶
func (client GlideClusterClient) ZIncrBy(key string, increment float64, member string) (float64, error)
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. If key does not exist, a new sorted set with the specified member as its sole member is created.
See valkey.io for details.
Parameters:
key - The key of the sorted set. increment - The score increment. member - A member of the sorted set.
Return value:
The new score of member.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) result1, err := client.ZIncrBy("key1", 3.0, "two") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 5
func (GlideClusterClient) ZInter ¶
Returns the intersection of members from sorted sets specified by the given `keys`. To get the elements with their scores, see [ZInterWithScores].
Note:
When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
keys - The keys of the sorted sets, see - [options.KeyArray].
Return value:
The resulting sorted set from the intersection.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.ZAdd("{key}1", map[string]float64{"a": 1.0, "b": 2.5, "c": 3.0, "d": 4.0}) client.ZAdd("{key}2", map[string]float64{"b": 1.0, "c": 2.5, "d": 3.0, "e": 4.0}) result, err := client.ZInter(options.KeyArray{ Keys: []string{"{key}1", "{key}2"}, }) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: [b c d]
func (GlideClusterClient) ZInterStore ¶
func (client GlideClusterClient) ZInterStore(destination string, keysOrWeightedKeys options.KeysOrWeightedKeys) (int64, error)
Computes the intersection of sorted sets given by the specified `keysOrWeightedKeys` and stores the result in `destination`. If `destination` already exists, it is overwritten. Otherwise, a new sorted set will be created.
Note:
When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
destination - The destination key for the result. keysOrWeightedKeys - The keys or weighted keys of the sorted sets, see - [options.KeysOrWeightedKeys]. - Use `options.NewKeyArray()` for keys only. - Use `options.NewWeightedKeys()` for weighted keys with score multipliers.
Return value:
The number of elements in the resulting sorted set stored at <code>destination</code>.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.ZAdd("{key}1", map[string]float64{"a": 1.0, "b": 2.5, "c": 3.0, "d": 4.0}) client.ZAdd("{key}2", map[string]float64{"b": 1.0, "c": 2.5, "d": 3.0, "e": 4.0}) result, err := client.ZInterStore("{key}dest", options.KeyArray{ Keys: []string{"{key}1", "{key}2"}, }) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 3
func (GlideClusterClient) ZInterStoreWithOptions ¶
func (client GlideClusterClient) ZInterStoreWithOptions( destination string, keysOrWeightedKeys options.KeysOrWeightedKeys, zInterOptions options.ZInterOptions, ) (int64, error)
Computes the intersection of sorted sets given by the specified `keysOrWeightedKeys` and stores the result in `destination`. If `destination` already exists, it is overwritten. Otherwise, a new sorted set will be created.
Note:
When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
destination - The destination key for the result. keysOrWeightedKeys - The keys or weighted keys of the sorted sets, see - [options.KeysOrWeightedKeys]. - Use `options.NewKeyArray()` for keys only. - Use `options.NewWeightedKeys()` for weighted keys with score multipliers. options - The options for the ZInterStore command, see - [options.ZInterOptions]. Optional `aggregate` option specifies the aggregation strategy to apply when combining the scores of elements.
Return value:
The number of elements in the resulting sorted set stored at <code>destination</code>.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.ZAdd("{key}1", map[string]float64{"a": 1.0, "b": 2.5, "c": 3.0, "d": 4.0}) client.ZAdd("{key}2", map[string]float64{"b": 1.0, "c": 2.5, "d": 3.0, "e": 4.0}) result, err := client.ZInterStoreWithOptions( "{key}dest", options.KeyArray{ Keys: []string{"{key}1", "{key}2"}, }, *options.NewZInterOptions().SetAggregate(options.AggregateSum), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: 3
func (GlideClusterClient) ZInterWithScores ¶
func (client GlideClusterClient) ZInterWithScores( keysOrWeightedKeys options.KeysOrWeightedKeys, zInterOptions options.ZInterOptions, ) (map[string]float64, error)
Returns the intersection of members and their scores from sorted sets specified by the given `keysOrWeightedKeys`.
Note:
When in cluster mode, all keys must map to the same hash slot.
See valkey.io for details.
Parameters:
keysOrWeightedKeys - The keys or weighted keys of the sorted sets, see - [options.KeysOrWeightedKeys]. - Use `options.NewKeyArray()` for keys only. - Use `options.NewWeightedKeys()` for weighted keys with score multipliers. options - The options for the ZInter command, see - [options.ZInterOptions]. Optional `aggregate` option specifies the aggregation strategy to apply when combining the scores of elements.
Return value:
A map of members to their scores.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.ZAdd("{key}1", map[string]float64{"a": 1.0, "b": 2.5, "c": 3.0, "d": 4.0}) client.ZAdd("{key}2", map[string]float64{"b": 1.0, "c": 2.5, "d": 3.0, "e": 4.0}) result, err := client.ZInterWithScores( options.KeyArray{ Keys: []string{"{key}1", "{key}2"}, }, *options.NewZInterOptions().SetAggregate(options.AggregateSum), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result)
Output: map[b:3.5 c:5.5 d:7]
func (GlideClusterClient) ZMScore ¶
Returns the scores associated with the specified `members` in the sorted set stored at `key`.
Since:
Valkey 6.2.0 and above.
Parameters:
key - The key of the sorted set. members - A list of members in the sorted set.
Return value:
An array of scores corresponding to `members`. If a member does not exist in the sorted set, the corresponding value in the list will be `nil`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.5, "c": 3.0, "d": 4.0}) result, err := client.ZMScore("key1", []string{"c", "b", "e"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } // If the key does not exist, an empty string is returned fmt.Println(result)
Output: [{3 false} {2.5 false} {0 true}]
func (GlideClusterClient) ZPopMax ¶
Removes and returns the member with the highest score from the sorted set stored at the specified `key`.
see valkey.io for details.
Parameters:
key - The key of the sorted set.
Return value:
A map containing the removed member and its corresponding score. If `key` doesn't exist, it will be treated as an empty sorted set and the command returns an empty map.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) result1, err := client.ZPopMax("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 map[three:3]
func (GlideClusterClient) ZPopMaxWithOptions ¶
func (client GlideClusterClient) ZPopMaxWithOptions(key string, options options.ZPopOptions) (map[string]float64, error)
Removes and returns up to `count` members with the highest scores from the sorted set stored at the specified `key`.
see valkey.io for details.
Parameters:
key - The key of the sorted set. count - The number of members to remove.
Return value:
A map containing the removed members and their corresponding scores. If `key` doesn't exist, it will be treated as an empty sorted set and the command returns an empty map.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) opts := options.NewZPopOptions().SetCount(2) result1, err := client.ZPopMaxWithOptions("key1", *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 map[three:3 two:2]
func (GlideClusterClient) ZPopMin ¶
Removes and returns the member with the lowest score from the sorted set stored at the specified `key`.
see valkey.io for details.
Parameters:
key - The key of the sorted set.
Return value:
A map containing the removed member and its corresponding score. If `key` doesn't exist, it will be treated as an empty sorted set and the command returns an empty map.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) result1, err := client.ZPopMin("key1") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 map[one:1]
func (GlideClusterClient) ZPopMinWithOptions ¶
func (client GlideClusterClient) ZPopMinWithOptions(key string, options options.ZPopOptions) (map[string]float64, error)
Removes and returns up to `count` members with the lowest scores from the sorted set stored at the specified `key`.
see valkey.io for details.
Parameters:
key - The key of the sorted set. count - The number of members to remove.
Return value:
A map containing the removed members and their corresponding scores. If `key` doesn't exist, it will be treated as an empty sorted set and the command returns an empty map.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) opts := options.NewZPopOptions().SetCount(2) result1, err := client.ZPopMinWithOptions("key1", *opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 map[one:1 two:2]
func (GlideClusterClient) ZRandMember ¶
Returns a random member from the sorted set stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the sorted set.
Return value:
A string representing a random member from the sorted set. If the sorted set does not exist or is empty, the response will be `nil`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) result, err := client.ZRandMember("key2") if err != nil { fmt.Println("Glide example failed with an error: ", err) } // If the key does not exist, an empty string is returned fmt.Println(result.Value() == "")
Output: true
func (GlideClusterClient) ZRandMemberWithCount ¶
Returns a random member from the sorted set stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the sorted set. count - The number of field names to return. If `count` is positive, returns unique elements. If negative, allows for duplicates.
Return value:
An array of members from the sorted set. If the sorted set does not exist or is empty, the response will be an empty array.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) result, err := client.ZRandMemberWithCount("key1", 4) if err != nil { fmt.Println("Glide example failed with an error: ", err) } // If the key does not exist, an empty string is returned fmt.Println(result)
Output: [d c b a]
func (GlideClusterClient) ZRandMemberWithCountWithScores ¶
func (client GlideClusterClient) ZRandMemberWithCountWithScores(key string, count int64) ([]MemberAndScore, error)
Returns a random member from the sorted set stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the sorted set. count - The number of field names to return. If `count` is positive, returns unique elements. If negative, allows for duplicates.
Return value:
An array of `MemberAndScore` objects, which store member names and their respective scores. If the sorted set does not exist or is empty, the response will be an empty array.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) result, err := client.ZRandMemberWithCountWithScores("key1", 4) if err != nil { fmt.Println("Glide example failed with an error: ", err) } // If the key does not exist, an empty string is returned fmt.Println(result)
Output: [{d 4} {c 3} {b 2} {a 1}]
func (GlideClusterClient) ZRange ¶
func (client GlideClusterClient) ZRange(key string, rangeQuery options.ZRangeQuery) ([]string, error)
Returns 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.
To get the elements with their scores, see [ZRangeWithScores].
See valkey.io for more details.
Parameters:
key - The key of the sorted set. rangeQuery - The range query object representing the type of range query to perform. - For range queries by index (rank), use [RangeByIndex]. - For range queries by lexicographical order, use [RangeByLex]. - For range queries by score, use [RangeByScore].
Return value:
An array of elements within the specified range. If `key` does not exist, it is treated as an empty sorted set, and the command returns an empty array.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) result1, err := client.ZRange("key1", options.NewRangeByIndexQuery(0, -1)) // Ascending order // Retrieve members within a score range in descending order query := options.NewRangeByScoreQuery( options.NewScoreBoundary(3, false), options.NewInfiniteScoreBoundary(options.NegativeInfinity)).SetReverse() result2, err := client.ZRange("key1", query) // `result` contains members which have scores within the range of negative infinity to 3, in descending order if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 3 [one two three] [two one]
func (GlideClusterClient) ZRangeWithScores ¶
func (client GlideClusterClient) ZRangeWithScores( key string, rangeQuery options.ZRangeQueryWithScores, ) ([]MemberAndScore, error)
Returns the specified range of elements with their scores 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.
See valkey.io for more details.
Parameters:
key - The key of the sorted set. rangeQuery - The range query object representing the type of range query to perform. - For range queries by index (rank), use [RangeByIndex]. - For range queries by score, use [RangeByScore].
Return value:
An array of elements and their scores within the specified range. If `key` does not exist, it is treated as an empty sorted set, and the command returns an empty array.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) result1, err := client.ZRangeWithScores("key1", options.NewRangeByIndexQuery(0, -1)) query := options.NewRangeByScoreQuery( options.NewScoreBoundary(3, false), options.NewInfiniteScoreBoundary(options.NegativeInfinity)).SetReverse() result2, err := client.ZRangeWithScores("key1", query) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1) fmt.Println(result2)
Output: 3 [{one 1} {two 2} {three 3}] [{two 2} {one 1}]
func (GlideClusterClient) ZRank ¶
Returns the rank of `member` in the sorted set stored at `key`, with scores ordered from low to high, starting from `0`. To get the rank of `member` with its score, see [ZRankWithScore].
See valkey.io for details.
Parameters:
key - The key of the sorted set. member - The member to get the rank of.
Return value:
The rank of `member` in the sorted set. If `key` doesn't exist, or if `member` is not present in the set, `nil` will be returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) result1, err := client.ZRank("key1", "two") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 {1 false}
func (GlideClusterClient) ZRankWithScore ¶
func (client GlideClusterClient) ZRankWithScore(key string, member string) (Result[int64], Result[float64], error)
Returns the rank of `member` in the sorted set stored at `key` with its score, where scores are ordered from the lowest to highest, starting from `0`.
See valkey.io for details.
Parameters:
key - The key of the sorted set. member - The member to get the rank of.
Return value:
A tuple containing the rank of `member` and its score. If `key` doesn't exist, or if `member` is not present in the set, `nil` will be returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) resRank, resScore, err := client.ZRankWithScore("key1", "two") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(resRank) fmt.Println(resScore)
Output: 3 {1 false} {2 false}
func (GlideClusterClient) ZRem ¶
Removes the specified members from the sorted set stored at `key`. Specified members that are not a member of this set are ignored.
See valkey.io for details.
Parameters:
key - The key of the sorted set. members - The members to remove.
Return value:
The number of members that were removed from the sorted set, not including non-existing members. If `key` does not exist, it is treated as an empty sorted set, and this command returns `0`.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}) result1, err := client.ZRem("key1", []string{"one", "two", "nonMember"}) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 3 2
func (GlideClusterClient) ZRemRangeByLex ¶
func (client GlideClusterClient) ZRemRangeByLex(key string, rangeQuery options.RangeByLex) (int64, error)
Removes all elements in the sorted set stored at `key` with a lexicographical order between `rangeQuery.Start` and `rangeQuery.End`.
See valkey.io for details.
Parameters:
key - The key of the sorted set. rangeQuery - The range query object representing the minimum and maximum bound of the lexicographical range.
Return value:
The number of members removed from the sorted set. If `key` does not exist, it is treated as an empty sorted set, and the command returns `0`. If `rangeQuery.Start` is greater than `rangeQuery.End`, `0` is returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) result1, err := client.ZRemRangeByLex( "key1", *options.NewRangeByLexQuery(options.NewLexBoundary("a", false), options.NewLexBoundary("c", true)), ) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 2
func (GlideClusterClient) ZRemRangeByRank ¶
func (client GlideClusterClient) ZRemRangeByRank(key string, start int64, stop int64) (int64, error)
Removes all elements in the sorted set stored at `key` with a rank between `start` and `stop`.
See valkey.io for details.
Parameters:
key - The key of the sorted set. start - The start rank. stop - The stop rank.
Return value:
The number of members removed from the sorted set. If `key` does not exist, it is treated as an empty sorted set, and the command returns `0`. If `start` is greater than `stop`, `0` is returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) result1, err := client.ZRemRangeByRank("key1", 1, 3) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 3
func (GlideClusterClient) ZRemRangeByScore ¶
func (client GlideClusterClient) ZRemRangeByScore(key string, rangeQuery options.RangeByScore) (int64, error)
Removes all elements in the sorted set stored at `key` with a score between `rangeQuery.Start` and `rangeQuery.End`.
See valkey.io for details.
Parameters:
key - The key of the sorted set. rangeQuery - The range query object representing the minimum and maximum bound of the score range. can be an implementation of [options.RangeByScore].
Return value:
The number of members removed from the sorted set. If `key` does not exist, it is treated as an empty sorted set, and the command returns `0`. If `rangeQuery.Start` is greater than `rangeQuery.End`, `0` is returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) result1, err := client.ZRemRangeByScore("key1", *options.NewRangeByScoreQuery( options.NewInfiniteScoreBoundary(options.NegativeInfinity), options.NewInfiniteScoreBoundary(options.PositiveInfinity), )) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 4
func (GlideClusterClient) ZRevRank ¶
Returns the rank of `member` in the sorted set stored at `key`, where scores are ordered from the highest to lowest, starting from `0`. To get the rank of `member` with its score, see [ZRevRankWithScore].
See valkey.io for details.
Parameters:
key - The key of the sorted set. member - The member to get the rank of.
Return value:
The rank of `member` in the sorted set, where ranks are ordered from high to low based on scores. If `key` doesn't exist, or if `member` is not present in the set, `nil` will be returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0, "four": 4.0}) result1, err := client.ZRevRank("key1", "two") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 {2 false}
func (GlideClusterClient) ZRevRankWithScore ¶
func (client GlideClusterClient) ZRevRankWithScore(key string, member string) (Result[int64], Result[float64], error)
Returns the rank of `member` in the sorted set stored at `key`, where scores are ordered from the highest to lowest, starting from `0`. To get the rank of `member` with its score, see [ZRevRankWithScore].
See valkey.io for details.
Parameters:
key - The key of the sorted set. member - The member to get the rank of.
Return value:
A tuple containing the rank of `member` and its score. If `key` doesn't exist, or if `member` is not present in the set, `nil` will be returned.s
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0, "four": 4.0}) resRank, resScore, err := client.ZRevRankWithScore("key1", "two") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(resRank) fmt.Println(resScore)
Output: 4 {2 false} {2 false}
func (GlideClusterClient) ZScan ¶
Iterates incrementally over a sorted set.
See valkey.io for details.
Parameters:
key - The key of the sorted set. cursor - The cursor that points to the next iteration of results. A value of `"0"` indicates the start of the search. For Valkey 8.0 and above, negative cursors are treated like the initial cursor("0").
Return value:
The first return value is the `cursor` for the next iteration of results. `"0"` will be the `cursor` returned on the last iteration of the sorted set. The second return value is always an array of the subset of the sorted set held in `key`. The array is a flattened series of `string` pairs, where the value is at even indices and the score is at odd indices.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0, "four": 4.0}) resCursor, resCol, err := client.ZScan("key1", "0") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(resCursor) fmt.Println(resCol)
Output: 4 0 [one 1 two 2 three 3 four 4]
func (GlideClusterClient) ZScanWithOptions ¶
func (client GlideClusterClient) ZScanWithOptions( key string, cursor string, options options.ZScanOptions, ) (string, []string, error)
Iterates incrementally over a sorted set.
See valkey.io for details.
Parameters:
key - The key of the sorted set. cursor - The cursor that points to the next iteration of results. options - The options for the command. See [options.ZScanOptions] for details.
Return value:
The first return value is the `cursor` for the next iteration of results. `"0"` will be the `cursor` returned on the last iteration of the sorted set. The second return value is always an array of the subset of the sorted set held in `key`. The array is a flattened series of `string` pairs, where the value is at even indices and the score is at odd indices. If [ZScanOptions.noScores] is to `true`, the second return value will only contain the members without scores.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0, "four": 4.0}) resCursor, resCol, err := client.ZScanWithOptions("key1", "0", *options.NewZScanOptions().SetMatch("*")) if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(resCursor) fmt.Println(resCol)
Output: 4 0 [one 1 two 2 three 3 four 4]
func (GlideClusterClient) ZScore ¶
Returns the score of `member` in the sorted set stored at `key`.
See valkey.io for details.
Parameters:
key - The key of the sorted set. member - The member whose score is to be retrieved.
Return value:
The score of the member. If `member` does not exist in the sorted set, `nil` is returned. If `key` does not exist, `nil` is returned.
Example ¶
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0, "four": 4.0}) result1, err := client.ZScore("key1", "three") if err != nil { fmt.Println("Glide example failed with an error: ", err) } fmt.Println(result) fmt.Println(result1)
Output: 4 {3 false}
type GlideClusterClientCommands ¶
type GlideClusterClientCommands interface { BaseClient GenericClusterCommands ServerManagementClusterCommands ConnectionManagementClusterCommands }
GlideClusterClientCommands is a client used for connection in cluster mode.
func NewGlideClusterClient ¶
func NewGlideClusterClient(config *GlideClusterClientConfiguration) (GlideClusterClientCommands, error)
NewGlideClusterClient creates a GlideClusterClientCommands in cluster mode using the given GlideClusterClientConfiguration.
type GlideClusterClientConfiguration ¶
type GlideClusterClientConfiguration struct {
// contains filtered or unexported fields
}
GlideClusterClientConfiguration represents the configuration settings for a Cluster Glide client. Note: Currently, the reconnection strategy in cluster mode is not configurable, and exponential backoff with fixed values is used.
func NewGlideClusterClientConfiguration ¶
func NewGlideClusterClientConfiguration() *GlideClusterClientConfiguration
NewGlideClusterClientConfiguration returns a GlideClusterClientConfiguration with default configuration settings. For further configuration, use the GlideClientConfiguration With* methods.
func (*GlideClusterClientConfiguration) WithAddress ¶
func (config *GlideClusterClientConfiguration) WithAddress(address *NodeAddress) *GlideClusterClientConfiguration
WithAddress adds an address for a known node in the cluster to this configuration's list of addresses. WithAddress can be called multiple times to add multiple addresses to the list. If the server is in cluster mode the list can be partial, as the client will attempt to map out the cluster and find all nodes. If the server is in standalone mode, only nodes whose addresses were provided will be used by the client.
For example:
config := NewGlideClusterClientConfiguration(). WithAddress(&NodeAddress{ Host: "sample-address-0001.use1.cache.amazonaws.com", Port: api.DefaultPost}). WithAddress(&NodeAddress{ Host: "sample-address-0002.use1.cache.amazonaws.com", Port: api.DefaultPost})
func (*GlideClusterClientConfiguration) WithClientName ¶
func (config *GlideClusterClientConfiguration) WithClientName(clientName string) *GlideClusterClientConfiguration
WithClientName sets the client name to be used for the client. Will be used with CLIENT SETNAME command during connection establishment.
func (*GlideClusterClientConfiguration) WithCredentials ¶
func (config *GlideClusterClientConfiguration) WithCredentials( credentials *ServerCredentials, ) *GlideClusterClientConfiguration
WithCredentials sets the credentials for the authentication process. If none are set, the client will not authenticate itself with the server.
func (*GlideClusterClientConfiguration) WithReadFrom ¶
func (config *GlideClusterClientConfiguration) WithReadFrom(readFrom ReadFrom) *GlideClusterClientConfiguration
WithReadFrom sets the client's ReadFrom strategy. If not set, Primary will be used.
func (*GlideClusterClientConfiguration) WithRequestTimeout ¶
func (config *GlideClusterClientConfiguration) WithRequestTimeout(requestTimeout int) *GlideClusterClientConfiguration
WithRequestTimeout sets the duration in milliseconds that the client should wait for a request to complete. This duration encompasses sending the request, awaiting for a response from the server, and any required reconnections or retries. If the specified timeout is exceeded for a pending request, it will result in a timeout error. If not set, a default value will be used.
func (*GlideClusterClientConfiguration) WithUseTLS ¶
func (config *GlideClusterClientConfiguration) WithUseTLS(useTLS bool) *GlideClusterClientConfiguration
WithUseTLS configures the TLS settings for this configuration. Set to true if communication with the cluster should use Transport Level Security. This setting should match the TLS configuration of the server/cluster, otherwise the connection attempt will fail.
type HashCommands ¶
type HashCommands interface { HGet(key string, field string) (Result[string], error) HGetAll(key string) (map[string]string, error) HMGet(key string, fields []string) ([]Result[string], error) HSet(key string, values map[string]string) (int64, error) HSetNX(key string, field string, value string) (bool, error) HDel(key string, fields []string) (int64, error) HLen(key string) (int64, error) HVals(key string) ([]string, error) HExists(key string, field string) (bool, error) HKeys(key string) ([]string, error) HStrLen(key string, field string) (int64, error) HIncrBy(key string, field string, increment int64) (int64, error) HIncrByFloat(key string, field string, increment float64) (float64, error) HScan(key string, cursor string) (string, []string, error) HRandField(key string) (Result[string], error) HRandFieldWithCount(key string, count int64) ([]string, error) HRandFieldWithCountWithValues(key string, count int64) ([][]string, error) HScanWithOptions(key string, cursor string, options options.HashScanOptions) (string, []string, error) }
Supports commands and transactions for the "Hash" group of commands for standalone and cluster clients.
See valkey.io for details.
type HyperLogLogCommands ¶
type HyperLogLogCommands interface { PfAdd(key string, elements []string) (int64, error) PfCount(keys []string) (int64, error) }
Supports commands and transactions for the "HyperLogLog" group of commands for standalone and cluster clients.
See valkey.io for details.
type KeyWithArrayOfMembersAndScores ¶
type KeyWithArrayOfMembersAndScores struct { Key string MembersAndScores []MemberAndScore }
Response of the [ZMPop] and [BZMPop] command.
type KeyWithMemberAndScore ¶
KeyWithMemberAndScore is used by BZPOPMIN/BZPOPMAX, which return an object consisting of the key of the sorted set that was popped, the popped member, and its score.
type ListCommands ¶
type ListCommands interface { LPush(key string, elements []string) (int64, error) LPop(key string) (Result[string], error) LPopCount(key string, count int64) ([]string, error) LPos(key string, element string) (Result[int64], error) LPosWithOptions(key string, element string, options options.LPosOptions) (Result[int64], error) LPosCount(key string, element string, count int64) ([]int64, error) LPosCountWithOptions(key string, element string, count int64, options options.LPosOptions) ([]int64, error) RPush(key string, elements []string) (int64, error) LRange(key string, start int64, end int64) ([]string, error) LIndex(key string, index int64) (Result[string], error) LTrim(key string, start int64, end int64) (string, error) LLen(key string) (int64, error) LRem(key string, count int64, element string) (int64, error) RPop(key string) (Result[string], error) RPopCount(key string, count int64) ([]string, error) LInsert(key string, insertPosition options.InsertPosition, pivot string, element string) (int64, error) BLPop(keys []string, timeoutSecs float64) ([]string, error) BRPop(keys []string, timeoutSecs float64) ([]string, error) RPushX(key string, elements []string) (int64, error) LPushX(key string, elements []string) (int64, error) LMPop(keys []string, listDirection options.ListDirection) (map[string][]string, error) LMPopCount(keys []string, listDirection options.ListDirection, count int64) (map[string][]string, error) BLMPop(keys []string, listDirection options.ListDirection, timeoutSecs float64) (map[string][]string, error) BLMPopCount( keys []string, listDirection options.ListDirection, count int64, timeoutSecs float64, ) (map[string][]string, error) LSet(key string, index int64, element string) (string, error) LMove( source string, destination string, whereFrom options.ListDirection, whereTo options.ListDirection, ) (Result[string], error) BLMove( source string, destination string, whereFrom options.ListDirection, whereTo options.ListDirection, timeoutSecs float64, ) (Result[string], error) }
Supports commands and transactions for the "List" group of commands for standalone and cluster clients.
See valkey.io for details.
type MemberAndScore ¶
MemberAndScore is used by ZRANDMEMBER, which return an object consisting of the sorted set member, and its score.
type NodeAddress ¶
type NodeAddress struct { Host string // If not supplied, api.DefaultHost will be used. Port int // If not supplied, api.DefaultPost will be used. }
NodeAddress represents the host address and port of a node in the cluster.
type Result ¶
type Result[T any] struct { // contains filtered or unexported fields }
func CreateFloat64Result ¶
func CreateInt64Result ¶
func CreateKeyWithArrayOfMembersAndScoresResult ¶
func CreateKeyWithArrayOfMembersAndScoresResult( kmsVals KeyWithArrayOfMembersAndScores, ) Result[KeyWithArrayOfMembersAndScores]
func CreateKeyWithMemberAndScoreResult ¶
func CreateKeyWithMemberAndScoreResult(kmsVal KeyWithMemberAndScore) Result[KeyWithMemberAndScore]
func CreateNilFloat64Result ¶
func CreateNilInt64Result ¶
func CreateNilKeyWithArrayOfMembersAndScoresResult ¶
func CreateNilKeyWithArrayOfMembersAndScoresResult() Result[KeyWithArrayOfMembersAndScores]
func CreateNilKeyWithMemberAndScoreResult ¶
func CreateNilKeyWithMemberAndScoreResult() Result[KeyWithMemberAndScore]
func CreateNilStringResult ¶
func CreateStringResult ¶
type ServerCredentials ¶
type ServerCredentials struct {
// contains filtered or unexported fields
}
ServerCredentials represents the credentials for connecting to servers.
func NewServerCredentials ¶
func NewServerCredentials(username string, password string) *ServerCredentials
NewServerCredentials returns a ServerCredentials struct with the given username and password.
func NewServerCredentialsWithDefaultUsername ¶
func NewServerCredentialsWithDefaultUsername(password string) *ServerCredentials
NewServerCredentialsWithDefaultUsername returns a ServerCredentials struct with a default username of "default" and the given password.
type ServerManagementClusterCommands ¶
type ServerManagementClusterCommands interface { Info() (map[string]string, error) InfoWithOptions(options options.ClusterInfoOptions) (ClusterValue[string], error) TimeWithOptions(routeOption options.RouteOption) (ClusterValue[[]string], error) DBSizeWithOptions(routeOption options.RouteOption) (int64, error) }
ServerManagementCommands supports commands for the "Server Management" group for a cluster client.
See valkey.io for details.
type ServerManagementCommands ¶
type ServerManagementCommands interface { Select(index int64) (string, error) ConfigGet(args []string) (map[string]string, error) ConfigSet(parameters map[string]string) (string, error) Info() (string, error) InfoWithOptions(options options.InfoOptions) (string, error) DBSize() (int64, error) Time() ([]string, error) }
ServerManagementCommands supports commands for the "Server Management" group for a standalone client.
See valkey.io for details.
type SetCommands ¶
type SetCommands interface { SAdd(key string, members []string) (int64, error) SRem(key string, members []string) (int64, error) SMembers(key string) (map[string]struct{}, error) SCard(key string) (int64, error) SIsMember(key string, member string) (bool, error) SDiff(keys []string) (map[string]struct{}, error) SDiffStore(destination string, keys []string) (int64, error) SInter(keys []string) (map[string]struct{}, error) SInterStore(destination string, keys []string) (int64, error) SInterCard(keys []string) (int64, error) SInterCardLimit(keys []string, limit int64) (int64, error) SRandMember(key string) (Result[string], error) SPop(key string) (Result[string], error) SMIsMember(key string, members []string) ([]bool, error) SUnionStore(destination string, keys []string) (int64, error) SUnion(keys []string) (map[string]struct{}, error) SScan(key string, cursor string) (string, []string, error) SScanWithOptions(key string, cursor string, options options.BaseScanOptions) (string, []string, error) SMove(source string, destination string, member string) (bool, error) }
Supports commands and transactions for the "Set" group of commands for standalone and cluster clients.
See valkey.io for details.
type SortedSetCommands ¶
type SortedSetCommands interface { ZAdd(key string, membersScoreMap map[string]float64) (int64, error) ZAddWithOptions(key string, membersScoreMap map[string]float64, opts options.ZAddOptions) (int64, error) ZAddIncr(key string, member string, increment float64) (Result[float64], error) ZAddIncrWithOptions(key string, member string, increment float64, opts options.ZAddOptions) (Result[float64], error) ZIncrBy(key string, increment float64, member string) (float64, error) ZPopMin(key string) (map[string]float64, error) ZPopMinWithOptions(key string, options options.ZPopOptions) (map[string]float64, error) ZPopMax(key string) (map[string]float64, error) ZPopMaxWithOptions(key string, options options.ZPopOptions) (map[string]float64, error) ZRem(key string, members []string) (int64, error) ZCard(key string) (int64, error) BZPopMin(keys []string, timeoutSecs float64) (Result[KeyWithMemberAndScore], error) BZMPop(keys []string, scoreFilter options.ScoreFilter, timeoutSecs float64) (Result[KeyWithArrayOfMembersAndScores], error) BZMPopWithOptions( keys []string, scoreFilter options.ScoreFilter, timeoutSecs float64, options options.ZMPopOptions, ) (Result[KeyWithArrayOfMembersAndScores], error) ZRange(key string, rangeQuery options.ZRangeQuery) ([]string, error) ZRangeWithScores(key string, rangeQuery options.ZRangeQueryWithScores) ([]MemberAndScore, error) ZRank(key string, member string) (Result[int64], error) ZRankWithScore(key string, member string) (Result[int64], Result[float64], error) ZRevRank(key string, member string) (Result[int64], error) ZRevRankWithScore(key string, member string) (Result[int64], Result[float64], error) ZScore(key string, member string) (Result[float64], error) ZCount(key string, rangeOptions options.ZCountRange) (int64, error) ZScan(key string, cursor string) (string, []string, error) ZScanWithOptions(key string, cursor string, options options.ZScanOptions) (string, []string, error) ZRemRangeByLex(key string, rangeQuery options.RangeByLex) (int64, error) ZRemRangeByRank(key string, start int64, stop int64) (int64, error) ZRemRangeByScore(key string, rangeQuery options.RangeByScore) (int64, error) ZDiff(keys []string) ([]string, error) ZDiffWithScores(keys []string) (map[string]float64, error) ZRandMember(key string) (Result[string], error) ZRandMemberWithCount(key string, count int64) ([]string, error) ZRandMemberWithCountWithScores(key string, count int64) ([]MemberAndScore, error) ZMScore(key string, members []string) ([]Result[float64], error) ZDiffStore(destination string, keys []string) (int64, error) ZInter(keys options.KeyArray) ([]string, error) ZInterWithScores(keysOrWeightedKeys options.KeysOrWeightedKeys, options options.ZInterOptions) (map[string]float64, error) ZInterStore(destination string, keysOrWeightedKeys options.KeysOrWeightedKeys) (int64, error) ZInterStoreWithOptions( destination string, keysOrWeightedKeys options.KeysOrWeightedKeys, options options.ZInterOptions, ) (int64, error) }
SortedSetCommands supports commands and transactions for the "Sorted Set Commands" group for standalone and cluster clients.
See valkey.io for details.
type StreamCommands ¶
type StreamCommands interface { XAdd(key string, values [][]string) (Result[string], error) XAddWithOptions(key string, values [][]string, options options.XAddOptions) (Result[string], error) XTrim(key string, options options.XTrimOptions) (int64, error) XLen(key string) (int64, error) XAutoClaim(key string, group string, consumer string, minIdleTime int64, start string) (XAutoClaimResponse, error) XAutoClaimWithOptions( key string, group string, consumer string, minIdleTime int64, start string, options options.XAutoClaimOptions, ) (XAutoClaimResponse, error) XAutoClaimJustId( key string, group string, consumer string, minIdleTime int64, start string, ) (XAutoClaimJustIdResponse, error) XAutoClaimJustIdWithOptions( key string, group string, consumer string, minIdleTime int64, start string, options options.XAutoClaimOptions, ) (XAutoClaimJustIdResponse, error) XReadGroup(group string, consumer string, keysAndIds map[string]string) (map[string]map[string][][]string, error) XReadGroupWithOptions( group string, consumer string, keysAndIds map[string]string, options options.XReadGroupOptions, ) (map[string]map[string][][]string, error) XRead(keysAndIds map[string]string) (map[string]map[string][][]string, error) XReadWithOptions(keysAndIds map[string]string, options options.XReadOptions) (map[string]map[string][][]string, error) XDel(key string, ids []string) (int64, error) XPending(key string, group string) (XPendingSummary, error) XPendingWithOptions(key string, group string, options options.XPendingOptions) ([]XPendingDetail, error) XGroupSetId(key string, group string, id string) (string, error) XGroupSetIdWithOptions(key string, group string, id string, opts options.XGroupSetIdOptions) (string, error) XGroupCreate(key string, group string, id string) (string, error) XGroupCreateWithOptions(key string, group string, id string, opts options.XGroupCreateOptions) (string, error) XGroupDestroy(key string, group string) (bool, error) XGroupCreateConsumer(key string, group string, consumer string) (bool, error) XGroupDelConsumer(key string, group string, consumer string) (int64, error) XAck(key string, group string, ids []string) (int64, error) XClaim( key string, group string, consumer string, minIdleTime int64, ids []string, ) (map[string][][]string, error) XClaimWithOptions( key string, group string, consumer string, minIdleTime int64, ids []string, options options.XClaimOptions, ) (map[string][][]string, error) XClaimJustId(key string, group string, consumer string, minIdleTime int64, ids []string) ([]string, error) XClaimJustIdWithOptions( key string, group string, consumer string, minIdleTime int64, ids []string, options options.XClaimOptions, ) ([]string, error) XRange(key string, start options.StreamBoundary, end options.StreamBoundary) ([]XRangeResponse, error) XRangeWithOptions( key string, start options.StreamBoundary, end options.StreamBoundary, options options.XRangeOptions, ) ([]XRangeResponse, error) XRevRange(key string, start options.StreamBoundary, end options.StreamBoundary) ([]XRangeResponse, error) XRevRangeWithOptions( key string, start options.StreamBoundary, end options.StreamBoundary, options options.XRangeOptions, ) ([]XRangeResponse, error) }
Supports commands and transactions for the "Stream" group of commands for standalone and cluster clients.
See valkey.io for details.
type StringCommands ¶
type StringCommands interface { Set(key string, value string) (string, error) SetWithOptions(key string, value string, options options.SetOptions) (Result[string], error) Get(key string) (Result[string], error) GetEx(key string) (Result[string], error) GetExWithOptions(key string, options options.GetExOptions) (Result[string], error) MSet(keyValueMap map[string]string) (string, error) MGet(keys []string) ([]Result[string], error) MSetNX(keyValueMap map[string]string) (bool, error) Incr(key string) (int64, error) IncrBy(key string, amount int64) (int64, error) IncrByFloat(key string, amount float64) (float64, error) Decr(key string) (int64, error) DecrBy(key string, amount int64) (int64, error) Strlen(key string) (int64, error) SetRange(key string, offset int, value string) (int64, error) GetRange(key string, start int, end int) (string, error) Append(key string, value string) (int64, error) LCS(key1 string, key2 string) (string, error) GetDel(key string) (Result[string], error) }
Supports commands and transactions for the "String" group of commands for standalone and cluster clients.
See valkey.io for details.
type XAutoClaimJustIdResponse ¶
type XAutoClaimJustIdResponse struct { NextEntry string ClaimedEntries []string DeletedMessages []string }
Response type of [XAutoClaimJustId] command.
type XAutoClaimResponse ¶
type XAutoClaimResponse struct { NextEntry string ClaimedEntries map[string][][]string DeletedMessages []string }
Response type of [XAutoClaim] command.
type XPendingDetail ¶
type XPendingDetail struct { // Id is the ID of the pending message. Id string // ConsumerName is the name of the consumer who has the pending message. ConsumerName string // IdleTime is the amount of time (in milliseconds) that the message has been idle. IdleTime int64 // DeliveryCount is the number of times the message has been delivered. DeliveryCount int64 }
XPendingDetail represents the details of a pending message in a stream group. It includes the message ID, the consumer's name, the idle time, and the delivery count.
type XPendingSummary ¶
type XPendingSummary struct { // NumOfMessages is the total number of pending messages in the stream group. NumOfMessages int64 // StartId is the ID of the first pending message in the stream group. StartId Result[string] // EndId is the ID of the last pending message in the stream group. EndId Result[string] // ConsumerMessages is a list of pending messages for each consumer in the stream group. ConsumerMessages []ConsumerPendingMessage }
XPendingSummary represents a summary of pending messages in a stream group. It includes the total number of pending messages, the ID of the first and last pending messages, and a list of consumer pending messages.
func CreateNilXPendingSummary ¶
func CreateNilXPendingSummary() XPendingSummary
type XRangeResponse ¶
Response type of [XRange] and [XRevRange] commands.
Source Files
¶
- base_client.go
- bitmap_commands.go
- config.go
- connection_management_cluster_commands.go
- connection_management_commands.go
- example_utils.go
- generic_base_commands.go
- generic_cluster_commands.go
- generic_commands.go
- glide_client.go
- glide_cluster_client.go
- hash_commands.go
- hyperloglog_commands.go
- list_commands.go
- pinner.go
- response_handlers.go
- response_types.go
- server_management_cluster_commands.go
- server_management_commands.go
- set_commands.go
- sorted_set_commands.go
- stream_commands.go
- string_commands.go