Golang Redis Queue Delete picture

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.