wanglizhong
2025-05-05 9b8a7157bb9c401de973a4107f74ff3e723ec156
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
<?php
class LtCacheHandle
{
    public $configHandle;
    public $group;
    public $node;
    public $role = "master";
    public $connectionManager;
    public $connectionResource;
    protected $connectionAdapter;
 
    public function __construct()
    {
    }
 
    public function init()
    {
        $this->connectionManager = new LtCacheConnectionManager;
        $this->connectionManager->configHandle =$this->configHandle;
    }
 
    public function add($key, $value, $ttl = 0, $tableName)
    {
        $this->initConnection();
        return $this->connectionAdapter->add($key, $value, $ttl, $tableName, $this->connectionResource);
    }
 
    public function del($key, $tableName)
    {
        $this->initConnection();
        return $this->connectionAdapter->del($key, $tableName, $this->connectionResource);
    }
 
    public function get($key, $tableName)
    {
        $this->initConnection();
        return $this->connectionAdapter->get($key, $tableName, $this->connectionResource);
    }
 
    public function update($key, $value, $ttl = 0, $tableName)
    {
        $this->initConnection();
        return $this->connectionAdapter->update($key, $value, $ttl, $tableName, $this->connectionResource);
    }
 
    protected function initConnection()
    {
        $connectionInfo = $this->connectionManager->getConnection($this->group, $this->node, $this->role);
        $this->connectionAdapter = $connectionInfo["connectionAdapter"];
        $this->connectionResource = $connectionInfo["connectionResource"];
    }
}