🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

github.com/valenciaj/gg-redis-pool

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/valenciaj/gg-redis-pool

v0.0.0-20180831172956-59e784689795
Source
Go
Version published
Created
Source

Gin-Gonic Redis Pool Middleware

Simple redis pool middleware for Gin-Gonic framework.

This middleware set on each request a redis connection (new or pooled), and can be accessed with context Get("Redis") or MustGet("Redis") method.

package main

import (
		ggRedisPool "github.com/valenciaj/gg-redis-pool"
)

// Create server
srv := gin.Default()

dbConnStr =: "redis://@127.0.0.1:6379/0"

// Set middlewares
srv.Use(
	gin.Recovery(),
	ggRedisPool.Redis(dbConnStr),
)

// ... set other stuff ...

// Set routes
srv.GET("/", func(ctx *gin.Context) {

	// With Get method
	redisI, err := ctx.Get("Redis")
	if err != nil {
		panic(err)
	}
	// Unbox redis connection
	redis := redisI.(*DB)

	// With MustGet method
	redis := ctx.MustGet("Redis").(*DB)

	// ... do some stuff with redis connection ...

	// Response data
	ctx.HTML(200, "welcome/index.tmpl", gin.H{})
})

FAQs

Package last updated on 31 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts