Redis: how to delete redis with prefix ?

Created on 12 Jul 2018  路  3Comments  路  Source: go-redis/redis

can somebody tell me how to delete redis key with prefix ?

example i have redis key :
category:book
category:movie

i want to delete all redis key with prefix category*

thanks

Most helpful comment

Something like:

iter := client.Scan(0, "prefix*", 0).Iterator()
for iter.Next() {
    err := client.Del(iter.Val()).Err()
    if err != nil { panic(err) }
}
if err := iter.Err(); err != nil {
    panic(err)
}

All 3 comments

use scan + del

@jakey766 can you give me sample golang script ?

please .. thank you

Something like:

iter := client.Scan(0, "prefix*", 0).Iterator()
for iter.Next() {
    err := client.Del(iter.Val()).Err()
    if err != nil { panic(err) }
}
if err := iter.Err(); err != nil {
    panic(err)
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

pranas picture pranas  路  8Comments

songlong picture songlong  路  8Comments

qiqisteve picture qiqisteve  路  3Comments

chenweiyj picture chenweiyj  路  3Comments

Turing-Chu picture Turing-Chu  路  3Comments