Skip to content

Instantly share code, notes, and snippets.

@yukimochi
Created Dec 22, 2018
Embed
What would you like to do?
Sidekiq relay to YUKIMOCHI Relay
package main
import (
"fmt"
"os"
"strings"
"github.com/go-redis/redis"
)
func main() {
redis_1 := redis.NewClient(&redis.Options{
Addr: os.Getenv("OLD_REDIS"),
})
redis_2 := redis.NewClient(&redis.Options{
Addr: os.Getenv("NEW_REDIS"),
})
nSub := 0
fmt.Println("-- subscriptions --")
domainKeys, _ := redis_1.Keys("subscription:*").Result()
for _, domainKey := range domainKeys {
domain := strings.Replace(domainKey, "subscription:", "", 1)
inbox, _ := redis_1.HGet(domainKey, "inbox_url").Result()
fmt.Println(domain, inbox)
redis_2.HSet("relay:subscription:"+domain, "inbox_url", inbox)
nSub++
}
fmt.Println("Result : ", nSub)
nLim := 0
fmt.Println("-- limited --")
domainKeys, _ = redis_1.Keys("limited_domain:*").Result()
for _, domainKey := range domainKeys {
domain := strings.Replace(domainKey, "limited_domain:", "", 1)
fmt.Println(domain)
redis_2.HSet("relay:config:limitedDomain", domain, "1").Result()
nLim++
}
fmt.Println("Result : ", nLim)
nBlo := 0
fmt.Println("-- blocked --")
domainKeys, _ = redis_1.Keys("blocked_domain:*").Result()
for _, domainKey := range domainKeys {
domain := strings.Replace(domainKey, "blocked_domain:", "", 1)
fmt.Println(domain)
redis_2.HSet("relay:config:blockedDomain", domain, "1").Result()
nBlo++
}
fmt.Println("Result : ", nBlo)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment