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

ihsw picture ihsw  路  5Comments

qiqisteve picture qiqisteve  路  3Comments

songlong picture songlong  路  8Comments

patrickwhite256 picture patrickwhite256  路  7Comments

krak3n picture krak3n  路  4Comments