ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

php中使用redis执行lua脚本

2021-09-26 19:34:24  阅读:120  来源: 互联网

标签:lua1234 sequence print redis lua luaError php


<?php
$lua = <<<LUA
    local sequenceKey = KEYS[1]
    local time = KEYS[2]
    local sequenceNumber = redis.call("incr", sequenceKey)
    redis.call("expire", sequenceKey, time)
    return sequenceNumber
LUA;

$redis = new Redis();
$redis->connect('127.0.0.1');
$redis->select(0);
$sequence = $redis->eval($lua, ['lua1234', 120], 2);
$luaError = $redis->getLastError();
if (isset($luaError)) {
    print_r($luaError);
}
print_r($sequence);
//sequence = 1 2 3

 

标签:lua1234,sequence,print,redis,lua,luaError,php
来源: https://www.cnblogs.com/dawuge/p/15339678.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有