PHP code example of xuepengdong / phalapiredis
1. Go to this page and download the library: Download xuepengdong/phalapiredis library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once ('vendor/autoload.php' );
xuepengdong / phalapiredis example snippets
以下为例子:
$getRedis = \PhalApi\DI()->redis->getRedis();
$getRedis->select(1 );
return $getRedis->set('key20220806' , 'value20220806' , 20000 );
\PhalApi\DI()->redis->set_forever(键名, 值, 库名);
\PhalApi\DI()->redis->get_forever(键名, 库名);
\PhalApi\DI()->redis->get_getSet(键名, 值, 库名);
$di->redis = function () {
return new \Xuepengdong\Phalapiredis\Lite(\PhalApi\DI()->config->get("app.redis.servers" ));
};
'redis' => array (
'servers' => array (
'host' => '127.0.0.1' ,
'port' => '6379' ,
'prefix' => 'PhalApi_' ,
'auth' => 'phalapi' ,
),
'DB' => array (
'developers' => 1 ,
'user' => 2 ,
'code' => 3 ,
),
'blocking' => 5 ,
),
\PhalApi\DI()->redis->set_list(数组, 库名);
例子:\PhalApi\DI()->redis->set_list(array ('key0' => 'value0' , 'key1' => 'value1' ), 'users' );
\PhalApi\DI()->redis->get_list(数组, 库名);
例子:\PhalApi\DI()->redis->get_list(array ('key0' , 'key1' ), 'users' );
\PhalApi\DI()->redis->get_time_ttl(键名, 库名);
\PhalApi\DI()->redis->get_lRange(队列键名, $start, $end);
\PhalApi\DI()->redis->get_lTrim(键名,$start, $end, 库名);
\PhalApi\DI()->redis->HSET($key, $field, $value, $tablename);
例子:\PhalApi\DI()->redis->HSET('hash1' , 'field2' , 'value2' , 1 );
\PhalApi\DI()->redis->HDEL($key, $field, $tablename);
\PhalApi\DI()->redis->HEXISTS($key, $field, $tablename);
\PhalApi\DI()->redis->HMGET($key, $field, $tablename);
备注:Redis Hmget 命令用于返回哈希表中,一个或多个给定字段的值。如果指定的字段不存在于哈希表,那么返回一个 nil 值。可以传数组
\PhalApi\DI()->redis->HGET($key, $field, $tablename);
备注:只传一个字段