Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to encapsulate redis developed in GE language

2025-03-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report