Get the App
SLTechnology News&Howtos  ›  Development  › 

How to encapsulate redis developed in GE language

Shulou Source: shulou.com Published: 2022-06-02 14:49:59 09月15日 Update

This article focuses on "how to encapsulate redis developed in GE language". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to encapsulate redis developed in GE language.

Go redis collection operation-- sadd

Redis's go language pack, we use the officially recommended redigo, https://github.com/garyburd/redigo

Install redigo$ go get github.com/garyburd/redigo redis operation with password package mainimport ("log"github.com/garyburd/redigo/redis") func main () {server: = "127.0.0.1 github.com/garyburd/redigo/redis" option: = redis.DialPassword ("123456") c, err: = redis.Dial ("tcp", server, option) if err! = nil {log.Println ("connect server failed:" Err) return} defer c.Close () v, err: = redis.Int64 (c.Do ("SADD", "myset", "10.8.37.98")) if err! = nil {log.Println ("SADD failed:", err) return} log.Println ("value:" V)} batch add package mainimport ("log"github.com/garyburd/redigo/redis") func main () {server: = "127.0.0.1 func main 6379" option: = redis.DialPassword ("123456") c, err: = redis.Dial ("tcp", server, option) if err! = nil {log.Println ("connect server failed:" Err) return} defer c.Close () setKey: = "myset" args: = [] interface {} {setKey} args = append (args, "10.1") args = append (args, "10.2") v, err: = redis.Int64 (c.Do ("SADD", args...)) If err! = nil {log.Println ("SADD failed:", err) return} log.Println ("value:", v)} password-less redis operation package mainimport ("fmt"github.com/gomodule/redigo/redis") func main () {c, err: = redis.Dial ("tcp") "127.0.0.1 return 6379") if err! = nil {fmt.Println (err) return} defer c.Close () c.Do ("SET", "hello", "world") s, err: = redis.String ("GET") "hello") redis package package redisimport ("autumn/tools/cfg"fmt"github.com/gomodule/redigo/redis"log") var REDIS redis.Connfunc InitRedis () {REDIS = redis_connect ("default")} func CloseRedis () {REDIS.Close ()} func redis_connect (project string) redis.Conn {server: = fmt.Sprintf ("% SV% s" Cfg.Get ("redis", project+ ".host") .String (), cfg.Get ("redis", project+ ".port") .String () var err error option: = redis.DialPassword (cfg.Get ("redis", project+ ".passwd") .String () c, err: = redis.Dial ("tcp", server) Option) if err! = nil {log.Fatal ("[GIN-MYSQL (" + project + ")] connect to redis error:" + err.Error ()} log.Println ("[GIN-Redis (" + project + ")] connected success") return c} so far I believe you have a deeper understanding of "how to encapsulate redis developed in GE language", so you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Language encapsulation development content password learning practical deeper interest official practical practical easy to operate method more friends website channel recommendation query Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Linux Microsoft Shulou Information Redmi