Last active
September 2, 2017 06:38
-
-
Save cipepser/6ac674e08083ff19c9154084b3d4787d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"errors" | |
"fmt" | |
"os" | |
"github.com/garyburd/redigo/redis" | |
) | |
func main() { | |
// connect to redis | |
c, err := redis.Dial("tcp", ":6379") | |
if err != nil { | |
panic(err) | |
} | |
defer c.Close() | |
if len(os.Args) != 1 { | |
errors.New("please input artist name.") | |
} | |
// get keys | |
keys, err := redis.Strings(c.Do("KEYS", "*")) | |
if err != nil { | |
panic(err) | |
} | |
// count up | |
cnt := 0 | |
for _, k := range keys { | |
rep, err := redis.Strings(c.Do("LRANGE", k, "0", "-1")) | |
if err != nil { | |
panic(err) | |
} else { | |
for _, r := range rep { | |
if r == "Japan" { | |
cnt++ | |
} | |
} | |
} | |
} | |
fmt.Println(cnt) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment