1234567891011121314151617181920212223242526272829303132333435 |
- package main
- import (
- "bufio"
- "encoding/csv"
- "fmt"
- "io"
- "log"
- "os"
- "github.com/gomodule/redigo/redis"
- rg "github.com/maguec/redisgraph-go"
- )
- func main() {
- csvFile, _ := os.Open("subreddit_members")
- reader := csv.NewReader(bufio.NewReader(csvFile))
- reader.Comma = '\t'
- reader.LazyQuotes = true
- for {
- line, error := reader.Read()
- if error == io.EOF {
- break
- } else if error != nil {
- log.Print(error)
- } else {
- conn, _ := redis.Dial("tcp", "localhost:6379")
- graph := rg.Graph{}.New("Reddit", conn)
- query := fmt.Sprintf("MATCH (s:SubReddit {RedditId:'%s'}), (u:User {RedditId:'%s'}) CREATE (u)-[d:SUBSCRIBE]->(s)", line[0], line[1])
- graph.Query(query)
- graph.Flush()
- conn.Close()
- }
- }
- }
|