php redis

/**
 * 保留2位小数,只四舍
 * @param type $num
 * @return type  1四舍 2四舍五入 3格式化  4向上取整  5向下取整
 */
function number_format_2( $num , $type=1 , $digit=2 ) {
    
    $digit1 = "%." . intval($digit) . "f";
    $digit2 = "%." . intval($digit + 1) . "f";
    
    if( $type == 1 ){
        return sprintf( $digit1 , substr(sprintf( $digit2 , $num), 0, -1));
    }elseif( $type == 2 ){
        return sprintf( $digit1 , $num );
    }elseif( $type == 3 ){
        return number_format( $num , $digit , '.' , '' );
    }elseif( $type == 4 ){
        return ceil( $num );
    }elseif( $type == 5 ){
        return floor( $num );
    }
    
}


if (!function_exists('getRedis')) {

    function getRedis($config = []) {
        $config = [
            "host" => "127.0.0.1",
            "port" => 6379,
        ];
        $redis = new redis();
        $redis->connect($config['host'], $config['port']);
        return $redis;
    }

}


/**
 * @return boolean
 */
function check_multi( $key='' , $value = "check" , $ttl = 5 ){
    
    /**
     *   //  使用
        $key = $goods_sn . "-" . "confirm_order" . "-"  . $this->id ;
        $check_info = check_multi( $key );
        if( !$check_info ){
            $this->error( "服务器繁忙,请稍候再试" );
        }
     */
    
    $config = [
        "host" => "127.0.0.1",
        "port" => 6379,
    ];
    $redis = new redis();
    $redis->connect($config['host'], $config['port']);
    
    $get_k = $redis->get( $key );
    if( $get_k ){
        return false;
    }
    $set_k = $redis->set( $key , $value , array('nx', 'ex' => $ttl));
    return $set_k;
    
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值