func FetchFromRedis(messages chan string, RedisClient *goredis.Redis) { data, _ := RedisClient.RPop("Tqueue") if data != nil { fmt.Println("Data: ", string(data)) messages <- string(data) } }
func fetchFromRedis(db *sql.DB, client *goredis.Redis) { reply, err := client.RPop("Rqueue") if err != nil { fmt.Println(err) } fmt.Println(string(reply)) storeinDB(db, string(reply)) }
func FetchFromRedis(messages chan string, RedisClient *goredis.Redis) { data, _ := RedisClient.RPop("Tqueue") if data != nil { //if isJSON(string(data)) { fmt.Println("Data: ", string(data)) messages <- string(data) //} else { // fmt.Println("Data not in JSON format...") //} } }
func redisGetKeyData(r *goredis.Redis, key string) (string, error) { objectType, err := r.Type(key) var data string = "" if err != nil { log.Println("Error getting redis type", err) return data, err } log.Println("redis type response", objectType) var resp interface{} = nil switch objectType { case OBJECT_TYPE_STRING: resp, err = r.Get(key) case OBJECT_TYPE_HASH: resp, err = r.HGetAll(key) case OBJECT_TYPE_LIST: resp, err = r.LRange(key, 0, -1) case OBJECT_TYPE_SET: resp, err = r.SMembers(key) case OBJECT_TYPE_ZSET: resp, err = r.ZRange(key, 0, -1, true) case OBJECT_TYPE_NONE: // key doesnt exist, return empty response return data, err default: // unknow type return empty response return data, err } if err != nil { log.Println("Error getting redis value", err) return data, err } if resp != nil { log.Printf("got resp to encode %+v", resp) // if we have a resp try decoding it var encoded []byte encoded, err = json.Marshal(resp) if err == nil { data = string(encoded) log.Printf("after encoding %+v", string(data)) } } if err != nil { log.Println("Error encoding value to json string", err) } return data, err }