> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xano.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Data Caching (Redis)

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Set Cache Value

```javascript theme={null}
redis.set {
  key = ""
  data = ""
  ttl = 0
}
```

| Parameter | Purpose                 | Example                       |
| --------- | ----------------------- | ----------------------------- |
| key       | Cache key identifier    | `"user:123"`, `"session:abc"` |
| data      | Value to store          | `"data"`, `{user: "john"}`    |
| ttl       | Time-to-live in seconds | `300`, `3600`                 |

<Accordion title="Example">
  ```javascript theme={null}
  redis.set {
    key = "user:"|add:$user.id
    data = $user.profile
    ttl = 3600
  }
  ```

  * Stores a value in cache
  * Optional TTL for expiration
  * Overwrites existing values
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Get Cache Value

```javascript theme={null}
redis.get {
  key = ""
} as x1
```

| Parameter | Purpose                   | Example             |
| --------- | ------------------------- | ------------------- |
| key       | Cache key to retrieve     | `"user:123"`        |
| as        | Alias for retrieved value | `x1`, `cached_data` |

<Accordion title="Example">
  ```javascript theme={null}
  redis.get {
    key = "user:"|add:$user.id
  } as user_data
  ```

  * Retrieves stored value
  * Returns null if key doesn't exist
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Has Cache Value

```javascript theme={null}
redis.has {
  key = ""
} as x2
```

| Parameter | Purpose            | Example         |
| --------- | ------------------ | --------------- |
| key       | Cache key to check | `"session:abc"` |
| as        | Alias for result   | `x2`, `exists`  |

<Accordion title="Example">
  ```javascript theme={null}
  redis.has {
    key = "session:"|add:$session.id
  } as session_exists
  ```

  * Checks if key exists in cache
  * Returns boolean
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Delete Cache Value

```javascript theme={null}
redis.del {
  key = ""
}
```

| Parameter | Purpose             | Example      |
| --------- | ------------------- | ------------ |
| key       | Cache key to delete | `"user:123"` |

<Accordion title="Example">
  ```javascript theme={null}
  redis.del {
    key = "temp:"|add:$id
  }
  ```

  * Removes key and value from cache
  * No effect if key doesn't exist
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Increment Cache Value

```javascript theme={null}
redis.incr {
  package_key = ""
  key = ""
  by = 1
} as x3
```

| Parameter    | Purpose                | Example           |
| ------------ | ---------------------- | ----------------- |
| package\_key | Optional namespace     | `"app1"`          |
| key          | Cache key to increment | `"counter:123"`   |
| by           | Increment amount       | `1`, `5`          |
| as           | Alias for new value    | `x3`, `new_count` |

<Accordion title="Example">
  ```javascript theme={null}
  redis.incr {
    key = "visits:"|add:$page.id
    by = 1
  } as visit_count
  ```

  * Increments numeric value
  * Creates key with value 0 if doesn't exist
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Decrement Cache Value

```javascript theme={null}
redis.decr {
  key = ""
  by = 1
} as x4
```

| Parameter | Purpose                | Example           |
| --------- | ---------------------- | ----------------- |
| key       | Cache key to decrement | `"stock:123"`     |
| by        | Decrement amount       | `1`, `5`          |
| as        | Alias for new value    | `x4`, `new_count` |

<Accordion title="Example">
  ```javascript theme={null}
  redis.decr {
    key = "stock:"|add:$product.id
    by = 1
  } as remaining_stock
  ```

  * Decrements numeric value
  * Creates key with value 0 if doesn't exist
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Get Cache Keys

```javascript theme={null}
redis.keys {
  search = ""
} as keys1
```

| Parameter | Purpose                | Example                  |
| --------- | ---------------------- | ------------------------ |
| search    | Pattern to match keys  | `"user"`, `"session"`    |
| as        | Alias for matched keys | `keys1`, `matching_keys` |

<Accordion title="Example">
  ```javascript theme={null}
  redis.keys {
    search = "user"
  } as active_sessions
  ```

  * Returns array of matching keys
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Add To End of List

```javascript theme={null}
redis.push {
  package_key = ""
  key = ""
  value = ""
} as x5
```

| Parameter    | Purpose                   | Example                            |
| ------------ | ------------------------- | ---------------------------------- |
| package\_key | Optional namespace        | `"app1"`, `"myservice"`            |
| key          | List key                  | `"queue:tasks"`, `"notifications"` |
| value        | Value to append           | `"task1"`, `{id: 123}`             |
| as           | Alias for new list length | `x5`, `list_length`                |

<Accordion title="Example">
  ```javascript theme={null}
  redis.push {
    package_key = "notifications"
    key = "user:"|add:$user.id
    value = $new_message
  } as queue_length
  ```

  * Adds value to end of list
  * Creates list if it doesn't exist
  * Returns new length of list
  * Supports any data type for value
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Add To Beginning of List

```javascript theme={null}
redis.unshift {
  key = ""
  value = ""
} as x6
```

| Parameter | Purpose                   | Example                            |
| --------- | ------------------------- | ---------------------------------- |
| key       | List key                  | `"queue:tasks"`, `"recent_items"`  |
| value     | Value to prepend          | `"new_task"`, `{priority: "high"}` |
| as        | Alias for new list length | `x6`, `list_length`                |

<Accordion title="Example">
  ```javascript theme={null}
  redis.unshift {
    key = "recent_views"
    value = $page.id
  } as list_size
  ```

  * Adds value to beginning of list
  * Creates list if it doesn't exist
  * Returns new length of list
  * Useful for "most recent" lists
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Remove From End of List

```javascript theme={null}
redis.pop {
  key = ""
} as x7
```

| Parameter | Purpose                | Example                          |
| --------- | ---------------------- | -------------------------------- |
| key       | List key               | `"queue:tasks"`, `"stack:items"` |
| as        | Alias for popped value | `x7`, `last_item`                |

<Accordion title="Example">
  ```javascript theme={null}
  redis.pop {
    key = "task_queue"
  } as next_task
  ```

  * Removes and returns last element
  * Returns null if list is empty
  * Reduces list length by 1
  * Common for stack operations
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Remove From Beginning of List

```javascript theme={null}
redis.shift {
  key = ""
} as x8
```

| Parameter | Purpose                 | Example                         |
| --------- | ----------------------- | ------------------------------- |
| key       | List key                | `"queue:tasks"`, `"processing"` |
| as        | Alias for shifted value | `x8`, `first_item`              |

<Accordion title="Example">
  ```javascript theme={null}
  redis.shift {
    key = "message_queue"
  } as next_message
  ```

  * Removes and returns first element
  * Returns null if list is empty
  * Reduces list length by 1
  * Common for queue operations
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Remove From List

```javascript theme={null}
redis.remove {
  key = ""
  value = ""
  count = 0
}
```

| Parameter | Purpose                         | Example                           |
| --------- | ------------------------------- | --------------------------------- |
| key       | List key                        | `"active_users"`, `"blocked_ips"` |
| value     | Value to remove                 | `"user123"`, `{id: 456}`          |
| count     | Number of occurrences to remove | `0` (all), `1`, `-2`              |

<Accordion title="Example">
  ```javascript theme={null}
  redis.remove {
    key = "active_sessions"
    value = $session.id
    count = 0
  }
  ```

  * Removes matching values from list
  * Count=0 removes all occurrences
  * Count>0 removes from head to tail
  * Count\<0 removes from tail to head
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Get Length Of List

```javascript theme={null}
redis.count {
  key = ""
} as x9
```

| Parameter | Purpose               | Example                             |
| --------- | --------------------- | ----------------------------------- |
| key       | List key              | `"queue:pending"`, `"users:online"` |
| as        | Alias for list length | `x9`, `count`                       |

<Accordion title="Example">
  ```javascript theme={null}
  redis.count {
    key = "waiting_users"
  } as queue_size
  ```

  * Returns current length of list
  * Returns 0 if list doesn't exist
  * Useful for queue management
  * Quick operation regardless of list size
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Get Elements From List

```javascript theme={null}
redis.range {
  key = ""
  start = 0
  stop = -1
} as x10
```

| Parameter | Purpose                | Example                           |
| --------- | ---------------------- | --------------------------------- |
| key       | List key               | `"recent:items"`, `"leaderboard"` |
| start     | Start index            | `0`, `5`, `-10`                   |
| stop      | End index              | `-1`, `9`, `20`                   |
| as        | Alias for range values | `x10`, `items`                    |

<Accordion title="Example">
  ```javascript theme={null}
  redis.range {
    key = "recent_posts"
    start = 0
    stop = 9
  } as recent_items
  ```

  * Returns range of list elements
  * -1 means last element
  * Supports negative indices
  * Inclusive of start and stop indices
</Accordion>

## <Icon icon="https://mintcdn.com/xano-997cb9ee/aZQYcxhIvSDTNEim/images/icons/xs_temp.svg?fit=max&auto=format&n=aZQYcxhIvSDTNEim&q=85&s=6e05b86a660544b2d6040353bd8faac8" size={46} width="371" height="137" data-path="images/icons/xs_temp.svg" /> Rate Limit

<Accordion title="Example">
  ```javascript theme={null}
  redis.ratelimit {
    key = "ip:"|add:$request.ip
    max = 100
    ttl = 3600
    error = "Rate limit exceeded. Try again later."
  } as rate_status
  ```

  * Implements rate limiting
  * Tracks attempts within time window
  * Returns current limit status
  * Throws error when limit exceeded
</Accordion>
