From 5bb68e74bf15ac7ecb1a92a1034a62c4cb95a4f9 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 10 Oct 2018 22:21:02 +0800 Subject: [PATCH] add redis cache ci tests --- go.sum | 14 ++++++++++++++ integrations/tests.go | 10 ++++++++-- interface.go | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/go.sum b/go.sum index 3c79850c..c2c01e42 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,19 @@ gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s= gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU= +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.37.4 h1:glPeL3BQJsbF6aIIYfZizMwc5LTYz250bDMjttbBGAU= +cloud.google.com/go v0.37.4/go.mod h1:NHPJ89PdicEuT9hdPXMROBD91xc5uRDxsMtSB16k7hw= +gitea.com/xorm/xorm-redis-cache v0.0.0-20190927143017-f2a95401d847 h1:ogqSdRcrO2rDaDGqHADNnVgjBJatxAR7/LOiOtD5tAE= +gitea.com/xorm/xorm-redis-cache v0.0.0-20190927143017-f2a95401d847/go.mod h1:TJIwRA0Cl8Dn41dI4a3HNTq3uCBRm6ZYTxrz3Di1wuY= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= +github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/integrations/tests.go b/integrations/tests.go index 8b14b0f4..44e12183 100644 --- a/integrations/tests.go +++ b/integrations/tests.go @@ -31,6 +31,7 @@ var ( ptrConnStr = flag.String("conn_str", "./test.db?cache=shared&mode=rwc", "test database connection string") mapType = flag.String("map_type", "snake", "indicate the name mapping") cacheFlag = flag.Bool("cache", false, "if enable cache") + cacheRedisServer = flag.String("cache_redis_server", "127.0.0.1:6379", "if cache enabled this will enable redis cache mode") cluster = flag.Bool("cluster", false, "if this is a cluster") splitter = flag.String("splitter", ";", "the splitter on connstr for cluster") schema = flag.String("schema", "", "specify the schema") @@ -126,8 +127,13 @@ func createEngine(dbType, connStr string) error { testEngine.ShowSQL(*showSQL) testEngine.SetLogLevel(log.LOG_DEBUG) if *cacheFlag { - cacher := caches.NewLRUCacher(caches.NewMemoryStore(), 100000) - testEngine.SetDefaultCacher(cacher) + if *cacheRedisServer == "" { + cacher := NewLRUCacher(NewMemoryStore(), 100000) + testEngine.SetDefaultCacher(cacher) + } else { + cacher := xormrediscache.NewRedisCacher(*cacheRedisServer, "", xormrediscache.DEFAULT_EXPIRATION, testEngine.Logger()) + testEngine.SetDefaultCacher(cacher) + } } if len(*mapType) > 0 { diff --git a/interface.go b/interface.go index 55162c8c..31e69303 100644 --- a/interface.go +++ b/interface.go @@ -94,6 +94,7 @@ type EngineInterface interface { GetTZDatabase() *time.Location GetTZLocation() *time.Location ImportFile(fp string) ([]sql.Result, error) + Logger() core.ILogger MapCacher(interface{}, caches.Cacher) error NewSession() *Session NoAutoTime() *Session