本文整理汇总了PHP中redis函数的典型用法代码示例。如果您正苦于以下问题:PHP redis函数的具体用法?PHP redis怎么用?PHP redis使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了redis函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect
/**
*/
function connect($params = [])
{
if (!$this->_connection) {
$override = ['REDIS_HOST' => $this->_get_conf('REDIS_QUEUE_HOST'), 'REDIS_PORT' => $this->_get_conf('REDIS_QUEUE_PORT'), 'REDIS_PREFIX' => $this->_get_conf('REDIS_QUEUE_PREFIX')];
$this->_connection = redis($params);
$this->_connection->connect($override);
}
return $this->_connection;
}
示例2: log_action
function log_action($user, $action) {
if (!is_array($user) && strlen(number($user)) < 5)
if ($u = user($user)) $user = $u;
if (is_array($user)) $user = $user['phone'];
redis()->lpush('actions', json_encode(array(
'phone' => $user,
'action' => $action,
'time' => time(),
)));
}
示例3: gc
public function gc($max)
{
$keys = redis()->keys('sessionsphp.*');
foreach ($keys as $key) {
$expires = redis()->hget($key, 'expires');
if ($expires < time()) {
redis()->del($key);
}
}
}
示例4: connect
/**
*/
function connect($params = [])
{
if (!$this->_is_connection) {
$override = ['REDIS_HOST' => $this->_get_conf('REDIS_PUBSUB_HOST'), 'REDIS_PORT' => $this->_get_conf('REDIS_PUBSUB_PORT'), 'REDIS_PREFIX' => $this->_get_conf('REDIS_PUBSUB_PREFIX')];
$this->_connection_pub = clone redis($params);
$this->_connection_pub->connect($override);
$this->_connection_sub = clone redis($params);
$this->_connection_sub->connect($override);
}
return $this->_is_connection;
}
示例5: makeFrom
public static function makeFrom($to, $from = null)
{
$defaultLng = Config::get('application.language', DEFAULT_LANGUAGE);
$from = is_null($from) ? $defaultLng : $from;
$keys = redis()->keys('lang.' . $from . '.*');
if (count($rows)) {
foreach ($rows as $row) {
$save = redis()->get($row);
list($dummy, $from, $id) = explode('.', $row, 3);
self::getDb()->create(['key' => $id, 'language' => $to, 'translation' => $save])->save();
}
}
}
示例6: check
public function check()
{
/* CLI case */
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'production');
if ('production' == APPLICATION_ENV) {
$ip = $_SERVER['REMOTE_ADDR'];
$this->isBanned($ip);
$key = 'ip.' . str_replace('.', '', $ip) . '.' . date('dmYHi') . '.flood';
$val = redis()->incr($key);
redis()->expire($key, 60);
if ($val > Config::get('application.flood.maxPageByMinute', 30)) {
$this->checkedBanned($ip);
Api::forbidden();
}
}
}
示例7: exec
public function exec($object = false, $count = false, $first = false)
{
if (!$object) {
$hash = self::$instance->getHash($object, $count, $first);
$ageDb = self::$instance->getAge();
$key = 'dbredis.exec.' . $hash . '.' . $ageDb;
$cache = redis()->get($key);
if ($cache) {
self::$instance->reset();
return unserialize($cache);
}
$collection = call_user_func_array([static::$instance, 'exec'], func_get_args());
redis()->set($key, serialize($collection));
return $collection;
} else {
return call_user_func_array([static::$instance, 'exec'], func_get_args());
}
}
示例8: test_redis
public function test_redis()
{
$redis = redis();
$this->assertInternalType('object', $redis);
$this->assertSame($redis, _class('wrapper_redis'));
$redis->connect();
$this->assertTrue($redis->is_ready());
$key = 'mytestkey';
$val = 'mytestval';
if ($redis->get($key)) {
$this->assertEquals($redis->del($key), 1);
}
$this->assertEmpty($redis->get($key));
$this->assertTrue($redis->set($key, $val));
$this->assertEquals($redis->get($key), $val);
$this->assertEquals($redis->del($key), 1);
$this->assertEmpty($redis->get($key));
}
示例9: get
/**
* Gets the actual result when available.
* If timeout is reached before actual result is redeemed, a TimeoutException will be thrown.
* If the actual result is an Exception, that Exception will be thrown.
*
* @param $timeout
* @return mixed
* @throws TimeoutException
* @throws
*/
public function get($timeout)
{
$blpop = redis()->blpop(self::RESULT . $this->asyncId, $timeout);
if (isset($blpop[1])) {
$this->result = crypto_unserialize($blpop[1]);
} else {
throw new TimeoutException();
}
redis()->del(FUTURE_LOCK . $this->asyncId);
// remove lock
if ($this->result instanceof Exception) {
throw $this->result;
}
return $this->result;
}
示例10: _init
/**
*/
function _init()
{
$override = ['REDIS_HOST' => $this->_get_conf('REDIS_CACHE_HOST'), 'REDIS_PORT' => $this->_get_conf('REDIS_CACHE_PORT'), 'REDIS_PREFIX' => $this->_get_conf('REDIS_CACHE_PREFIX')];
$this->_connection = redis();
$this->_connection->connect($override);
}
示例11: import
public function import($file)
{
$content = redis()->get($file);
if (!$content) {
$content = 'return null;';
}
return eval($content);
}
示例12: ponterestSearch
public function ponterestSearch($rec)
{
$cached = redis()->get('pins.s.' . sha1($rec));
if (!$cached) {
$cached = file_get_contents("https://fr.pinterest.com/search/pins/?q=" . urlencode($rec));
// $cached = dwn("https://fr.pinterest.com/search/pins/?q=" . urlencode($rec) . "&term_meta[]=" . urlencode($rec) . "|typed");
redis()->set('pins.s.' . sha1($rec), $cached);
}
$data = Utils::cut('P.main.start(', '});', $cached) . '}';
$data = json_decode($data, true);
$resourceDataCache = isAke($data, 'resourceDataCache', []);
$data = isAke(current($resourceDataCache), 'data', []);
$results = isAke($data, 'results', []);
dd($results);
}
示例13: searchWd
public function searchWd($q)
{
/*https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q1631&format=json*/
$keyCache = 'wm.search.' . sha1($q);
$json = redis()->get($keyCache);
if (!$json) {
$json = file_get_contents('https://www.wikidata.org/w/api.php?action=wbsearchentities&search=' . urlencode($q) . '&language=fr&limit=20&format=json');
redis()->set($keyCache, $json);
redis()->expire($keyCache, strtotime('+6 month') - time());
}
$tab = json_decode($json, true);
dd($tab);
}
示例14: restrict
<?
restrict();
top();
?>
<h2>Users</h2>
<?
$users = redis()->hgetall('users');
function sort_users($a, $b) { return $a['name'] > $b['name']; }
usort(array_values($users), 'sort_users');
table();
foreach ($users as $user) {
$user = json_decode($user, true);
row(
format_user($user),
o($user, 'phone'),
_href('/users/' . o($user, 'phone') . '/edit', '(edit)'),
_href('javascript:if(confirm("Are you sure you want to delete ' . o($user, 'name') . '?")) window.location="/users/' . o($user, 'phone') . '/delete"', '(delete)')
);
}
endtable();
href('/users/create', 'Create New User');
bottom();
示例15: index
public function index()
{
$_GET = array_merge($_GET, $_POST);
$k = I("request.keyword");
$first = I("request.first");
// 默认搜索第一个热搜词
if (!$k && $first) {
$k = $first;
}
if ($k) {
$redis = redis();
$redis->select(1);
// var_dump($redis->keys());die;
$redis->zIncrBy('hot_search', '1', $k);
// 搜索词+1,不存在则创建
// var_dump($redis->zRange('hot_search' , 0 ,-1));die;
// var_dump($redis->zRevRange('search', 0, 5, true));//取出排名前5的搜索词
// $redis->lPushx('hotsearch' , $k);
// $redis->lpush( 'hotsearch' , $k);
$history['uid'] = 0;
$history['keyword'] = $k;
$history['add_time'] = time();
M('Search_history')->add($history);
}
// 搜索
$client = elasticsearch();
$query = array();
$cate_id = I('request.cate_id');
if ($cate_id) {
$query['must'][]['term']['cate_id'] = $cate_id;
$this->assign("cate_id", $cate_id);
}
$format = I('request.format');
if ($format) {
$query['must'][]['term']['format'] = I('post.format');
$this->assign("format", $format);
}
$preorder = I('request.preorder');
if ($preorder) {
$query['must'][]['term']['preorder'] = $preorder;
$this->assign("preorder", $preorder);
}
$released_from = I('request.released_from');
$released_to = I('request.released_to');
if ($released_from) {
$query['must'][]['range']['released'] = array('from' => $released_from, 'to' => $released_to);
$this->assign("released_from", $released_from);
$this->assign("released_to", $released_to);
}
$price_greater_than = I('request.price_greater_than');
$price_less_than = I('request.price_less_than');
if ($price_greater_than && $price_less_than) {
$query['must'][]['range']['price'] = array('from' => $price_greater_than, 'to' => $price_less_than);
$this->assign("price_greater_than", $price_greater_than);
$this->assign("price_less_than", $price_less_than);
}
$availability = I('request.availability');
if ($format) {
$query['must'][]['term']['availability'] = $availability;
$this->assign("availability", $availability);
}
if ($k) {
$querystring['query_string']['default_field'] = '_all';
$querystring['query_string']['query'] = $k;
$query['must'][] = $querystring;
}
// sort
if (I('get.sort')) {
$sort = I('get.sort');
} else {
$sort = 'default';
}
if ('default' == $sort) {
$param['sort'] = array(array('sales' => array('order' => 'desc')), array('comment' => array('order' => 'desc')), array('price' => array('order' => 'desc')));
} else {
$param['sort'] = array(array($sort => array('order' => 'desc')));
}
$p = I('get.p');
$size = '20';
if ($p) {
$form = ($p - 1) * $size;
} else {
$form = 0;
}
$param['from'] = $form;
$param['size'] = $size;
$param['query']['bool'] = $query;
//var_dump( $param );
$json = json_encode($param, true);
$params['index'] = 'ec_' . C('DB_NAME');
$params['type'] = 'ec_goods';
$params['body'] = $json;
//var_dump( $json );
$results = $client->search($params);
$page = $this->page($results['hits']['total'], $size);
$page_simple = $this->page_simple($results['hits']['total'], $size);
// 推荐商品
$lists = M('Goods')->field('id,name,price,img_url')->where('isrec=1')->limit(3)->order('id desc')->select();
$this->assign("recGoods", $lists);
$this->assign("keyword", $k);
//.........这里部分代码省略.........