Skip to content

backend

gojuukaze edited this page Aug 27, 2022 · 2 revisions

redisBackend

import "github.com/gojuukaze/YTask/drives/redis/v3"

// 127.0.0.1 : host
// 6379 : port
// "" : password
// 0 : db
// 10 : Maximum number of idle connections in the pool. If poolSize<=0 use default value
//      default value is min(10, numWorkers) at the server
//      default value is 10 at the client

b:=redis.NewRedisBackend("127.0.0.1", "6379", "", 0, 10)

memCacheBackend

import "github.com/gojuukaze/YTask/drives/memcache/v3"

// 127.0.0.1 : host
// 11211 : port
// 10 : Maximum number of idle connections in the pool. If poolSize<=0 use default value
//      default value is min(10, numWorkers) at the server
//      default value is 10 at the client

b := memcache.NewMemCacheBackend([]string{"127.0.0.1:11211"}, 10)

mongoBackend

If you are upgrading from v2 and want to keep old data, use mongo , otherwise use mongo2

  • MongoBackend does not need to set up connection pool size
  • If you need to set the expiration time, you can only set it in the NewMongoBackend() function, and it cannot be modified later after it is set.
    If you want to modify it, you can only manually modify the index of the corresponding table in MongoDB (modify ExpireAfterSeconds)
import "github.com/gojuukaze/YTask/drives/mongo2/v3"

// 127.0.0.1 : host
// 27017 : port
// "" : username
// "" : password
// "test": db
// "test": collection
// 20: Expiration time, in seconds

backend := mongo2.NewMongoBackend("127.0.0.1", "27017", "", "", "test", "test", 20)

custom backend

type BackendInterface interface {
	SetResult(result message.Result, exTime int) error
	GetResult(key string) (message.Result, error)
	// Activate connection
	Activate()
	SetPoolSize(int)
	GetPoolSize() int
	Clone() BackendInterface

}