| 59 | } |
| 60 | |
| 61 | func ExampleClient_bitcount() { |
| 62 | ctx := context.Background() |
| 63 | |
| 64 | rdb := redis.NewClient(&redis.Options{ |
| 65 | Addr: "localhost:6379", |
| 66 | Password: "", // no password docs |
| 67 | DB: 0, // use default DB |
| 68 | }) |
| 69 | |
| 70 | // REMOVE_START |
| 71 | // start with fresh database |
| 72 | rdb.FlushDB(ctx) |
| 73 | _, err := rdb.SetBit(ctx, "pings:2024-01-01-00:00", 123, 1).Result() |
| 74 | |
| 75 | if err != nil { |
| 76 | panic(err) |
| 77 | } |
| 78 | // REMOVE_END |
| 79 | |
| 80 | // STEP_START bitcount |
| 81 | res4, err := rdb.BitCount(ctx, "pings:2024-01-01-00:00", |
| 82 | &redis.BitCount{ |
| 83 | Start: 0, |
| 84 | End: 456, |
| 85 | }).Result() |
| 86 | |
| 87 | if err != nil { |
| 88 | panic(err) |
| 89 | } |
| 90 | |
| 91 | fmt.Println(res4) // >>> 1 |
| 92 | // STEP_END |
| 93 | |
| 94 | // Output: |
| 95 | // 1 |
| 96 | } |