-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.php
More file actions
90 lines (68 loc) · 2.1 KB
/
demo.php
File metadata and controls
90 lines (68 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
require 'autoload.php';
// redis连接设定
$config = array(
'host' => 'redis',
'port' => 6379,
'index' => 0,
'auth' => '',
'timeout' => 1,
'reserved' => NULL,
'retry_interval' => 100,
);
// 定义bucket名称
$bucket = 'my-bucket';
// 创建bucket配置对象
$redisBucketConfig = new \Bucket\RedisBucketConfig;
$redisBucketConfig->setConfig($config);
$redisBucketConfig->setName($bucket);
// 创建bucket组件对象
$redisBucket = \Bucket\BucketFactory::make(\Bucket\Type::REDIS, $redisBucketConfig);
// 初始化
$redisBucket->init();
// 设置最大容量
$redisBucket->setMaxSize(3);
// 设置锁超时时间
$redisBucket->setLockTimeout(300);
// 设置执行超时时间
$redisBucket->setTimeout(2000);
// 设置重试间隔时间
$redisBucket->setRetryTime(10);
// 压入3条数据
$response = $redisBucket->push('a');
print_r($response);
$response = $redisBucket->push('b');
print_r($response);
$response = $redisBucket->push('c');
print_r($response);
// 查看已使用容量及最大容量
var_dump(assert($redisBucket->usedSize()==3));
var_dump(assert($redisBucket->maxSize()==3));
// 压入1条数据,不强制弹出,容器已满
$response = $redisBucket->push('d');
print_r($response);
// 压入1条数据,强制弹出
$response = $redisBucket->push('d', 1);
print_r($response);
// 设置最大容量为5,比已用容量大,不用弹出数据
$response = $redisBucket->setMaxSize(5);
print_r($response);
// 压入2条数据
$redisBucket->push('e');
$redisBucket->push('f');
// 查看已使用容量及最大容量
var_dump(assert($redisBucket->usedSize()==5));
var_dump(assert($redisBucket->maxSize()==5));
// 弹出3条数据
$response = $redisBucket->pop(3);
print_r($response);
// 查看已使用容量及最大容量
var_dump(assert($redisBucket->usedSize()==2));
var_dump(assert($redisBucket->maxSize()==5));
// 设置最大容量为1,比已用容量小,弹出数据
$response = $redisBucket->setMaxSize(1);
print_r($response);
// 查看已使用容量及最大容量
var_dump(assert($redisBucket->usedSize()==1));
var_dump(assert($redisBucket->maxSize()==1));
?>