redis实战
cache.php
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
<?php
/**
* redis实战
* Redis practice
*
* 简单字符串缓存
* easy string cache
*
* @author <https://github.com/wuxiumu>
*/
$redis = new \Redis();
$redis->connect('127.0.0.1', 6379);
/**
* 缓存数据
* cache data
*/
$redis->set('cache-key', json_encode([
'data-list' => '这是个缓存数据~',
'data-list-en' => 'This a data of cache~',
]), JSON_UNESCAPED_UNICODE);
echo "字符串缓存成功~ \n\n";
echo "String cache success \n\n";
/**
* 获取缓存数据
* get cache data
*/
$data = $redis->get('cache-key');
echo "读取缓存数据为: \n";
echo "The cache data is: \n";
print_r(json_decode($data,true));