This is a creation in Article, where the information may have evolved or changed.
Before a few completed the thumbnail function, today under the guidance of the usual handsome, completed the Golang operation queue Delete picture function, before planning to use Lua-resty-redis, do not know how to trigger, SB. Then triumph said to use Golang, okay. The following code is available.
Package Mainimport ("FMT" "Time" "gopkg.in/redis.v5" "Strings" "OS" "Path/filepath") var client *redis. Clientfunc Main () {FMT. Println ("Hello, world") client = Redis. Newclient (&redis. OPTIONS{ADDR: "ip:6379", dialtimeout:10 * time. SECOND,READTIMEOUT:30 * time. SECOND,WRITETIMEOUT:30 * time. SECOND,POOLSIZE:10,POOLTIMEOUT:30 * time. Second,}) Pong, err: = client. Ping (). Result () fmt. Println (PONG,ERR) if err! = Nil {panic (err)}for{result, err: = client. Blpop (0, "sync_img"). Result () if err! = Nil {fmt. Println ("Error:%s", err) Continue}img_path: = Result[1]if len (img_path) < 1 {fmt. PRINTLN ("path is null") Continue}if (strings. Contains (Img_path, "..")) {FMT. PRINTLN ("Path can ' t contains ...") continue}//(Gif|jpg|png|jpegif (strings. Hassuffix (Img_path, ". gif") | | Strings. Hassuffix (Img_path, ". jpg") | | Strings. Hassuffix (Img_path, ". png") | | Strings. Hassuffix (Img_path, ". jpeg")) {full_path: = "/tmp" +img_pathfiles, err: = FilePath. Glob (full_path+ "*") if err! = nil{fmt. PriNTLN (Err) Continue}for _, F: = Range files{fmt. Println ("rm Path:%s", f) Removeerr: =os. Remove (f) if removeerr! = nil {fmt. Printf ("File Remove error! %s ", Removeerr)} else {//If the deletion succeeds, output file remove ok! Fmt. Print ("file Remove ok!")}}} Else{fmt. Println ("Only Receive:gif | JPG |png |jpeg ")}}}
The above code patchwork, right, need to go to install first: Go get gopkg.in/redis.v5
Then execute the Run command in the console: Go run xxx.go
Then triumph said that the use of root on the server permission is too large, accidentally delete the other data to do, and then find the use of nobody Run command, modify the following
VIM/ETC/PASSWD find Nobody:x:99:99:nobody:/:/sbin/nologin change to Nobody:x:99:99:nobody:/:/bin/bash after saving execution su-nobody
Then you can do it: su-m nobody-c "Go Run Redis_queue.go &"
Resources: Https://github.com/go-redis/redis Finish the call
SOURCE My blog: http://www.hihubs.com/article/271