| 116 | } |
| 117 | |
| 118 | func ExampleClient_timeseries_add() { |
| 119 | ctx := context.Background() |
| 120 | |
| 121 | rdb := redis.NewClient(&redis.Options{ |
| 122 | Addr: "localhost:6379", |
| 123 | Password: "", // no password set |
| 124 | DB: 0, // use default DB |
| 125 | }) |
| 126 | |
| 127 | // REMOVE_START |
| 128 | // make sure we are working with fresh database |
| 129 | rdb.FlushDB(ctx) |
| 130 | rdb.Del(ctx, "thermometer:1", "thermometer:2") |
| 131 | rdb.TSCreate(ctx, "thermometer:1") |
| 132 | rdb.TSCreate(ctx, "thermometer:2") |
| 133 | // REMOVE_END |
| 134 | |
| 135 | // STEP_START madd |
| 136 | res1, err := rdb.TSMAdd(ctx, [][]interface{}{ |
| 137 | {"thermometer:1", 1, 9.2}, |
| 138 | {"thermometer:1", 2, 9.9}, |
| 139 | {"thermometer:2", 2, 10.3}, |
| 140 | }).Result() |
| 141 | if err != nil { |
| 142 | panic(err) |
| 143 | } |
| 144 | |
| 145 | fmt.Println(res1) // >>> [1 2 2] |
| 146 | // STEP_END |
| 147 | |
| 148 | // STEP_START get |
| 149 | // The last recorded temperature for thermometer:2 |
| 150 | // was 10.3 at time 2. |
| 151 | res2, err := rdb.TSGet(ctx, "thermometer:2").Result() |
| 152 | if err != nil { |
| 153 | panic(err) |
| 154 | } |
| 155 | |
| 156 | fmt.Println(res2) |
| 157 | // >>> {2 10.3} |
| 158 | // STEP_END |
| 159 | |
| 160 | // Output: |
| 161 | // [1 2 2] |
| 162 | // {2 10.3} |
| 163 | } |
| 164 | |
| 165 | func ExampleClient_timeseries_range() { |
| 166 | ctx := context.Background() |