Skip to content

Commit 6f6ca12

Browse files
committed
Merge changes
2 parents ae19c82 + b95fbbd commit 6f6ca12

File tree

9 files changed

+900
-889
lines changed

9 files changed

+900
-889
lines changed

go/api/base_client.go

Lines changed: 571 additions & 321 deletions
Large diffs are not rendered by default.

go/api/generic_base_commands.go

Lines changed: 6 additions & 242 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import "github.com/valkey-io/valkey-glide/go/glide/api/options"
1010
//
1111
// [valkey.io]: https://valkey.io/commands/?group=Generic
1212
type GenericBaseCommands interface {
13-
1413
Del(keys []string) (int64, error)
1514

1615
Exists(keys []string) (int64, error)
@@ -43,97 +42,20 @@ type GenericBaseCommands interface {
4342

4443
Touch(keys []string) (int64, error)
4544

46-
Type(key string) (Result[string], error)
45+
Type(key string) (string, error)
4746

48-
Rename(key string, newKey string) (Result[string], error)
47+
Rename(key string, newKey string) (string, error)
4948

5049
Renamenx(key string, newKey string) (bool, error)
5150

5251
Persist(key string) (bool, error)
5352

54-
// Create a key associated with a value that is obtained by
55-
// deserializing the provided serialized value (obtained via [valkey.io]: Https://valkey.io/commands/dump/).
56-
//
57-
// Parameters:
58-
// key - The key to create.
59-
// ttl - The expiry time (in milliseconds). If 0, the key will persist.
60-
// value - The serialized value to deserialize and assign to key.
61-
//
62-
// Return value:
63-
// Return OK if successfully create a key with a value </code>.
64-
//
65-
// Example:
66-
// result, err := client.Restore("key",ttl, value)
67-
// if err != nil {
68-
// // handle error
69-
// }
70-
// fmt.Println(result.Value()) // Output: OK
71-
//
72-
// [valkey.io]: https://valkey.io/commands/restore/
7353
Restore(key string, ttl int64, value string) (Result[string], error)
7454

75-
// Create a key associated with a value that is obtained by
76-
// deserializing the provided serialized value (obtained via [valkey.io]: Https://valkey.io/commands/dump/).
77-
//
78-
// Parameters:
79-
// key - The key to create.
80-
// ttl - The expiry time (in milliseconds). If 0, the key will persist.
81-
// value - The serialized value to deserialize and assign to key.
82-
// restoreOptions - Set restore options with replace and absolute TTL modifiers, object idletime and frequency
83-
//
84-
// Return value:
85-
// Return OK if successfully create a key with a value.
86-
//
87-
// Example:
88-
// restoreOptions := api.NewRestoreOptionsBuilder().SetReplace().SetABSTTL().SetEviction(api.FREQ, 10)
89-
// resultRestoreOpt, err := client.RestoreWithOptions(key, ttl, value, restoreOptions)
90-
// if err != nil {
91-
// // handle error
92-
// }
93-
// fmt.Println(result.Value()) // Output: OK
94-
//
95-
// [valkey.io]: https://valkey.io/commands/restore/
9655
RestoreWithOptions(key string, ttl int64, value string, option *RestoreOptions) (Result[string], error)
9756

98-
// Returns the internal encoding for the Valkey object stored at key.
99-
//
100-
// Note:
101-
// When in cluster mode, both key and newkey must map to the same hash slot.
102-
//
103-
// Parameters:
104-
// The key of the object to get the internal encoding of.
105-
//
106-
// Return value:
107-
// If key exists, returns the internal encoding of the object stored at
108-
// key as a String. Otherwise, returns null.
109-
//
110-
// Example:
111-
// result, err := client.ObjectEncoding("mykeyRenamenx")
112-
// if err != nil {
113-
// // handle error
114-
// }
115-
// fmt.Println(result.Value()) // Output: embstr
116-
//
117-
// [valkey.io]: https://valkey.io/commands/object-encoding/
11857
ObjectEncoding(key string) (Result[string], error)
11958

120-
// Serialize the value stored at key in a Valkey-specific format and return it to the user.
121-
//
122-
// Parameters:
123-
// The key to serialize.
124-
//
125-
// Return value:
126-
// The serialized value of the data stored at key
127-
// If key does not exist, null will be returned.
128-
//
129-
// Example:
130-
// result, err := client.Dump([]string{"key"})
131-
// if err != nil {
132-
// // handle error
133-
// }
134-
// fmt.Println(result.Value()) // Output: (Serialized Value)
135-
//
136-
// [valkey.io]: https://valkey.io/commands/dump/
13759
Dump(key string) (Result[string], error)
13860

13961
ObjectFreq(key string) (Result[int64], error)
@@ -142,173 +64,15 @@ type GenericBaseCommands interface {
14264

14365
ObjectRefCount(key string) (Result[int64], error)
14466

145-
// Sorts the elements in the list, set, or sorted set at key and returns the result.
146-
// The sort command can be used to sort elements based on different criteria and apply
147-
// transformations on sorted elements.
148-
// To store the result into a new key, see the sortStore function.
149-
//
150-
// Parameters:
151-
// key - The key of the list, set, or sorted set to be sorted.
152-
//
153-
// Return value:
154-
// An Array of sorted elements.
155-
//
156-
// Example:
157-
//
158-
// result, err := client.Sort("key")
159-
// result.Value(): [{1 false} {2 false} {3 false}]
160-
// result.IsNil(): false
161-
//
162-
// [valkey.io]: https://valkey.io/commands/sort/
16367
Sort(key string) ([]Result[string], error)
16468

165-
// Sorts the elements in the list, set, or sorted set at key and returns the result.
166-
// The sort command can be used to sort elements based on different criteria and apply
167-
// transformations on sorted elements.
168-
// To store the result into a new key, see the sortStore function.
169-
//
170-
// Note:
171-
// In cluster mode, if `key` map to different hash slots, the command
172-
// will be split across these slots and executed separately for each. This means the command
173-
// is atomic only at the slot level. If one or more slot-specific requests fail, the entire
174-
// call will return the first encountered error, even though some requests may have succeeded
175-
// while others did not. If this behavior impacts your application logic, consider splitting
176-
// the request into sub-requests per slot to ensure atomicity.
177-
// The use of SortOptions.byPattern and SortOptions.getPatterns in cluster mode is
178-
// supported since Valkey version 8.0.
179-
//
180-
// Parameters:
181-
// key - The key of the list, set, or sorted set to be sorted.
182-
// sortOptions - The SortOptions type.
183-
//
184-
// Return value:
185-
// An Array of sorted elements.
186-
//
187-
// Example:
188-
//
189-
// options := api.NewSortOptions().SetByPattern("weight_*").SetIsAlpha(false).AddGetPattern("object_*").AddGetPattern("#")
190-
// result, err := client.Sort("key", options)
191-
// result.Value(): [{Object_3 false} {c false} {Object_1 false} {a false} {Object_2 false} {b false}]
192-
// result.IsNil(): false
193-
//
194-
// [valkey.io]: https://valkey.io/commands/sort/
19569
SortWithOptions(key string, sortOptions *options.SortOptions) ([]Result[string], error)
19670

197-
// Sorts the elements in the list, set, or sorted set at key and stores the result in
198-
// destination. The sort command can be used to sort elements based on
199-
// different criteria, apply transformations on sorted elements, and store the result in a new key.
200-
// The sort command can be used to sort elements based on different criteria and apply
201-
// transformations on sorted elements.
202-
// To get the sort result without storing it into a key, see the sort or sortReadOnly function.
203-
//
204-
// Note:
205-
// In cluster mode, if `key` and `destination` map to different hash slots, the command
206-
// will be split across these slots and executed separately for each. This means the command
207-
// is atomic only at the slot level. If one or more slot-specific requests fail, the entire
208-
// call will return the first encountered error, even though some requests may have succeeded
209-
// while others did not. If this behavior impacts your application logic, consider splitting
210-
// the request into sub-requests per slot to ensure atomicity.
211-
//
212-
// Parameters:
213-
// key - The key of the list, set, or sorted set to be sorted.
214-
// destination - The key where the sorted result will be stored.
215-
//
216-
// Return value:
217-
// The number of elements in the sorted key stored at destination.
218-
//
219-
// Example:
220-
//
221-
// result, err := client.SortStore("key","destkey")
222-
// result.Value(): 1
223-
// result.IsNil(): false
224-
//
225-
// [valkey.io]: https://valkey.io/commands/sort/
226-
SortStore(key string, destination string) (Result[int64], error)
227-
228-
// Sorts the elements in the list, set, or sorted set at key and stores the result in
229-
// destination. The sort command can be used to sort elements based on
230-
// different criteria, apply transformations on sorted elements, and store the result in a new key.
231-
// The sort command can be used to sort elements based on different criteria and apply
232-
// transformations on sorted elements.
233-
// To get the sort result without storing it into a key, see the sort or sortReadOnly function.
234-
//
235-
// Note:
236-
// In cluster mode, if `key` and `destination` map to different hash slots, the command
237-
// will be split across these slots and executed separately for each. This means the command
238-
// is atomic only at the slot level. If one or more slot-specific requests fail, the entire
239-
// call will return the first encountered error, even though some requests may have succeeded
240-
// while others did not. If this behavior impacts your application logic, consider splitting
241-
// the request into sub-requests per slot to ensure atomicity.
242-
// The use of SortOptions.byPattern and SortOptions.getPatterns
243-
// in cluster mode is supported since Valkey version 8.0.
244-
//
245-
// Parameters:
246-
// key - The key of the list, set, or sorted set to be sorted.
247-
// destination - The key where the sorted result will be stored.
248-
// sortOptions - The SortOptions type.
249-
//
250-
// Return value:
251-
// The number of elements in the sorted key stored at destination.
252-
//
253-
// Example:
254-
//
255-
// options := api.NewSortOptions().SetByPattern("weight_*").SetIsAlpha(false).AddGetPattern("object_*").AddGetPattern("#")
256-
// result, err := client.SortStore("key","destkey",options)
257-
// result.Value(): 1
258-
// result.IsNil(): false
259-
//
260-
// [valkey.io]: https://valkey.io/commands/sort/
261-
SortStoreWithOptions(key string, destination string, sortOptions *options.SortOptions) (Result[int64], error)
262-
263-
// Sorts the elements in the list, set, or sorted set at key and returns the result.
264-
// The sortReadOnly command can be used to sort elements based on different criteria and apply
265-
// transformations on sorted elements.
266-
// This command is routed depending on the client's ReadFrom strategy.
267-
//
268-
// Parameters:
269-
// key - The key of the list, set, or sorted set to be sorted.
270-
//
271-
// Return value:
272-
// An Array of sorted elements.
273-
//
274-
// Example:
275-
//
276-
// result, err := client.SortReadOnly("key")
277-
// result.Value(): [{1 false} {2 false} {3 false}]
278-
// result.IsNil(): false
279-
//
280-
// [valkey.io]: https://valkey.io/commands/sort/
71+
SortStore(key string, destination string) (int64, error)
72+
73+
SortStoreWithOptions(key string, destination string, sortOptions *options.SortOptions) (int64, error)
74+
28175
SortReadOnly(key string) ([]Result[string], error)
28276

283-
// Sorts the elements in the list, set, or sorted set at key and returns the result.
284-
// The sort command can be used to sort elements based on different criteria and apply
285-
// transformations on sorted elements.
286-
// This command is routed depending on the client's ReadFrom strategy.
287-
//
288-
// Note:
289-
// In cluster mode, if `key` map to different hash slots, the command
290-
// will be split across these slots and executed separately for each. This means the command
291-
// is atomic only at the slot level. If one or more slot-specific requests fail, the entire
292-
// call will return the first encountered error, even though some requests may have succeeded
293-
// while others did not. If this behavior impacts your application logic, consider splitting
294-
// the request into sub-requests per slot to ensure atomicity.
295-
// The use of SortOptions.byPattern and SortOptions.getPatterns in cluster mode is
296-
// supported since Valkey version 8.0.
297-
//
298-
// Parameters:
299-
// key - The key of the list, set, or sorted set to be sorted.
300-
// sortOptions - The SortOptions type.
301-
//
302-
// Return value:
303-
// An Array of sorted elements.
304-
//
305-
// Example:
306-
//
307-
// options := api.NewSortOptions().SetByPattern("weight_*").SetIsAlpha(false).AddGetPattern("object_*").AddGetPattern("#")
308-
// result, err := client.SortReadOnly("key", options)
309-
// result.Value(): [{Object_3 false} {c false} {Object_1 false} {a false} {Object_2 false} {b false}]
310-
// result.IsNil(): false
311-
//
312-
// [valkey.io]: https://valkey.io/commands/sort/
31377
SortReadOnlyWithOptions(key string, sortOptions *options.SortOptions) ([]Result[string], error)
31478
}

go/api/hash_commands.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ type HashCommands interface {
2424

2525
HLen(key string) (int64, error)
2626

27-
HVals(key string) ([]Result[string], error)
27+
HVals(key string) ([]string, error)
2828

2929
HExists(key string, field string) (bool, error)
3030

31-
HKeys(key string) ([]Result[string], error)
31+
HKeys(key string) ([]string, error)
3232

3333
HStrLen(key string, field string) (int64, error)
3434

go/api/list_commands.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,23 @@ package api
88
//
99
// [valkey.io]: https://valkey.io/commands/#list
1010
type ListCommands interface {
11-
1211
LPush(key string, elements []string) (int64, error)
1312

1413
LPop(key string) (Result[string], error)
1514

16-
LPopCount(key string, count int64) ([]Result[string], error)
15+
LPopCount(key string, count int64) ([]string, error)
1716

1817
LPos(key string, element string) (Result[int64], error)
1918

2019
LPosWithOptions(key string, element string, options *LPosOptions) (Result[int64], error)
2120

22-
LPosCount(key string, element string, count int64) ([]Result[int64], error)
21+
LPosCount(key string, element string, count int64) ([]int64, error)
2322

24-
LPosCountWithOptions(key string, element string, count int64, options *LPosOptions) ([]Result[int64], error)
23+
LPosCountWithOptions(key string, element string, count int64, options *LPosOptions) ([]int64, error)
2524

2625
RPush(key string, elements []string) (int64, error)
2726

28-
LRange(key string, start int64, end int64) ([]Result[string], error)
27+
LRange(key string, start int64, end int64) ([]string, error)
2928

3029
LIndex(key string, index int64) (Result[string], error)
3130

@@ -37,13 +36,13 @@ type ListCommands interface {
3736

3837
RPop(key string) (Result[string], error)
3938

40-
RPopCount(key string, count int64) ([]Result[string], error)
39+
RPopCount(key string, count int64) ([]string, error)
4140

4241
LInsert(key string, insertPosition InsertPosition, pivot string, element string) (int64, error)
4342

44-
BLPop(keys []string, timeoutSecs float64) ([]Result[string], error)
43+
BLPop(keys []string, timeoutSecs float64) ([]string, error)
4544

46-
BRPop(keys []string, timeoutSecs float64) ([]Result[string], error)
45+
BRPop(keys []string, timeoutSecs float64) ([]string, error)
4746

4847
RPushX(key string, elements []string) (int64, error)
4948

go/api/options/stream_options.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,43 @@ func (xpo *XPendingOptions) ToArgs() ([]string, error) {
262262

263263
return args, nil
264264
}
265+
266+
// Optional arguments for `XGroupCreate` in [StreamCommands]
267+
type XGroupCreateOptions struct {
268+
mkStream bool
269+
entriesRead int64
270+
}
271+
272+
// Create new empty `XGroupCreateOptions`
273+
func NewXGroupCreateOptions() *XGroupCreateOptions {
274+
return &XGroupCreateOptions{false, -1}
275+
}
276+
277+
// Once set and if the stream doesn't exist, creates a new stream with a length of `0`.
278+
func (xgco *XGroupCreateOptions) SetMakeStream() *XGroupCreateOptions {
279+
xgco.mkStream = true
280+
return xgco
281+
}
282+
283+
// A value representing the number of stream entries already read by the group.
284+
//
285+
// Since Valkey version 7.0.0.
286+
func (xgco *XGroupCreateOptions) SetEntriesRead(entriesRead int64) *XGroupCreateOptions {
287+
xgco.entriesRead = entriesRead
288+
return xgco
289+
}
290+
291+
func (xgco *XGroupCreateOptions) ToArgs() ([]string, error) {
292+
var args []string
293+
294+
// if minIdleTime is set, we need to add an `IDLE` argument along with the minIdleTime
295+
if xgco.mkStream {
296+
args = append(args, "MKSTREAM")
297+
}
298+
299+
if xgco.entriesRead > -1 {
300+
args = append(args, "ENTRIESREAD", utils.IntToString(xgco.entriesRead))
301+
}
302+
303+
return args, nil
304+
}

0 commit comments

Comments
 (0)