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

Function ExampleClient_num

doctests/json_tutorial_test.go:117–171  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

115}
116
117func ExampleClient_num() {
118 ctx := context.Background()
119
120 rdb := redis.NewClient(&redis.Options{
121 Addr: "localhost:6379",
122 Password: "", // no password docs
123 DB: 0, // use default DB
124 })
125
126 // REMOVE_START
127 // start with fresh database
128 rdb.FlushDB(ctx)
129 rdb.Del(ctx, "crashes")
130 // REMOVE_END
131
132 // STEP_START num
133 res7, err := rdb.JSONSet(ctx, "crashes", "$", 0).Result()
134
135 if err != nil {
136 panic(err)
137 }
138
139 fmt.Println(res7) // >>> OK
140
141 res8, err := rdb.JSONNumIncrBy(ctx, "crashes", "$", 1).Result()
142
143 if err != nil {
144 panic(err)
145 }
146
147 fmt.Println(res8) // >>> [1]
148
149 res9, err := rdb.JSONNumIncrBy(ctx, "crashes", "$", 1.5).Result()
150
151 if err != nil {
152 panic(err)
153 }
154
155 fmt.Println(res9) // >>> [2.5]
156
157 res10, err := rdb.JSONNumIncrBy(ctx, "crashes", "$", -0.75).Result()
158
159 if err != nil {
160 panic(err)
161 }
162
163 fmt.Println(res10) // >>> [1.75]
164 // STEP_END
165
166 // Output:
167 // OK
168 // [1]
169 // [2.5]
170 // [1.75]
171}
172
173func ExampleClient_arr() {
174 ctx := context.Background()

Callers

nothing calls this directly

Calls 5

FlushDBMethod · 0.65
DelMethod · 0.65
ResultMethod · 0.65
JSONSetMethod · 0.65
JSONNumIncrByMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…