func main() { flag.Parse() path := flag.Arg(0) config, _ = simpleconfig.NewConfig(path) host := config.GetStringDefault("redis.netaddress", "tcp:localhost:6379") db := config.GetIntDefault("redis.database", 0) passwd := config.GetStringDefault("redis.password", "") filenotfound = config.GetStringDefault("filenotfound", "https://www.youtube.com/watch?v=oHg5SJYRHA0") redis = godis.New(host, db, passwd) router := mux.NewRouter() router.HandleFunc("/shorten/{url:(.*$)}", shorten) router.HandleFunc("/{short:([a-zA-Z0-9]+$)}", resolve) router.HandleFunc("/{short:([a-zA-Z0-9]+)\\+$}", info) router.HandleFunc("/info/{short:[a-zA-Z0-9]+}", info) router.HandleFunc("/latest/{data:[0-9]+}", latest) router.HandleFunc("/{fileName:(.*$)}", static) listen := config.GetStringDefault("listen", "0.0.0.0") port := config.GetStringDefault("port", "9999") s := &http.Server{ Addr: listen + ":" + port, Handler: router, } s.ListenAndServe() }
func NewRedisConnection(prismId string) *RedisClient { urlString := os.Getenv("PARTY_CLOUD_REDIS") if urlString == "" { urlString = "redis://localhost:6379/" } redisUrl, err := url.Parse(urlString) if err != nil { panic(err) } password := "" if redisUrl.User != nil { password, _ = redisUrl.User.Password() } return &RedisClient{ c: redis.New("tcp:"+redisUrl.Host, 0, password), rpcKey: fmt.Sprintf("prism:%s:connection_request", prismId), playersKey: fmt.Sprintf("prism:%s:players", prismId), maintenanceKey: fmt.Sprintf("prism:%s:maintenance", prismId), protocolKey: fmt.Sprintf("prism:%s:protocol", prismId), badProtocolKey: fmt.Sprintf("prism:%s:bad_protocol", prismId), motdKey: fmt.Sprintf("prism:%s:motd", prismId), } }
func main() { // new client on default port 6379, select db 0 and use no password c := redis.New("tcp:112.65.197.72:6379", 0, "") // set the key "foo" to "Hello Redis" if err := c.Set("foo1", "Hello Redis"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } c.Set("hxsg_uid_max", 300000) c.Set("hxsg_sid_max", 3000000) // retrieve the value of "foo". Returns an Elem obj elem, _ := c.Get("max_id") elem1, _ := c.Get("foo1") // convert the obj to a string and print it fmt.Println("foo:", elem.String()) fmt.Println("foo1:", elem1.String()) if _, err := c.Hset("myhash", "field", "field"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } elem2, _ := c.Get("name") elem3, _ := c.Hget("myhash", "field1") size, _ := c.Hlen("myhash") fmt.Println("name:", elem2.String()) fmt.Println("field:", elem3.String()) fmt.Println("size:", size) TestType("asdfdf") }
func associateUUIDandShortid(shortid string, uuid string) (err error) { r := redis.New(REDIS_ADDR, OPMLFEED_REDIS_DB, REDIS_PASS) err = r.Set("OF_"+shortid, uuid) if err == nil { err = r.Set("OF_id_"+uuid, shortid) } return }
func NewRDB() *redis.Client { rdb_info, err := util.GenFileHash("environments/" + getEnvironment() + "_redis") rdb_num, _ := strconv.Atoi(rdb_info["NUM"]) if err != nil { log.Fatal(err) } return redis.New("tcp:"+rdb_info["HOST"]+":"+rdb_info["PORT"], rdb_num, rdb_info["PASS"]) }
func main() { redis_handle = redis.New("tcp:112.65.197.72:6379", 0, "") redis_handle.Set("111", "111") //log.Fatal(http.ListenAndServe(":8080", http.FileServer(http.Dir("D:\\work\\gostudy")))) //http.Handle("/gostudy/", http.StripPrefix("/gostudy/", http.FileServer(http.Dir("D:\\work\\gostudy")))) http.HandleFunc("/post", postfunc) http.HandleFunc("/get", getfunc) log.Fatal(http.ListenAndServe(":8080", nil)) }
func makeRedisConnector(app *mgollective.Mgollective) mgollective.Connector { host := app.GetStringDefault("connector", "host", "127.0.0.1") port := app.GetStringDefault("connector", "port", "6379") db := app.GetIntDefault("connector", "database", 1) password := app.GetStringDefault("connector", "password", "") client := redis.New("tcp:"+host+":"+port, db, password) return &RedisConnector{ app: app, client: client, } }
func Enqueue_DBSave(binfo, queue_name, class_name string) { var err error client := redis.New(REDIS_ENQUEUE_HOST, 0, "") // Create new Redis client to use for enqueuing enqueuer := resque.NewRedisEnqueuer("godis", client) // Create enqueuer instance // Enqueue the job into the "go" queue with appropriate client _, err = enqueuer.Enqueue(queue_name, class_name, binfo) if err != nil { panic(err) } }
func TestSimonz05GodisConnect(t *testing.T) { simonz05GodisClient = redis.New(fmt.Sprintf("tcp:%s:%d", host, port), 0, "") b, err := simonz05GodisClient.Ping() if err != nil { t.Fatalf("Command failed: %v", err) } if string(b) != "PONG" { t.Fatalf("Failed") } }
// Gets redis instance from configuration parameters. func redis_instance() (redis *godis.Client) { host := os.Getenv("REDIS_HOST") db, _ := strconv.Atoi(os.Getenv("REDIS_DB")) passwd := os.Getenv("REDIS_PASS") redis = godis.New(host, db, passwd) var error_on_set = redis.Set("INIT", time.Now().UTC()) if error_on_set != nil { log.Critical("Cannot access Redis server") os.Exit(2) } return }
func main() { // new client on default port 6379, select db 0 and use no password c := redis.New("", 0, "") // set the key "foo" to "Hello Redis" if err := c.Set("foo", "Hello Redis"); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } // retrieve the value of "foo". Returns an Elem obj elem, _ := c.Get("foo") // convert the obj to a string and print it fmt.Println("foo:", elem.String()) }
func NewRedisConnection() *redis.Client { urlString := os.Getenv("PARTY_CLOUD_REDIS") if urlString == "" { urlString = "redis://10.0.2.2:6379" } redisUrl, err := url.Parse(urlString) if err != nil { panic(err) } password := "" if redisUrl.User != nil { password, _ = redisUrl.User.Password() } return redis.New("tcp:"+redisUrl.Host, 0, password) }
func Open(u *url.URL) (store.Store, error) { var ( addr = "tcp:" + u.Host pass = "" prefix = "sx:" conn *redis.Client ) if ui := u.User; ui != nil { pass, _ = ui.Password() } prefix += u.Path prefix = path.Clean(prefix) conn = redis.New(addr, 0, pass) return &store_t{conn, prefix}, nil }
func main() { // new client on default port 6379, select db 0 and use no password. c := redis.New("", 0, "") // values we want to store values := []int{0, 1, 1, 2, 3, 5, 8, 13, 21, 34} // push the values to the redis list for _, v := range values { if _, err := c.Rpush("bar", v); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } // retrieve the items in the list. Returns a Reply object. res, _ := c.Lrange("bar", 0, 9) // convert the list to an array of ints and print it. fmt.Println("bar:", res.IntArray()) }
func old_Enqueue_NextCrawl(url, id, queue_name, class_name string) { if queue_name == "none" { return } var err error retries := 15 err = errors.New("Init Errir") for retries > 0 && err != nil { client := redis.New(REDIS_ENQUEUE_HOST, 0, "") // Create new Redis client to use for enqueuing enqueuer := resque.NewRedisEnqueuer("godis", client) // Create enqueuer instance _, err = enqueuer.Enqueue(queue_name, class_name, url, id) if err != nil { c := color.New(color.FgYellow) c.Println(retries, "REDIS! Error in queueing on redis", err) time.Sleep(10 * time.Second) } retries = retries - 1 } if err != nil { fmt.Println("ENQUEING ERROR: ", err) panic(err) } if retries < 14 { c := color.New(color.FgCyan) c.Printf("\nRecovered from redis error in %d tries\n", 14-retries) } return }
func ConnectToRedis() *RedisContext { rc := new(RedisContext) rc.Conn = redis.New("tcp:127.0.0.1:6379", 0, "") status_type, err := rc.Conn.Type("migration_status") if err != nil { switch status_type { case "string": status, err := rc.Conn.Get("migration_status") if err == nil { rc.State = DecodeStatus(status.String()) } else { log.Println("Could not get migration_status value, assuming normal") rc.State = NORMAL } default: log.Printf("Could not ascertain migration_status type (unknown type %s), assuming Normal", status_type) } } else { log.Println("Could not ascertain migration_status type due to error, assuming Normal") rc.State = NORMAL } return rc }
func storeClientData(uuid string, clientData []byte) (err error) { r := redis.New(REDIS_ADDR, OPMLFEED_REDIS_DB, REDIS_PASS) err = r.Set("OF_"+uuid, clientData) return }
func shortFromUUID(uuid string) (shortid []byte, err error) { r := redis.New(REDIS_ADDR, OPMLFEED_REDIS_DB, REDIS_PASS) shortid, err = r.Get("OF_id_" + uuid) return }
func uuidFromShort(shortid string) (uuid []byte, err error) { r := redis.New(REDIS_ADDR, OPMLFEED_REDIS_DB, REDIS_PASS) uuid, err = r.Get("OF_" + shortid) return }
func opmlFromUUID(uuid string) (opml []byte, err error) { r := redis.New(REDIS_ADDR, OPMLFEED_REDIS_DB, REDIS_PASS) opml, err = r.Get("OF_" + uuid) return }
func ConnectToRedis() { Conn = redis.New("tcp:127.0.0.1:6379", 0, *RedisPass) }
func GetRedis() *redis.Client { return redis.New(golink.REDIS_HOST, 0, golink.REDIS_AUTH) }