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

Function ExampleClient_incr

doctests/string_example_test.go:136–181  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

134}
135
136func ExampleClient_incr() {
137 ctx := context.Background()
138
139 rdb := redis.NewClient(&redis.Options{
140 Addr: "localhost:6379",
141 Password: "", // no password docs
142 DB: 0, // use default DB
143 })
144
145 // REMOVE_START
146 // start with fresh database
147 rdb.FlushDB(ctx)
148 rdb.Del(ctx, "total_crashes")
149 // REMOVE_END
150
151 // STEP_START incr
152 res8, err := rdb.Set(ctx, "total_crashes", "0", 0).Result()
153
154 if err != nil {
155 panic(err)
156 }
157
158 fmt.Println(res8) // >>> OK
159
160 res9, err := rdb.Incr(ctx, "total_crashes").Result()
161
162 if err != nil {
163 panic(err)
164 }
165
166 fmt.Println(res9) // >>> 1
167
168 res10, err := rdb.IncrBy(ctx, "total_crashes", 10).Result()
169
170 if err != nil {
171 panic(err)
172 }
173
174 fmt.Println(res10) // >>> 11
175 // STEP_END
176
177 // Output:
178 // OK
179 // 1
180 // 11
181}

Callers

nothing calls this directly

Calls 6

FlushDBMethod · 0.65
DelMethod · 0.65
ResultMethod · 0.65
SetMethod · 0.65
IncrMethod · 0.65
IncrByMethod · 0.65

Tested by

no test coverage detected