1、connect:
1 <?php 2 3 $Redis = new \Redis(); 4 $result = $Redis->connect(‘127.0.0.1‘, 6379); 5 var_dump($result); // boolean true
2、set:
1 <?php 2 3 $Redis = new \Redis(); 4 $Redis->connect(‘127.0.0.1‘, 6379); 5 $result = $Redis->set(‘test‘, date(‘Y-m-d H:i:s‘, time())); 6 var_dump($result); // boolean true
3、get:
1 <?php 2 3 $Redis = new \Redis(); 4 $Redis->connect(‘127.0.0.1‘, 6379); 5 $result = $Redis->get(‘test‘); 6 var_dump($result); // string ‘2015-10-27 14:09:20‘ (length=19)
4、delete:
1 <?php 2 3 $Redis = new \Redis(); 4 $Redis->connect(‘127.0.0.1‘, 6379); 5 $Redis->set(‘test‘, date(‘Y-m-d H:i:s‘, time())); 6 var_dump($Redis->get(‘test‘)); // string ‘2015-10-27 14:13:34‘ (length=19) 7 $Redis->delete(‘test‘); 8 var_dump($Redis->get(‘tesst‘)); // boolean false
5、setnx:
1 <?php 2 3 $Redis = new \Redis(); 4 $Redis->connect(‘127.0.0.1‘, 6379); 5 $Redis->set(‘test‘, date(‘Y-m-d H:i:s‘, time())); 6 $Redis->set(‘test‘, date(‘Y-m-d‘, time())); 7 var_dump($Redis->get(‘test‘)); // string ‘2015-10-27‘ (length=10) 8 $Redis->delete(‘test‘); 9 $Redis->setnx(‘test‘, ‘this is a test‘); 10 var_dump($Redis->get(‘test‘)); // string ‘this is a test‘ (length=14)
6、exists:
1 <?php 2 3 $Redis = new \Redis(); 4 $Redis->connect(‘127.0.0.1‘, 6379); 5 $Redis->set(‘test‘, date(‘Y-m-d H:i:s‘, time())); 6 var_dump($Redis->exists(‘test‘)); // boolean true
7、incr:
1 <?php 2 3 $Redis = new \Redis(); 4 $Redis->connect(‘127.0.0.1‘, 6379); 5 $Redis->set(‘test‘, 1001); 6 var_dump($Redis->incr(‘test‘)); // int 1002 7 var_dump($Redis->incr(‘test‘)); // int 1003
8、decr:
1 <?php 2 3 $Redis = new \Redis(); 4 $Redis->connect(‘127.0.0.1‘, 6379); 5 $Redis->set(‘test‘, 1001); 6 var_dump($Redis->decr(‘test‘)); // int 1000 7 var_dump($Redis->decr(‘test‘)); // int 999
9、getMultiple:
1 <?php 2 3 $Redis = new \Redis(); 4 $Redis->connect(‘127.0.0.1‘, 6379); 5 $Redis->set(‘test1‘, 1001); 6 $Redis->set(‘test2‘, 1002); 7 $result = $Redis->getMultiple(array(‘test1‘, ‘test2‘)); 8 var_dump($result); 9 10 /** 11 * 运行结果: 12 * 13 * array (size=2) 14 * 0 => string ‘1001‘ (length=4) 15 * 1 => string ‘1002‘ (length=4) 16 */
10、
11、
12、
时间: 2024-10-31 23:33:57