PHP code example of ienaga / phalcon-redis-plugin

1. Go to this page and download the library: Download ienaga/phalcon-redis-plugin 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');

/* Start to develop here. Best regards https://php-download.com/ */

    

ienaga / phalcon-redis-plugin example snippets


$loader = new Phalcon\Config\Adapter\Yaml\Loader();
return $loader
    ->setIgnore(["routing"]) // ignore yml names
    ->setEnvironment("stg") // default dev
    ->setBasePath(realpath(dirname(__FILE__) . "/../.."))
    ->load();

/**
 * Database connection is created based in the parameters defined in the configuration file
 */
$dbService = new \Phalcon\Mvc\Model\Adapter\Redis\Service();
$dbService->registration();

/**
 * If the configuration specify the use of metadata adapter use it or use memory otherwise
 */
$di->setShared('modelsMetadata', function () {
    return new \Phalcon\Mvc\Model\Adapter\Redis\Metadata\Redis(
        $this->getConfig()
            ->get("redis")
            ->get("metadata")
            ->toArray()
    );
});

class Robot extends \Phalcon\Mvc\Model\Adapter\Redis\Model {}

# findFirst
$robot = Robot::criteria()
    ->add('id', $id)
    ->add('type', $type, Criteria::NOT_EQUAL)
    ->group('type')
    ->findFirst();

class Robot extends \Phalcon\Mvc\Model\Adapter\Redis\Model {}

$robot = Robot::criteria()
    ->add('id', array($id), Criteria::IN)
    ->add('type', array($start, $end), Criteria::BETWEEN)
    ->limit(10, 5) // limit, offset
    ->order('type DESC')
    ->find();

class Robot extends \Phalcon\Mvc\Model\Adapter\Redis\Model {}

$robot = Robot::criteria()
    ->add('id', array($id), Criteria::IN)
    ->add('type', array($start, $end), Criteria::BETWEEN)
    ->limit(10, 30)
    ->order('type DESC')
    ->cache(false)
    ->find();

class Robot extends \Phalcon\Mvc\Model\Adapter\Redis\Model {}

$robot = Robot::criteria()
    ->add('id', array($id), Criteria::IN)
    ->add('type', array($start, $end), Criteria::BETWEEN)
    ->limit(10, 30)
    ->order('type DESC')
    ->autoIndex(false)
    ->find();

class UserItem extends \Phalcon\Mvc\Model\Adapter\Redis\Model {}

$userItem = new UserItem();
$userItem->setId($id);
$userItem->setType($type);
$userItem->save();


class Robot extends \Phalcon\Mvc\Model\Adapter\Redis\Model {}

Robot::criteria()
    ->add("user_status", 1)
    ->add("power", 100)
    ->set("status", 2)
    ->set("name", "robot")
    ->update();

class Robot extends \Phalcon\Mvc\Model\Adapter\Redis\Model {}

Robot::criteria()
    ->add("user_status", 1)
    ->add("power", 100, Robot::GREATER_EQUAL)
    ->delete();

class Robot extends \Phalcon\Mvc\Model\Adapter\Redis\Model {}

$count = Robot::criteria()
    ->add("user_status", 1)
    ->add("power", 100)
    ->add("status", 2)
    ->count();

class Robot extends \Phalcon\Mvc\Model\Adapter\Redis\Model {}

$sum = Robot::criteria()
    ->add("user_status", 1)
    ->sum("price");

class Robot extends \Phalcon\Mvc\Model\Adapter\Redis\Model {}

$robot = Robot::criteria()
    ->limit(10)
    ->add("type", $type)
    ->addGroup("type")
    ->addOrder("id", "DESC")
    ->add("status", $status)
    ->add("id", $id)
    ->find();

class Robot extends \Phalcon\Mvc\Model\Adapter\Redis\Model {}

$robot = Robot::criteria()
    ->limit(10)
    ->add("type", $type)
    ->addGroup("type")
    ->addOrder("id", "DESC")
    ->add("status", $status)
    ->add("id", $id)
    ->test(true)
    ->find();

class Robot extends \Phalcon\Mvc\Model\Adapter\Redis\Model {}

\RedisPlugin\Mvc\Model::test(true);

$robot = Robot::criteria()
    ->limit(10)
    ->add("type", $type)
    ->addGroup("type")
    ->addOrder("id", "DESC")
    ->add("status", $status)
    ->add("id", $id)
    ->find();
linux
sudo yum install libyaml libyaml-devel php-pecl-yaml php-pecl-redis
mysql
UPDATE `robot` SET `status` = 2, `name` = "robot" WHERE `user_status` = 1 AND `power` = 100;