Skip to content

memcachier/examples-gin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MemCachier and Gin on Heroku tutorial

This is an example Gin Gonic app that uses the MemCachier add-on on Heroku. A running version of this app can be found here.

Detailed instructions for developing this app are available here.

Deploy to Heroku

You can deploy this app yourself to Heroku to play with.

Deploy

Running Locally

Run the following commands to get started running this app locally:

$ cd $GOPATH/src
$ git clone https://github.com/memcachier/examples-gin.git
$ cd examples-gin
$ govendor sync
$ memcached &  # run a local memcached server instance
$ MEMCACHIER_SERVERS=localhost:11211 go run main.go

Then visit http://localhost:3000 to play with the app.

Note: instead of running a local memcached server you can also create a MemCachier cache and add the MEMCACHIER_* variables to the environment).

Deploying to Heroku

Run the following commands to deploy the app to Heroku:

$ git clone https://github.com/memcachier/examples-gin.git
$ cd examples-gin
$ heroku create
Creating app... done, ⬢ rocky-chamber-17110
https://rocky-chamber-17110.herokuapp.com/ | https://git.heroku.com/rocky-chamber-17110.git
$ heroku addons:create memcachier:dev
$ git push heroku master
$ heroku open

Configuring MemCachier

Install memcachier/mc and configure it in Gin as follows to use it with MemCachier:

username := os.Getenv("MEMCACHIER_USERNAME")
password := os.Getenv("MEMCACHIER_PASSWORD")
servers := os.Getenv("MEMCACHIER_SERVERS")

config := mc.DefaultConfig()
config.Hasher = mc.NewModuloHasher()         // default
config.Retries = 2                           // default
config.RetryDelay = 200 * time.Millisecond   // default
config.Failover = true                       // default
config.ConnectionTimeout = 2 * time.Second   // default
config.DownRetryDelay = 60 * time.Second     // default
config.PoolSize = 1                          // default
config.TcpKeepAlive = true                   // default
config.TcpKeepAlivePeriod = 60 * time.Second // default
config.TcpNoDelay = true                     // default

mcClient := mc.NewMCwithConfig(servers, username, password, config)

Get involved!

We are happy to receive bug reports, fixes, documentation enhancements, and other improvements.

Please report bugs via the github issue tracker.

Master git repository:

  • git clone git://github.com/memcachier/examples-gin.git

Licensing

This example is open-sourced software licensed under the MIT license.