MCPcopy
hub / github.com/redis/go-redis / ExampleClient_incrby_get_mget

Function ExampleClient_incrby_get_mget

doctests/hash_tutorial_test.go:208–289  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

206}
207
208func ExampleClient_incrby_get_mget() {
209 ctx := context.Background()
210
211 rdb := redis.NewClient(&redis.Options{
212 Addr: "localhost:6379",
213 Password: "", // no password docs
214 DB: 0, // use default DB
215 })
216
217 // REMOVE_START
218 // start with fresh database
219 rdb.FlushDB(ctx)
220 rdb.Del(ctx, "bike:1:stats")
221 // REMOVE_END
222
223 // STEP_START incrby_get_mget
224 res8, err := rdb.HIncrBy(ctx, "bike:1:stats", "rides", 1).Result()
225
226 if err != nil {
227 panic(err)
228 }
229
230 fmt.Println(res8) // >>> 1
231
232 res9, err := rdb.HIncrBy(ctx, "bike:1:stats", "rides", 1).Result()
233
234 if err != nil {
235 panic(err)
236 }
237
238 fmt.Println(res9) // >>> 2
239
240 res10, err := rdb.HIncrBy(ctx, "bike:1:stats", "rides", 1).Result()
241
242 if err != nil {
243 panic(err)
244 }
245
246 fmt.Println(res10) // >>> 3
247
248 res11, err := rdb.HIncrBy(ctx, "bike:1:stats", "crashes", 1).Result()
249
250 if err != nil {
251 panic(err)
252 }
253
254 fmt.Println(res11) // >>> 1
255
256 res12, err := rdb.HIncrBy(ctx, "bike:1:stats", "owners", 1).Result()
257
258 if err != nil {
259 panic(err)
260 }
261
262 fmt.Println(res12) // >>> 1
263
264 res13, err := rdb.HGet(ctx, "bike:1:stats", "rides").Result()
265

Callers

nothing calls this directly

Calls 6

FlushDBMethod · 0.65
DelMethod · 0.65
ResultMethod · 0.65
HIncrByMethod · 0.65
HGetMethod · 0.65
HMGetMethod · 0.65

Tested by

no test coverage detected