In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Redis go how to operate lua script, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
Lua script filename: test.lua
Local key=KEYS [1] local val=ARGV [1] return redis.call ('SET', key, val)
Go code
Package mainimport ("fmt"io/ioutil"time"github.com/gomodule/redigo/redis") func CliPool () * redis.Pool {return & redis.Pool {MaxIdle: 10, MaxActive: 100, IdleTimeout: time.Duration (20) * time.Second, Dial: func () (redis.Conn Error) {c, err: = redis.Dial ("tcp", "127.0.0.1 redis.Dial 6379") if err! = nil {return nil, err} return c, nil} }} func main () {var data [] byte var err error if data, err = ioutil.ReadFile ("test.lua") Err! = nil {fmt.Printf ("read failed% v", err.Error ()) return} script: = redis.NewScript (1, string (data)) pool: = CliPool () defer pool.Close () cli: = pool.Get () script.Load (cli) arg: = [] string {"key" "value"} args: = redis.Args {} .AddFlat (arg) var reply interface {} if reply, err = script.Do (cli, args...) Err! = nil {fmt.Printf ("redis exec failed% v", err.Error ()) return} fmt.Printf ("return% v", reply)}
Script.Do parameters must be correct, otherwise it is easy to make mistakes, either fill in arg [0], arg [1] or use redis.Args {} to fill in the parameters, other ways are easy to make mistakes. Make sure that all parameters are in one slice after being operated by (s * Script) args (spec string, keysAndArgs [] interface {}) method.
This is the answer to the question about how redis go operates lua script. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel to learn more about it.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.