12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- 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("random_reddit_ids")
- reader := csv.NewReader(bufio.NewReader(csvFile))
- reader.Comma = '\t'
- reader.LazyQuotes = true
- conn, _ := redis.Dial("tcp", "localhost:6379")
- graph := rg.Graph{}.New("Reddit", conn)
- batchCounter := 0
- for {
- line, error := reader.Read()
- if error == io.EOF {
- break
- } else if error != nil {
- log.Print(error)
- } else {
- p := &rg.Node{
- Label: "User",
- Properties: map[string]interface{}{
- "RedditId": fmt.Sprintf("u%d", batchCounter),
- "Name": line[0],
- },
- }
- graph.AddNode(p)
- if batchCounter%100 == 0 {
- graph.Flush()
- fmt.Println("Records Added:", batchCounter)
- }
- }
- batchCounter = batchCounter + 1
- }
- graph.Flush()
- conn.Close()
- }
|