Example #1
0
<?php

/**
 * Author: jellycheng <*****@*****.**>
 * Date: 2015/11/11
 * Desc: 
 */
header("Content-type: text/html; charset=utf-8");
require dirname(__DIR__) . '/vendor/autoload.php';
//设置用户信息
$userinfo = array('userid' => 123456, 'phone' => '13712345678', 'nickname' => '租888借');
$bool = \JellyRedis\Redis\Redis::set("user", "userinfo:123456", json_encode($userinfo));
//获取缓存用户组信息
$res = \JellyRedis\Redis\Redis::get("user", "userinfo:123456");
var_dump($res);
echo "<br>";
Example #2
0
<?php

/**
 * Author: jellycheng <*****@*****.**>
 * Date: 2015/11/11
 * Desc: 
 */
header("Content-type: text/html; charset=utf-8");
require dirname(__DIR__) . '/vendor/autoload.php';
$res = \JellyRedis\Redis\Redis::get("auth", "key1");
var_dump($res);
Example #3
0
<?php

/**
 * Author: jellycheng <*****@*****.**>
 * Date: 2015/11/11
 * Desc: 
 */
header("Content-type: text/html; charset=utf-8");
require dirname(__DIR__) . '/vendor/autoload.php';
//设置用户信息
$userinfo = array('userid' => 88, 'phone' => '13712345678', 'nickname' => '租八借');
$bool = \JellyRedis\Redis\Redis::set("user", "userinfo:" . $userinfo['userid'], json_encode($userinfo));
var_export($bool);
echo "<br>";
echo "aaz:user:userinfo:" . $userinfo['userid'] . "的有效期(-1表永久,-2key不存在,单位秒): " . \JellyRedis\Redis\Redis::ttl('user', 'userinfo:' . $userinfo['userid']);
echo "<br>";
echo "aaz:user:abc的有效期(-1表永久,-2key不存在,单位秒): " . \JellyRedis\Redis\Redis::ttl('user', 'abc');
echo "<br>";
$i = mt_rand(1000, 9999);
//设置有效期 EXPIRE key seconds
\JellyRedis\Redis\Redis::set('user', 'jelly' . $i, "jelly nickname");
\JellyRedis\Redis\Redis::EXPIRE('user', 'jelly' . $i, 90);
echo "jelly" . $i . "的有效期(-1表永久,-2key不存在,单位秒): " . \JellyRedis\Redis\Redis::ttl('user', 'jelly' . $i);
echo "<br>";
echo "dbsize: " . \JellyRedis\Redis\Redis::dbsize('user');
echo "<br>";
$obj = \JellyRedis\Redis\Redis::getInstance('user');
$keys = $obj->keys('*');
echo "<pre>user组服务器,所有key:";
var_export($keys);
Example #4
0
<?php

/**
 * Author: jellycheng <*****@*****.**>
 * Date: 2015/11/11
 * Desc: 
 */
header("Content-type: text/html; charset=utf-8");
require __DIR__ . '/vendor/autoload.php';
//备注: 所有方法的第1个参数一定是业务组代号,如果业务组代号不存在或者其它参数错误,均返回空
$res = \JellyRedis\Redis\Redis::get();
//参数错误写法,但不会出现错误,返回空
echo "参数错误写法,但不会出现错误,返回空: ";
var_dump($res);
//一定是空
echo "<br>";
echo "传入不存在的组,也不会直接影响业务,结果一直返回空: ";
$res = \JellyRedis\Redis\Redis::set("group", "key1", "val1");
var_dump($res);
echo "<br>";
//获取不存在组的情况,一直返回空
echo "获取不存在组的情况,一直返回空: ";
$res = \JellyRedis\Redis\Redis::get("group", "key1");
var_dump($res);
echo "<br>";
//获取缓存用户组信息
$res = \JellyRedis\Redis\Redis::get("user", "userinfo:123456");
var_dump($res);
echo "<br>";
echo "dbsize: " . \JellyRedis\Redis\Redis::dbsize('user');
echo "<br>";
Example #5
0
<?php

/**
 * Author: jellycheng <*****@*****.**>
 * Date: 2015/11/11
 * Desc: 
 */
header("Content-type: text/html; charset=utf-8");
require dirname(__DIR__) . '/vendor/autoload.php';
$i = mt_rand(100, 999);
//开启事物
$multi = \JellyRedis\Redis\Redis::multi('user');
//获取组的key前缀
$prefix = \JellyRedis\Redis\Redis::getKeyPrefix('user');
$multi->set($prefix . 'abc', '123-' . $i);
$multi->set($prefix . 'xyz', '1234xyz-' . $i);
$multi->exec();
echo "事物演示完毕";
Example #6
0
 /**
  * 获取队列长度
  * @param $group redis配置组
  * @param $subKey 队列后缀
  * @return mixed
  */
 public static function getQueueLen($group, $subKey)
 {
     return \JellyRedis\Redis\Redis::LLEN($group, $subKey);
 }