Esempio n. 1
0
// Create a redis-based implementation of goauth2.AuthCache
// By default, it will not have token expiration times
func NewRedisAuthCache(addr string, dbnum int, pass string) *RedisAuthCache {
	return &RedisAuthCache{
		db:          redis.New(addr, dbnum, pass),
		CodeExpiry:  120,
		TokenExpiry: 0,
	}
}
Esempio n. 2
0
func RegisterStream(area *Area, user *User) (Stream, error) {

	pub := godis.New(Cfg.SubAddr, Cfg.SubDb, Cfg.SubPassword)
	sub := godis.NewSub(Cfg.SubAddr, Cfg.SubDb, Cfg.SubPassword)

	err := sub.Subscribe(area.token("Updates"))

	if err != nil {
		return nil, err
	}

	s := &streamImpl{
		pub,
		sub,
		make(chan string, 0),
		area,
		user,
		make(chan bool, 0),
	}

	go s.rcvGoroutine()

	// Do on-join activities
	s.onJoin()

	return s, nil
}
Esempio n. 3
0
File: blog.go Progetto: swcai/goblog
func main() {
	client = godis.New("", 0, "")
	blog.addNewEntries()
	http.Handle("/", http.FileServer(http.Dir("www")))
	http.Handle("/static", http.FileServer(http.Dir("static")))
	http.HandleFunc("/blog/", ServeHTTP(blogIndex))
	http.HandleFunc("/blog/view/", ServeHTTP(viewBlogEntry))
	http.HandleFunc("/blog/edit/", ServeHTTP(editBlogEntry))
	http.ListenAndServe(":8080", nil)
}
Esempio n. 4
0
func BenchmarkGodis(b *testing.B) {
	c := godis.New("", 0, "")
	var p string
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		p = fmt.Sprint(i)
		c.Set(p, p)
	}
	b.StopTimer()
}
Esempio n. 5
0
File: ggodis.go Progetto: rif/gocmd
func main() {
	r := godis.New("", 10, "")
	r.Rpush("lista", 1)
	r.Rpush("lista", 2)
	r.Rpush("lista", 3)
	result, _ := r.Lrange("lista", -100, 100)
	r.Hmset("hash", map[string]interface{}{"month": 1, "now": time.Now()})
	log.Print(result.IntArray())
	result1, _ := r.Hgetall("hash")
	m := result1.StringMap()
	log.Print(time.Parse(m["now"], m["now"]))
}
Esempio n. 6
0
func listen() {
	c := godis.New("", 0, "")

	s, err := c.Subscribe("toukei")
	if err != nil {
		log.Fatal(err)
	}

	for {
		m := <-s.Messages
		println(m.Elem.String())
	}
}
Esempio n. 7
0
func main() {
	fmt.Println(os.Args)
	if len(os.Args) < 2 {
		fmt.Println("Usage:\n\tclean_redis_database <database_nb>")
		log.Fatal("Bye!")
	}
	db_nb, _ := strconv.Atoi(os.Args[1])
	r := godis.New("", db_nb, "")
	keys, _ := r.Keys("*")
	for _, key := range keys {
		r.Del(key)
	}
	fmt.Println("done!")
}
Esempio n. 8
0
func main() {
	// new client on default port 6379, select db 0 and use no password
	c := godis.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())
}
Esempio n. 9
0
func main() {
	r := godis.New("", 10, "")
	start := time.Now()

	for i := 0; i < 10e4; i++ {
		r.Set(fmt.Sprintf("a%v", i), i)
	}
	for i := 0; i < 10e4; i++ {
		r.Get(fmt.Sprintf("a%v", i))
	}
	for i := 0; i < 10e4; i++ {
		r.Del(fmt.Sprintf("a%v", i))
	}
	duration := time.Since(start)
	log.Printf("Elapsed: %v.", duration)
}
Esempio n. 10
0
func publish(stats Stat) {
	c := godis.New("", 0, "")

	statsJson, err := json.Marshal(stats)
	if err != nil {
		log.Fatal(err)
	}

	if err := c.Set("toukei", statsJson); err != nil {
		log.Fatal(err)
	}

	if _, err := c.Publish("toukei", statsJson); err != nil {
		log.Fatal(err)
	}
}
Esempio n. 11
0
func connectToRedis() {
	rawurl := os.Getenv("REDISTOGO_URL")
	log.Printf("Redis to go url: %s\n", rawurl)
	redisurl := url.URL{
		Host: "localhost:6379",
		User: url.UserPassword("", ""),
	}
	parsedurl := &redisurl
	if rawurl != "" {
		var err error
		parsedurl, err = parsedurl.Parse(rawurl)
		if err != nil {
			log.Fatal("Could not parse redis url", err)
		}
	}
	password, _ := parsedurl.User.Password()
	log.Printf("Connecting to redis: '%s' with password '%s'\n", parsedurl.Host, password)
	redis = godis.New("tcp:"+parsedurl.Host, 0, password)
}
Esempio n. 12
0
func newFilterForUri(uri string) sewer.Filter {
	var err error
	var url *url.URL
	var password string
	var db int
	var client *redis.Client

	if url, err = parseRedisUrl(uri); err != nil {
		panic("Invalid redis URL: " + uri)
	}
	if db, err = getRedisDb(url.Path); err != nil {
		panic("Invalid database: " + url.Path)
	}
	if url.User != nil {
		password, _ = url.User.Password()
	}

	client = redis.New("tcp:"+url.Host, db, password)
	return newFilterForClient(client)
}
Esempio n. 13
0
func main() {
	// new client on default port 6379, select db 0 and use no password.
	c := godis.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())
}
Esempio n. 14
0
func main() {
	redis = godis.New("", 0, "")

	for i := 0; i < 1535; i++ {
		body, err := nounFile(i)
		if err != nil {
			fmt.Println("Unable to read svg " + strconv.Itoa(i))
			continue
		}
		if err := redis.Set(nounKey(i), body); err != nil {
			fmt.Println("Unable to write svg " + strconv.Itoa(i) + " to redis.")
		}
	}

	http.Handle("/js/", http.StripPrefix("/js", http.FileServer(http.Dir("/projects/noun_fountain/js"))))

	http.HandleFunc("/", indexHandler)
	http.HandleFunc("/noun/", nounHandler)

	http.ListenAndServe(":8080", nil)
}
Esempio n. 15
0
// jsonServer handles listening to reddis messages and push the result to connected clients
func jsonServer(ws *websocket.Conn) {
	c := godis.New("", 0, "")

	elem, err := c.Get("toukei")
	if err != nil {
		log.Println(err)
		elem = []byte("{}")
	}
	println(string(elem))
	websocketSend(ws, elem)

	s, err := c.Subscribe("toukei")
	if err != nil {
		log.Fatal(err)
	}

	for {
		m := <-s.Messages
		websocketSend(ws, m.Elem)
	}
}
Esempio n. 16
0
func NewRedisStore(addr string) *RedisStore {
	return &RedisStore{client: godis.New(addr, 0, "")}
}
Esempio n. 17
0
func GetRedis() *godis.Client {
	return godis.New(golink.REDIS_HOST, 0, golink.REDIS_AUTH)
}
Esempio n. 18
0
func init() {
	client = redis.New("tcp:127.0.0.1:6379", 0, "")
	client.Flushdb()
}
Esempio n. 19
0
func NewServer() Server {
	var t tcRedis
	t.db = godis.New(Cfg.DbAddr, Cfg.DbDb, Cfg.DbPassword)
	return &t
}
Esempio n. 20
0
func NewRedisStore(keyPrefix string) Interface {
	client := godis.New("", 0, "")
	return &RedisStore{client, keyPrefix}
}
Esempio n. 21
0
type CacheEntry struct {
	Value int
	TTL   time.Time
}

type Request struct {
	Name  string
	Param []string
	Reply chan interface{}
}

var (
	cache = map[string]CacheEntry{}
	queue = make(chan Request, 10)

	redis = godis.New("tcp:localhost:6379", 0, "")
)

func gateway() {
	for true {
		request := <-queue

		cacheReturn := handleCache(request)
		if cacheReturn != -1 {
			request.Reply <- cacheReturn
			continue
		}

		redisReturn := handleRedis(request)
		addToCache(request, redisReturn)