| 155 | } |
| 156 | |
| 157 | func ExampleClient_hincrby() { |
| 158 | ctx := context.Background() |
| 159 | |
| 160 | rdb := redis.NewClient(&redis.Options{ |
| 161 | Addr: "localhost:6379", |
| 162 | Password: "", // no password docs |
| 163 | DB: 0, // use default DB |
| 164 | }) |
| 165 | |
| 166 | // REMOVE_START |
| 167 | // start with fresh database |
| 168 | rdb.FlushDB(ctx) |
| 169 | rdb.Del(ctx, "bike:1") |
| 170 | // REMOVE_END |
| 171 | |
| 172 | hashFields := []string{ |
| 173 | "model", "Deimos", |
| 174 | "brand", "Ergonom", |
| 175 | "type", "Enduro bikes", |
| 176 | "price", "4972", |
| 177 | } |
| 178 | |
| 179 | _, err := rdb.HSet(ctx, "bike:1", hashFields).Result() |
| 180 | |
| 181 | if err != nil { |
| 182 | panic(err) |
| 183 | } |
| 184 | |
| 185 | // STEP_START hincrby |
| 186 | res6, err := rdb.HIncrBy(ctx, "bike:1", "price", 100).Result() |
| 187 | |
| 188 | if err != nil { |
| 189 | panic(err) |
| 190 | } |
| 191 | |
| 192 | fmt.Println(res6) // >>> 5072 |
| 193 | |
| 194 | res7, err := rdb.HIncrBy(ctx, "bike:1", "price", -100).Result() |
| 195 | |
| 196 | if err != nil { |
| 197 | panic(err) |
| 198 | } |
| 199 | |
| 200 | fmt.Println(res7) // >>> 4972 |
| 201 | // STEP_END |
| 202 | |
| 203 | // Output: |
| 204 | // 5072 |
| 205 | // 4972 |
| 206 | } |
| 207 | |
| 208 | func ExampleClient_incrby_get_mget() { |
| 209 | ctx := context.Background() |