()
| 157 | } |
| 158 | |
| 159 | func ExampleKV_getSortedPrefix() { |
| 160 | forUnitTestsRunInMockedContext(mockKV_getSortedPrefix, func() { |
| 161 | cli, err := clientv3.New(clientv3.Config{ |
| 162 | Endpoints: exampleEndpoints(), |
| 163 | DialTimeout: dialTimeout, |
| 164 | }) |
| 165 | if err != nil { |
| 166 | log.Fatal(err) |
| 167 | } |
| 168 | defer cli.Close() |
| 169 | |
| 170 | for i := range make([]int, 3) { |
| 171 | ctx, cancel := context.WithTimeout(context.Background(), requestTimeout) |
| 172 | _, err = cli.Put(ctx, fmt.Sprintf("key_%d", i), "value") |
| 173 | cancel() |
| 174 | if err != nil { |
| 175 | log.Fatal(err) |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | ctx, cancel := context.WithTimeout(context.Background(), requestTimeout) |
| 180 | resp, err := cli.Get(ctx, "key", clientv3.WithPrefix(), clientv3.WithSort(clientv3.SortByKey, clientv3.SortDescend)) |
| 181 | cancel() |
| 182 | if err != nil { |
| 183 | log.Fatal(err) |
| 184 | } |
| 185 | for _, ev := range resp.Kvs { |
| 186 | fmt.Printf("%s : %s\n", ev.Key, ev.Value) |
| 187 | } |
| 188 | }) |
| 189 | // Output: |
| 190 | // key_2 : value |
| 191 | // key_1 : value |
| 192 | // key_0 : value |
| 193 | } |
| 194 | |
| 195 | func mockKV_delete() { |
| 196 | fmt.Println("Deleted all keys: true") |
nothing calls this directly
no test coverage detected
searching dependent graphs…