Skip to content

Commit bbae0da

Browse files
committed
Update: 更新文档
1 parent 7c624f1 commit bbae0da

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

doc/components/redis/function.md

+24-9
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,9 @@ SCRIPT
8888

8989
imi 提供的通过类定义 LUA 脚本的方式,可以更好的管理和复用 LUA 脚本。
9090

91-
***定义***
91+
***普通定义***
9292

9393
```php
94-
declare(strict_types=1);
95-
9694
use Imi\Redis\RedisLuaScript;
9795

9896
class TestEvalScript1 extends RedisLuaScript
@@ -114,11 +112,9 @@ class TestEvalScript1 extends RedisLuaScript
114112
LUA;
115113
}
116114
}
117-
```
118115

119-
***使用***
116+
// ==== 使用 ====
120117

121-
```php
122118
use Imi\Redis\IRedisHandler;
123119

124120
/** @var IRedisHandler $redis */
@@ -130,12 +126,31 @@ $result = $script->invoke($redis, ['imi-script:key1', 'imi-script:key2'], 'val1'
130126
$script->withReadOnly()->invoke($redis, ['imi-script:key1', 'imi-script:key2'], 'val4', 'val5');
131127
```
132128
129+
***快速定义并使用***
130+
131+
```php
132+
use Imi\Redis\RedisLuaScript;
133+
134+
/** @var IRedisHandler $redis */
135+
136+
$script = RedisLuaScript::fastCreate(
137+
script: <<<'LUA'
138+
-- 从工作队列删除
139+
redis.call('zrem', KEYS[1], ARGV[1])
140+
redis.call('rpush', KEYS[2], ARGV[1])
141+
return true
142+
LUA,
143+
keyNum: 2,
144+
);
145+
$script->invoke($redis, ['{imi:work}:queue', '{imi:work}:doing']);
146+
```
147+
133148
> 注意**cluster**模式下使用时必须确保所以`key`都命中同一`node`,否则会导致执行失败。
134149
135150
> 注意**只读执行**环境条件:
136-
> redis >= 7.0
137-
> phpredis >= 6.0
138-
> predis >= 2.2 (cluster 模式下存在 bug,待扩展修复才能使用)
151+
> - redis >= 7.0
152+
> - phpredis >= 6.0
153+
> - predis > 2.2.2 (版本`<= 2.2.2``cluster`模式存在`bug`,待扩展新版本发布才能使用)
139154
140155
### SCAN系列方法
141156

0 commit comments

Comments
 (0)