Python Golang Java DevOps Programmer

Redis Watch

<?php  
header("content-type:text/html;charset=utf-8");  
$redis = new redis();  
$result = $redis->connect('10.10.10.119', 6379); 
$redis->watch("mywatchkey");   
$mywatchkey = $redis->get("mywatchkey");  
$rob_total = 100;   //抢购数量  
if($mywatchkey<$rob_total){  
   
    $redis->multi();  
      
    //设置延迟,方便测试效果。  
    sleep(5);  
    //插入抢购数据  
    $redis->hSet("mywatchlist","user_id_".mt_rand(1, 9999),time());  
    $redis->set("mywatchkey",$mywatchkey+1);  
    $rob_result = $redis->exec();  
    if($rob_result){  
        $mywatchlist = $redis->hGetAll("mywatchlist");  
        echo "抢购成功!<br/>";  
        echo "剩余数量:".($rob_total-$mywatchkey-1)."<br/>";  
        echo "用户列表:<pre>";  
        var_dump($mywatchlist);  
    }else{  
        echo "手气不好,再抢购!";exit;  
    }  
}  
?>  

Express

const express = require('express'); const path = require('path'); const bodyParser = require('body-parser'); const crypto = require('crypto'); // 生成一个 express 实例 const app = express(); // 设置视图文件存放目录 app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs'); // 设置静态文件存放目录 app.use(express.static(path.join(__dirname, 'public'))); // 解析 urlencoded 请求体必备 app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); // 响应首页get请求 app.get('/', function(req, res) { res.render('index', { title: '首页' }); }); app.get('/login', function(req, res) { res.render('login', { title: '登录', user: req.session.user, page: 'login' }); }); app. [Read More]

Coupon 商品优惠券 API

##coupon_temp 优惠券模板

CREATE TABLE `coupon_temp` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ctime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `utime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
  `start_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `end_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `type` tinyint(1) NOT NULL,
  `metadata` varchar(11) DEFAULT NULL,
  `amount_available` bigint(16) DEFAULT NULL,
  `amount_off` bigint(16) DEFAULT NULL,
  `percent_off` bigint(16) DEFAULT NULL,
  `max_circulation` int(8) DEFAULT NULL,
  `max_user_circulation` int(8) DEFAULT NULL,
  `duration` bigint(16) DEFAULT NULL,
  `name` varchar(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=100003 DEFAULT CHARSET=utf8mb4;

Gin API 设计

package main import ( "fmt" "net/http" "reflect" "github.com/gin-gonic/gin" xutil "hdutil" "logic/pkg/dao" "logic/pkg/service" ) func main() { r := gin.Default() rt := r.Group(`/homeworks`) rt.POST( ``, xutil.GRequestBodyObject(reflect.TypeOf(dao.Homework{}), "json"), CreateHomework, ) rt.PUT( `/:homeworkId`, xutil.GPathRequireInt("homeworkId"), xutil.GRequestBodyMap, UpdateHomework, ) r.GET( `/homeworksByFilter`, xutil.GQueryRequireString("filter"), xutil.GQueryOptionalIntDefault("current", 1), xutil.GQueryOptionalIntDefault("pageSize", 10), GetHomeworkByFilter, ) rt.POST( `/notify`, xutil.GRequestBodyObject(reflect.TypeOf([]int64{}), "json"), BatchSendRemark, ) rt.GET( `/:homeworkId/thumb`, xutil.GPathRequireInt("homeworkId"), xutil.GQueryRequireString("sessionId"), ThumbUp, ) rt.GET( `/:homeworkId/sharetimeline`, xutil.GPathRequireInt("homeworkId"), ShareTimeline, ) rt.GET( `/:homeworkId/sharefriend`, xutil.GPathRequireInt("homeworkId"), ShareFriend, ) r.Run(":5000") } func CreateHomework(c *gin.Context) { u := c. [Read More]

商品订单系统API

订单 Order{ Amount: integer ($int64) 商品总金额 = 商品单价 * 购买的商品数量 (填购买几件,1,2,3等等) CancelUrl: string 取消订单后的回调url(不用填) Channel: string 订单渠道 alipay, wx_pub_qr 微信公众号扫码支付(必填,当前支持alipay或者wx_pub_qr) Ctime: string ($string) 订单创建时间 默认自动生成当前时间(不用填) Id: integer ($int64) 订单编号主键自增 (不用填) PingId: integer ($int64) ping++ 自动生成的订单编号 (不用填) PingInfo: string ping++ 自动生成的 支付凭证信息 (不用填) Price: integer ($int64) 商品单价 (必填) ProductId: integer ($int64) 商品id (必填) Status: string 订单状态 待支付:'CREATED',已支付:'PAID',支付失败:'FAIL',存在退款:'REFUNDED',订单已取消'CANCELED' (不用填,默认是待支付,服务端根据ping++的通知 更改状态) SuccessUrl: string 支付成功的回调url(不用填) UserId: integer ($int64) 用户id(必填) Utime: string ($string) 订单更改时间(默认自动生成当前时间,不用填) } 商品 Product{ Avatar: string 商品图片(必填,例如http://img. [Read More]

golang nsq

安装 brew install nsq nsqd : 负责接收消息,存储队列和将消息发送给客户端,nsqd 可以多机器部署,当你使用客户端向一个topic发送消息时,可以配置多个nsqd地址,消息会随机的 分配到各个nsqd上,nsqd优先把消息存储到内存channel中,当内存channel满了之后,则把消息写到磁盘文件中。他监听了两个tcp端口,一个用来服务客 户端,一个用来提供http的接口 ,nsqd 启动时置顶下nsqlookupd地址即可: 在一个 shell 中,运行 nsqlookupd: nsqlookupd: 主要负责服务发现 负责nsqd的心跳、状态监测,给客户端、nsqadmin提供nsqd地址与状态 ➜nsqlookupd [nsqlookupd] 2017/11/27 22:48:11.186029 nsqlookupd v1.0.0-compat (built w/go1.8) [nsqlookupd] 2017/11/27 22:48:11.186266 TCP: listening on [::]:4160 [nsqlookupd] 2017/11/27 22:48:11.186314 HTTP: listening on [::]:4161 再开启一个 shell,运行 nsqd: ➜ bin ./nsqd --lookupd-tcp-address=127.0.0.1:4160 [nsqd] 2017/11/27 22:49:11.433686 nsqd v1.0.0-compat (built w/go1.8) [nsqd] 2017/11/27 22:49:11.433755 ID: 280 [nsqd] 2017/11/27 22:49:11.433797 NSQ: persisting topic/channel metadata to nsqd.dat [nsqd] 2017/11/27 22:49:11. [Read More]