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

Function ExampleClient_ttl_cmd

doctests/cmds_generic_test.go:164–200  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

162}
163
164func ExampleClient_ttl_cmd() {
165 ctx := context.Background()
166
167 rdb := redis.NewClient(&redis.Options{
168 Addr: "localhost:6379",
169 Password: "", // no password docs
170 DB: 0, // use default DB
171 })
172
173 // REMOVE_START
174 // start with fresh database
175 rdb.FlushDB(ctx)
176 rdb.Del(ctx, "mykey")
177 // REMOVE_END
178
179 // STEP_START ttl
180 ttlResult1, err := rdb.Set(ctx, "mykey", "Hello", 10*time.Second).Result()
181
182 if err != nil {
183 panic(err)
184 }
185
186 fmt.Println(ttlResult1) // >>> OK
187
188 ttlResult2, err := rdb.TTL(ctx, "mykey").Result()
189
190 if err != nil {
191 panic(err)
192 }
193
194 fmt.Println(math.Round(ttlResult2.Seconds())) // >>> 10
195 // STEP_END
196
197 // Output:
198 // OK
199 // 10
200}

Callers

nothing calls this directly

Calls 5

FlushDBMethod · 0.65
DelMethod · 0.65
ResultMethod · 0.65
SetMethod · 0.65
TTLMethod · 0.65

Tested by

no test coverage detected