Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@
"redis/sdks/ts/commands/auth/ping"
]
},
{
"group": "Connection",
"pages": [
"redis/sdks/ts/commands/connection/client_setinfo"
]
},
{
"group": "Bitmap",
"pages": [
Expand Down Expand Up @@ -209,6 +215,8 @@
"redis/sdks/ts/commands/hash/hexpiretime",
"redis/sdks/ts/commands/hash/hget",
"redis/sdks/ts/commands/hash/hgetall",
"redis/sdks/ts/commands/hash/hgetdel",
"redis/sdks/ts/commands/hash/hgetex",
"redis/sdks/ts/commands/hash/hincrby",
"redis/sdks/ts/commands/hash/hincrbyfloat",
"redis/sdks/ts/commands/hash/hkeys",
Expand All @@ -217,6 +225,7 @@
"redis/sdks/ts/commands/hash/hrandfield",
"redis/sdks/ts/commands/hash/hscan",
"redis/sdks/ts/commands/hash/hset",
"redis/sdks/ts/commands/hash/hsetex",
"redis/sdks/ts/commands/hash/hpersist",
"redis/sdks/ts/commands/hash/hpexpire",
"redis/sdks/ts/commands/hash/hpexpireat",
Expand Down Expand Up @@ -353,10 +362,12 @@
"group": "Stream",
"pages": [
"redis/sdks/ts/commands/stream/xack",
"redis/sdks/ts/commands/stream/xackdel",
"redis/sdks/ts/commands/stream/xadd",
"redis/sdks/ts/commands/stream/xautoclaim",
"redis/sdks/ts/commands/stream/xclaim",
"redis/sdks/ts/commands/stream/xdel",
"redis/sdks/ts/commands/stream/xdelex",
"redis/sdks/ts/commands/stream/xgroup",
"redis/sdks/ts/commands/stream/xinfo",
"redis/sdks/ts/commands/stream/xlen",
Expand Down Expand Up @@ -423,6 +434,12 @@
"redis/sdks/py/commands/auth/ping"
]
},
{
"group": "Connection",
"pages": [
"redis/sdks/py/commands/connection/client_setinfo"
]
},
{
"group": "Bitmap",
"pages": [
Expand Down Expand Up @@ -465,6 +482,8 @@
"redis/sdks/py/commands/hash/hexpiretime",
"redis/sdks/py/commands/hash/hget",
"redis/sdks/py/commands/hash/hgetall",
"redis/sdks/py/commands/hash/hgetdel",
"redis/sdks/py/commands/hash/hgetex",
"redis/sdks/py/commands/hash/hincrby",
"redis/sdks/py/commands/hash/hincrbyfloat",
"redis/sdks/py/commands/hash/hkeys",
Expand All @@ -479,6 +498,7 @@
"redis/sdks/py/commands/hash/hpexpiretime",
"redis/sdks/py/commands/hash/hpttl",
"redis/sdks/py/commands/hash/hmset",
"redis/sdks/py/commands/hash/hsetex",
"redis/sdks/py/commands/hash/hsetnx",
"redis/sdks/py/commands/hash/hstrlen",
"redis/sdks/py/commands/hash/httl",
Expand Down Expand Up @@ -611,10 +631,12 @@
"group": "Stream",
"pages": [
"redis/sdks/py/commands/stream/xack",
"redis/sdks/py/commands/stream/xackdel",
"redis/sdks/py/commands/stream/xadd",
"redis/sdks/py/commands/stream/xautoclaim",
"redis/sdks/py/commands/stream/xclaim",
"redis/sdks/py/commands/stream/xdel",
"redis/sdks/py/commands/stream/xdelex",
"redis/sdks/py/commands/stream/xgroup_create",
"redis/sdks/py/commands/stream/xgroup_createconsumer",
"redis/sdks/py/commands/stream/xgroup_delconsumer",
Expand Down
145 changes: 124 additions & 21 deletions redis/sdks/py/commands/bitmap/bitop.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,34 @@ title: BITOP
description: Perform bitwise operations between strings.
---

The `BITOP` command in Redis is used to perform bitwise operations on multiple keys (or Redis strings) and store the result in a destination key. It is primarily used for performing logical AND, OR, XOR, and NOT operations on binary data stored in Redis.
The `BITOP` command in Redis is used to perform bitwise operations on multiple keys (or Redis strings) and store the result in a destination key. It supports standard logical operations (AND, OR, XOR, NOT) and advanced operations (DIFF, DIFF1, ANDOR, ONE) for complex bit manipulation.


## Arguments

<ParamField body="operation" type="AND | OR | XOR | NOT" required>
Specifies the type of bitwise operation to perform, which can be one of the
following: `AND`, `OR`, `XOR`, or `NOT`.
<ParamField body="operation" type="AND | OR | XOR | NOT | DIFF | DIFF1 | ANDOR | ONE | and | or | xor | not | diff | diff1 | andor | one" required>
Specifies the type of bitwise operation to perform (case-insensitive):

**Standard Operations:**
- `AND` or `and`: Bitwise AND
- `OR` or `or`: Bitwise OR
- `XOR` or `xor`: Bitwise XOR
- `NOT` or `not`: Bitwise NOT

**Advanced Operations (Redis 8.2+):**
- `DIFF` or `diff`: A bit is set only if it's set in all source bitmaps
- `DIFF1` or `diff1`: A bit is set if it's set in the first key but not in any of the other keys
- `ANDOR` or `andor`: A bit is set if it's set in X and also in one or more of Y1, Y2, ...
- `ONE` or `one`: A bit is set if it's set in exactly one source key
</ParamField>

<ParamField body="destkey" type="str" required>
The key to store the result of the operation in.
The key to store the result of the operation in.
</ParamField>

<ParamField body="keys" type="*List[str]" required>
One or more keys to perform the operation on.
</ParamField>
<ParamField body="keys" type="*List[str]" required >
One or more keys to perform the operation on.
</ParamField>

## Response

Expand All @@ -27,17 +39,108 @@ The `BITOP` command in Redis is used to perform bitwise operations on multiple k
</ResponseField>

<RequestExample>
```py Example
# key1 = 00000001
# key2 = 00000010
redis.setbit("key1", 0, 1)
redis.setbit("key2", 0, 0)
redis.setbit("key2", 1, 1)

assert redis.bitop("AND", "dest", "key1", "key2") == 1

# result = 00000000
assert redis.getbit("dest", 0) == 0
assert redis.getbit("dest", 1) == 0
```
```py Standard Operations
# AND operation
redis.setbit("key1", 0, 1)
redis.setbit("key2", 0, 0)
redis.setbit("key2", 1, 1)

assert redis.bitop("AND", "dest", "key1", "key2") == 1

# OR operation
redis.bitop("OR", "dest", "key1", "key2")

# XOR operation
redis.bitop("XOR", "dest", "key1", "key2")

# NOT operation (only accepts one source key)
redis.bitop("NOT", "dest", "key1")
```

```py DIFF Operation (Redis 8.2+)
# Set bits in multiple bitmaps
redis.setbit("bitmap1", 0, 1)
redis.setbit("bitmap1", 1, 1)
redis.setbit("bitmap2", 1, 1)
redis.setbit("bitmap2", 2, 1)

# DIFF: bits set in all sources
result = redis.bitop("DIFF", "result", "bitmap1", "bitmap2")
# Result: bit 1 is set (only bit present in both)
```

```py DIFF1 Operation (Redis 8.2+)
# Set bits in bitmaps
redis.setbit("exclude", 0, 1)
redis.setbit("exclude", 1, 1)
redis.setbit("include1", 1, 1)
redis.setbit("include2", 2, 1)

# DIFF1: bits in first key but not in others
result = redis.bitop("DIFF1", "result", "exclude", "include1", "include2")
# Result: bit 0 is set (only in exclude, not in include1 or include2)
```

```py ANDOR Operation (Redis 8.2+)
# Set bits in bitmaps
redis.setbit("required", 0, 1)
redis.setbit("required", 1, 1)
redis.setbit("option1", 1, 1)
redis.setbit("option2", 2, 1)

# ANDOR: bits in required AND in at least one option
result = redis.bitop("ANDOR", "result", "required", "option1", "option2")
# Result: bit 1 is set (in required AND in option1)
```

```py ONE Operation (Redis 8.2+)
# Set bits in multiple sources
redis.setbit("source1", 0, 1)
redis.setbit("source1", 1, 1)
redis.setbit("source2", 1, 1)
redis.setbit("source2", 2, 1)
redis.setbit("source3", 2, 1)

# ONE: bits set in exactly one source
result = redis.bitop("ONE", "result", "source1", "source2", "source3")
# Result: bit 0 is set (only in source1)
```
</RequestExample>

## Advanced Operations Details (Redis 8.2+)

### DIFF
A bit in the destination is set if it is set in **all** source bitmaps. This is equivalent to the intersection of all source bitmaps.

**Use Cases:**
- Finding common features across multiple datasets
- Identifying users present in all segments
- Intersection of multiple filters

### DIFF1
A bit in the destination is set if it is set in the **first key** but **not in any of the other keys**. This finds bits unique to the first bitmap.

**Use Cases:**
- Finding exclusive features
- Identifying users in one segment but not in others
- Exclusion filtering

### ANDOR
A bit in the destination is set if it is set in **X and also in one or more of Y1, Y2, ...**. This implements "X AND (Y1 OR Y2 OR ...)" logic.

**Use Cases:**
- Required condition with optional alternatives
- Users with a required attribute and at least one optional attribute
- Complex filtering with mandatory and optional criteria

### ONE
A bit in the destination is set if it is set in **exactly one** of the source keys. This finds bits that are unique to a single source.

**Use Cases:**
- Finding unique occurrences
- Identifying exclusive memberships
- Detecting singular conditions across multiple sets

<Note>
The advanced operations (DIFF, DIFF1, ANDOR, ONE) are available in Redis 8.2.0 and later.
</Note>
91 changes: 91 additions & 0 deletions redis/sdks/py/commands/connection/client_setinfo.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
title: CLIENT SETINFO
description: Set client library name and version information.
---

The `CLIENT SETINFO` command sets client library name and version information that will be shown in CLIENT LIST and CLIENT INFO commands. This helps identify which client library is being used and is useful for debugging and monitoring.

## Arguments

<ParamField body="attribute" type="Literal['LIB-NAME', 'LIB-VER']" required>
The attribute to set (case-insensitive):
- `"LIB-NAME"` or `"lib-name"`: Library name
- `"LIB-VER"` or `"lib-ver"`: Library version
</ParamField>

<ParamField body="value" type="str" required>
The value to set for the attribute.
</ParamField>

## Response

<ResponseField type="str" required>
Returns `"OK"` if the attribute was successfully set.
</ResponseField>

<RequestExample>
```py Set Library Name
# Set the library name
result = redis.client_setinfo("LIB-NAME", "redis-py")
assert result == "OK"
```

```py Set Library Version
# Set the library version
result = redis.client_setinfo("LIB-VER", "1.0.0")
assert result == "OK"
```

```py Lowercase Attributes
# Attributes are case-insensitive
redis.client_setinfo("lib-name", "redis-py")
redis.client_setinfo("lib-ver", "2.0.0")
```

```py With Custom Suffix
# Common pattern: include wrapper or framework info
redis.client_setinfo("LIB-NAME", "redis-py(upstash_v1.0.0)")
redis.client_setinfo("LIB-VER", "1.0.0")
```

```py Complete Setup
# Set both library name and version
redis.client_setinfo("LIB-NAME", "my-redis-wrapper")
redis.client_setinfo("LIB-VER", "3.2.1")

# Now this information will appear in CLIENT LIST output
```
</RequestExample>

## Use Cases

- **Debugging**: Identify which client library version is being used
- **Monitoring**: Track different client libraries connecting to Redis
- **Analytics**: Understand client library distribution across connections
- **Support**: Quickly identify client versions when troubleshooting issues

## Viewing Client Information

After setting client info, you can view it using the CLIENT LIST command:

```py
# Set client information
redis.client_setinfo("LIB-NAME", "redis-py")
redis.client_setinfo("LIB-VER", "1.0.0")

# View all clients (if you have access to CLIENT LIST)
# The output will include lib-name and lib-ver fields
```

## Best Practices

1. **Set on Connection**: Set client info immediately after establishing a connection
2. **Include Version**: Always set both library name and version
3. **Use Descriptive Names**: Make library names easily identifiable
4. **Version Format**: Use semantic versioning (e.g., "1.2.3")
5. **Include Context**: Add wrapper or framework info if applicable

<Note>
This command is available in Redis 7.2.0 and later. The attribute names are case-insensitive and will be normalized to uppercase.
</Note>

Loading