Skip to content

Commit

Permalink
docs added
Browse files Browse the repository at this point in the history
  • Loading branch information
osteensco committed Nov 18, 2024
1 parent 681666f commit cbe90ae
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
48 changes: 48 additions & 0 deletions docs/docs/commands/hash/hexpire.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# HEXPIRE

### Syntax
```
HEXPIRE key seconds [NX | XX | GT | LT] FIELDS numfields field [field...]
```

### Module
<span className="acl-category">hash</span>

### Categories
<span className="acl-category">fast</span>
<span className="acl-category">hash</span>
<span className="acl-category">write</span>

### Description
Set an expiration (TTL or time to live) in seconds on one or more fields of a given hash key.
You must specify at least one field. Field(s) will automatically be deleted from the hash key when their TTLs expire.

### Examples

<Tabs
defaultValue="go"
values={[
{ label: 'Go (Embedded)', value: 'go', },
{ label: 'CLI', value: 'cli', },
]}
>
<TabItem value="go">
Set the expiration in seconds for fields in the hash:
```go
db, err := sugardb.NewSugarDB()
if err != nil {
log.Fatal(err)
}
respArray, err := db.HExpire("key", 500, nil, field1, field2)
```
</TabItem>
<TabItem value="cli">
Set the expiration in seconds for fields in the hash:
```
> HEXPIRE key 500 FIELDS 2 field1 field2
```
</TabItem>
</Tabs>
48 changes: 48 additions & 0 deletions docs/docs/commands/hash/httl.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# HTTL

### Syntax
```
HTTL key FIELDS numfields field [field...]
```

### Module
<span className="acl-category">hash</span>

### Categories
<span className="acl-category">fast</span>
<span className="acl-category">hash</span>
<span className="acl-category">read</span>

### Description
Returns the remaining TTL (time to live) of a hash key's field(s) that have a set expiration.
This introspection capability allows you to check how many seconds a given hash field will continue to be part of the hash key.

### Examples

<Tabs
defaultValue="go"
values={[
{ label: 'Go (Embedded)', value: 'go', },
{ label: 'CLI', value: 'cli', },
]}
>
<TabItem value="go">
Get the expiration time in seconds for fields in the hash:
```go
db, err := sugardb.NewSugarDB()
if err != nil {
log.Fatal(err)
}
TTLArray, err := db.HTTL("key", field1, field2)
```
</TabItem>
<TabItem value="cli">
Get the expiration time in seconds for fields in the hash:
```
> HTTL key FIELDS 2 field1 field2
```
</TabItem>
</Tabs>
37 changes: 37 additions & 0 deletions sugardb/api_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,27 @@ func (server *SugarDB) HDel(key string, fields ...string) (int, error) {
return internal.ParseIntegerResponse(b)
}

// HExpire sets the expiration for the provided field(s) in a hash map.
//
// Parameters:
//
// `key` - string - the key to the hash map.
//
// `seconds` - int - number of seconds until expiration.
//
// `ExOpt` - ExpireOptions - One of NX, XX, GT, LT.
//
// `fields` - ...string - a list of fields to set expiration of.
//
// Returns: an integer array representing the outcome of the commmand for each field.
// - Integer reply: -2 if no such field exists in the provided hash key, or the provided key does not exist.
// - Integer reply: 0 if the specified NX | XX | GT | LT condition has not been met.
// - Integer reply: 1 if the expiration time was set/updated.
// - Integer reply: 2 when HEXPIRE/HPEXPIRE is called with 0 seconds
//
// Errors:
//
// "value of key <key> is not a hash" - when the provided key is not a hash.
func (server *SugarDB) HExpire(key string, seconds int, ExOpt ExpireOptions, fields ...string) ([]int, error) {
secs := fmt.Sprintf("%v", seconds)
cmd := []string{"HEXPIRE", key, secs}
Expand All @@ -376,6 +397,22 @@ func (server *SugarDB) HExpire(key string, seconds int, ExOpt ExpireOptions, fie
return internal.ParseIntegerArrayResponse(b)
}

// HTTL gets the expiration for the provided field(s) in a hash map.
//
// Parameters:
//
// `key` - string - the key to the hash map.
//
// `fields` - ...string - a list of fields to get TTL for.
//
// Returns: an integer array representing the outcome of the commmand for each field.
// - Integer reply: the TTL in seconds.
// - Integer reply: -2 if no such field exists in the provided hash key, or the provided key does not exist.
// - Integer reply: -1 if the field exists but has no associated expiration set.
//
// Errors:
//
// "value of key <key> is not a hash" - when the provided key is not a hash.
func (server *SugarDB) HTTL(key string, fields ...string) ([]int, error) {
numFields := fmt.Sprintf("%v", len(fields))

Expand Down

0 comments on commit cbe90ae

Please sign in to comment.