Skip to content

Commit

Permalink
Return int64 instead of Result[int64] where possible.
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Jan 11, 2025
1 parent 0b0b467 commit c051e64
Show file tree
Hide file tree
Showing 12 changed files with 471 additions and 551 deletions.
178 changes: 89 additions & 89 deletions go/api/base_client.go

Large diffs are not rendered by default.

43 changes: 19 additions & 24 deletions go/api/generic_base_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type GenericBaseCommands interface {
// fmt.Println(result) // Output: 2
//
// [valkey.io]: https://valkey.io/commands/del/
Del(keys []string) (Result[int64], error)
Del(keys []string) (int64, error)

// Exists returns the number of keys that exist in the database
//
Expand All @@ -52,11 +52,10 @@ type GenericBaseCommands interface {
//
// Example:
// result, err := client.Exists([]string{"key1", "key2", "key3"})
// result.Value(): 2
// result.IsNil(): false
// result: 2
//
// [valkey.io]: https://valkey.io/commands/exists/
Exists(keys []string) (Result[int64], error)
Exists(keys []string) (int64, error)

// Expire sets a timeout on key. After the timeout has expired, the key will automatically be deleted
//
Expand Down Expand Up @@ -246,16 +245,15 @@ type GenericBaseCommands interface {
//
// Return value:
// The expiration Unix timestamp in seconds.
// -2 if key does not exist or -1 is key exists but has no associated expiration.
// `-2` if key does not exist or `-1` is key exists but has no associated expiration.
//
// Example:
//
// result, err := client.ExpireTime("key")
// result.Value(): 1732118030
// result.IsNil(): false
// result: 1732118030
//
// [valkey.io]: https://valkey.io/commands/expiretime/
ExpireTime(key string) (Result[int64], error)
ExpireTime(key string) (int64, error)

// PExpire Time returns the absolute Unix timestamp (since January 1, 1970) at which the given key
// will expire, in milliseconds.
Expand All @@ -265,16 +263,15 @@ type GenericBaseCommands interface {
//
// Return value:
// The expiration Unix timestamp in milliseconds.
// -2 if key does not exist or -1 is key exists but has no associated expiration.
// `-2` if key does not exist or `-1` is key exists but has no associated expiration.
//
// Example:
//
// result, err := client.PExpireTime("key")
// result.Value(): 33177117420000
// result.IsNil(): false
// result: 33177117420000
//
// [valkey.io]: https://valkey.io/commands/pexpiretime/
PExpireTime(key string) (Result[int64], error)
PExpireTime(key string) (int64, error)

// TTL returns the remaining time to live of key that has a timeout, in seconds.
//
Expand All @@ -283,16 +280,15 @@ type GenericBaseCommands interface {
//
// Return value:
// Returns TTL in seconds,
// -2 if key does not exist, or -1 if key exists but has no associated expiration.
// `-2` if key does not exist, or `-1` if key exists but has no associated expiration.
//
// Example:
//
// result, err := client.TTL("key")
// result.Value(): 3
// result.IsNil(): false
// result: 3
//
// [valkey.io]: https://valkey.io/commands/ttl/
TTL(key string) (Result[int64], error)
TTL(key string) (int64, error)

// PTTL returns the remaining time to live of key that has a timeout, in milliseconds.
//
Expand All @@ -301,16 +297,15 @@ type GenericBaseCommands interface {
//
// Return value:
// Returns TTL in milliseconds,
// -2 if key does not exist, or -1 if key exists but has no associated expiration.
// `-2` if key does not exist, or `-1` if key exists but has no associated expiration.
//
// Example:
//
// result, err := client.PTTL("key")
// result.Value(): 1000
// result.IsNil(): false
// result: 1000
//
// [valkey.io]: https://valkey.io/commands/pttl/
PTTL(key string) (Result[int64], error)
PTTL(key string) (int64, error)

// 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
Expand All @@ -334,10 +329,10 @@ type GenericBaseCommands interface {
// if err != nil {
// // handle error
// }
// fmt.Println(result.Value()) // Output: 3
// fmt.Println(result) // Output: 3
//
// [valkey.io]: Https://valkey.io/commands/unlink/
Unlink(keys []string) (Result[int64], error)
Unlink(keys []string) (int64, error)

// Alters the last access time of a key(s). A key is ignored if it does not exist.
//
Expand All @@ -360,10 +355,10 @@ type GenericBaseCommands interface {
// if err != nil {
// // handle error
// }
// fmt.Println(result.Value()) // Output: 3
// fmt.Println(result) // Output: 3
//
// [valkey.io]: Https://valkey.io/commands/touch/
Touch(keys []string) (Result[int64], error)
Touch(keys []string) (int64, error)

// Type returns the string representation of the type of the value stored at key.
// The different types that can be returned are: string, list, set, zset, hash and stream.
Expand Down
35 changes: 15 additions & 20 deletions go/api/hash_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,14 @@ type HashCommands interface {
// values - A map of field-value pairs to set in the hash.
//
// Return value:
// The Result[int64] containing number of fields that were added or updated.
// The number of fields that were added or updated.
//
// For example:
// num, err := client.HSet("my_hash", map[string]string{"field": "value", "field2": "value2"})
// // num.Value(): 2
// // num.IsNil(): false
// // num: 2
//
// [valkey.io]: https://valkey.io/commands/hset/
HSet(key string, values map[string]string) (Result[int64], error)
HSet(key string, values map[string]string) (int64, error)

// HSetNX sets field in the hash stored at key to value, only if field does not yet exist.
// If key does not exist, a new key holding a hash is created.
Expand Down Expand Up @@ -136,16 +135,14 @@ type HashCommands interface {
// fields - The fields to remove from the hash stored at key.
//
// Return value:
// The Result[int64] containing number of fields that were removed from the hash, not including specified but non-existing
// fields.
// The number of fields that were removed from the hash, not including specified but non-existing fields.
//
// For example:
// num, err := client.HDel("my_hash", []string{"field_1", "field_2"})
// // num.Value(): 2
// // num.IsNil(): false
// // num: 2
//
// [valkey.io]: https://valkey.io/commands/hdel/
HDel(key string, fields []string) (Result[int64], error)
HDel(key string, fields []string) (int64, error)

// HLen returns the number of fields contained in the hash stored at key.
//
Expand All @@ -155,19 +152,17 @@ type HashCommands interface {
// key - The key of the hash.
//
// Return value:
// The Result[int64] containing number of fields in the hash, or 0 when key does not exist.
// 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.
//
// For example:
// num1, err := client.HLen("myHash")
// // num.Value(): 3
// // num.IsNil(): false
// // num: 3
// num2, err := client.HLen("nonExistingKey")
// // num.Value(): 0
// // num.IsNil(): false
// // num: 0
//
// [valkey.io]: https://valkey.io/commands/hlen/
HLen(key string) (Result[int64], error)
HLen(key string) (int64, error)

// HVals returns all values in the hash stored at key.
//
Expand Down Expand Up @@ -241,15 +236,15 @@ type HashCommands interface {
// field - The field to get the string length of its value.
//
// Return value:
// The Result[int64] containing length of the string value associated with field, or 0 when field or key do not exist.
// The length of the string value associated with field, or `0` when field or key do not exist.
//
// For example:
// strlen, err := client.HStrLen("my_hash", "my_field")
// // strlen.Value(): 10
// // strlen.IsNil(): false
//
// [valkey.io]: https://valkey.io/commands/hstrlen/
HStrLen(key string, field string) (Result[int64], error)
HStrLen(key string, field string) (int64, error)

// 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.
Expand All @@ -263,15 +258,15 @@ type HashCommands interface {
// increment - The amount to increment.
//
// Return value:
// The Result[int64] value of `field` in the hash stored at `key` after the increment.
// The value of `field` in the hash stored at `key` after the increment.
//
// Example:
// _, err := client.HSet("key", map[string]string{"field": "10"})
// hincrByResult, err := client.HIncrBy("key", "field", 1)
// // hincrByResult.Value(): 11
// // hincrByResult: 11
//
// [valkey.io]: https://valkey.io/commands/hincrby/
HIncrBy(key string, field string, increment int64) (Result[int64], error)
HIncrBy(key string, field string, increment int64) (int64, 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.
Expand Down
14 changes: 6 additions & 8 deletions go/api/hyperloglog_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ type HyperLogLogCommands interface {
//
// Return value:
// If the HyperLogLog is newly created, or if the HyperLogLog approximated cardinality is
// altered, then returns 1. Otherwise, returns 0.
// altered, then returns `1`. Otherwise, returns `0`.
//
// Example:
// result, err := client.PfAdd("key",[]string{"value1", "value2", "value3"})
// result.Value(): 1
// result.IsNil(): false
// result: 1
//
// [valkey.io]: https://valkey.io/commands/pfadd/
PfAdd(key string, elements []string) (Result[int64], error)
PfAdd(key string, elements []string) (int64, error)

// 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.
Expand All @@ -45,13 +44,12 @@ type HyperLogLogCommands interface {
//
// Return value:
// The approximated cardinality of given HyperLogLog data structures.
// The cardinality of a key that does not exist is 0.
// The cardinality of a key that does not exist is `0`.
//
// Example:
// result, err := client.PfCount([]string{"key1","key2"})
// result.Value(): 5
// result.IsNil(): false
// result: 5
//
// [valkey.io]: https://valkey.io/commands/pfcount/
PfCount(keys []string) (Result[int64], error)
PfCount(keys []string) (int64, error)
}
Loading

0 comments on commit c051e64

Please sign in to comment.