xn_assert('b->count("+2")', $r == 2); $arr = $b->get(2); xn_assert('b->get("+2")', count($arr) == 2); $list = $b->index_fetch($cond = array(), $orderby = array('uid' => -1), 0, $pagesize = 30); print_r($list); // ---------------------> 测试主键包含多列字段的情况, 实例 primary key(fid, user) $b = new base_model(); $b->db->query(" DROP TABLE IF EXISTS `xn_mblog`"); $b->db->query("\n\t CREATE TABLE `xn_mblog` ( \n `fid` int(11) unsigned NOT NULL default '0', \n `blogid` int(11) unsigned NOT NULL default '0', \n `uid` int(11) unsigned NOT NULL default '0', \n `dateline` int(11) unsigned NOT NULL default '0', \n `subject` char(80) NOT NULL default '', \n `message` longtext NOT NULL, \n `username` char(16) NOT NULL default '', \n `isprivate` tinyint(4) NOT NULL default '0', \n PRIMARY KEY (`fid`, `blogid`), \n KEY `uidblogid` (`uid`,`blogid`) \n ) ENGINE=MyISAM AUTO_INCREMENT=24 DEFAULT CHARSET=utf8 \n"); $b->table = 'mblog'; $b->primarykey = array('fid', 'blogid'); $b->cacheconf['enable'] = FALSE; $n = $b->count(0); xn_assert('b->count(0)', $n == 0); $m = $b->maxid(0); xn_assert('b->maxid(0)', $m == 0); $m = $b->maxid('+1'); xn_assert('b->maxid(\'+1\')', $m == 1); $r = $b->set(1, 1, array('subject' => 'this is subject 111 .', 'message' => 'this is message 111')); xn_assert('b->set(1)', $r); $m = $b->maxid('+1'); xn_assert('b->maxid(\'+1\')', $m == 2); $r = $b->set(1, 2, array('subject' => 'this is subject 222 .', 'message' => 'this is message 222')); xn_assert('b->set(2)', $r); $r = $b->count('+2'); $r = $b->count('+2'); xn_assert('b->count("+2")', $r == 4); $arr = $b->get(1, 2); xn_assert('b->get("+2")', count($arr) == 2); $list = $b->index_fetch($cond = array('fid' => 1), $orderby = array('uid' => -1), 0, $pagesize = 30); print_r($list);
xn_assert("count('user', 0)", $r == 0); // 增加一条记录: $uid = $cache->maxid('user', '+1'); xn_assert("maxid('user', '+1')", $uid == 1); $r = $cache->set("user-uid-{$uid}", array('username' => 'admin1', 'email' => '*****@*****.**')); xn_assert("set('user-uid-{$uid}', array())", $r == TRUE); // 增加一条记录: $uid = $cache->maxid('user', '+1'); $r = $cache->set("user-uid-{$uid}", array('username' => 'admin1', 'email' => '*****@*****.**')); // 增加一条记录: $uid = $cache->maxid('user', '+1'); $r = $cache->set("user-uid-{$uid}", array('username' => 'admin1', 'email' => '*****@*****.**')); $n = $cache->count('user', '+3'); // 取一条记录 $arr = $cache->get('user-uid-1'); xn_assert("maxid('user', '+1')", !empty($arr) && $arr['username'] == 'admin1'); // 删除 $r = $cache->delete("user-uid-1"); xn_assert("delete('user-uid-1')", $r == TRUE); $n = $cache->count('user', '-1'); // 删除以后的总数,maxid 删除以后不变 $n = $cache->count('user'); xn_assert("count('user')", $n == 2); // 通过最大ID进行遍历 $uids = array(); $maxid = $cache->maxid('user'); for ($i = 0; $i < $maxid; $i++) { $uids[] = "user-uid-{$i}"; } $userlist = $cache->get($uids); print_r($userlist);