Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/hzxgo/redis

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/hzxgo/redis

  • v0.0.0-20190220093138-a53ca32b139d
  • Source
  • Go
  • Socket score

Version published
Created
Source

redis

redis orm by golang 目前对redis的方法支持不全,需要的时候后期再添加

使用介绍--初始化单个实例

package main

import (
	"github.com/hzxgo/log"
	"github.com/hzxgo/redis"
)

func main() {
	address := "127.0.0.1:6379"
	db := 1
	timeout := 3
	auth := "redis_auth_string"
	// instance := "main"

	// init redis
	// 指定实例名称初始化:redis.Init(address, db, timeout, auth, instance)
	err := redis.Init(address, db, timeout, auth)
	if err != nil {
		log.Errorf("redis init | %v", err)
		return
	}

	// redis set
	// 指定实例:redis.Set(rdsUsername, "hezhixiong", instance)
	rdsUsername := "test:username"
	err = redis.Set(rdsUsername, "hezhixiong")
	if  err != nil {
		log.Errorf("redis set %s | %v", rdsUsername, err)
		return
	}

	// redis get
	username, err := redis.Get(rdsUsername)
	if err != nil {
		log.Errorf("redis get %s | %v", rdsUsername, err)
		return
	}

	log.Infof("username: %s", username)
}

初始化多个实例

rc := make([]*redis.RdsCfg, len(Config.Redis))
	for i, v := range Config.Redis {
		rc[i] = &redis.RdsCfg{
			Instance:  v.Instance,
			Address:   v.Address,
			DB:        v.Db,
			Auth:      v.Auth,
			Timeout:   v.Timeout,
			IsDefault: v.IsDefault,
		}
	}
	if err := redis.BatchInit(rc); err != nil {
		log.Errorf("batch init redis | %v", err)
		return
	}

FAQs

Package last updated on 20 Feb 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc