Created
March 4, 2015 12:38
-
-
Save Luzifer/f73e1d4c158590cd38c8 to your computer and use it in GitHub Desktop.
Migrate Etherpad-Lite from MySQL to Redis
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 ( | |
"database/sql" | |
"fmt" | |
"gopkg.in/redis.v2" | |
_ "github.com/go-sql-driver/mysql" | |
) | |
func main() { | |
db := redis.NewTCPClient(&redis.Options{ | |
Addr: "<your redis address>:6379", | |
Password: "<your redis pwd>", | |
DB: 10, | |
}) | |
my, err := sql.Open("mysql", "<mysqluser>:<mysqlpass>@tcp(<mysqlhost>:3306)/<database>") | |
if err != nil { | |
panic(err) | |
} | |
defer my.Close() | |
rows, err := my.Query("SELECT * FROM store") | |
if err != nil { | |
panic(err) | |
} | |
for rows.Next() { | |
var key, value string | |
err = rows.Scan(&key, &value) | |
if err != nil { | |
panic(err) | |
} | |
db.Set(key, value) | |
fmt.Printf(".") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment