/** * 批量删除键值 * @param array $keys 键名数组 * @return boolean 是否成功 */ public function mDel($keys) { try { $timeKeys = []; foreach ($keys as $key) { $timeKeys[] = self::timeKey($key); } $ret = $this->handler->multi_del(array_merge($keys, $timeKeys)); if ($ret > 0) { return true; } elseif ($ret === 0) { $hasKeys = $this->mHas($keys); //在 PHP 5.5 之前,empty() 仅支持变量;任何其他东西将会导致一个解析错误 if (empty($hasKeys) && is_array($hasKeys)) { return true; } } return false; } catch (SSDBException $ex) { self::exception($ex); //连接状态置为false $this->isConnected = false; } return false; }
/** * 批量删除键值 * @param array $keys 键名数组 * @return boolean 是否成功 */ public function mDel($keys) { try { $ret = $this->handler->multi_del($keys); if ($ret !== false || $ret === 0 && empty($this->mHas($keys))) { return true; } return false; } catch (SSDBException $ex) { self::exception($ex); //连接状态置为false $this->isConnected = false; } return false; }
function KVStorageConnect($host, $port, $pwd, $name) { global $ssdb; global $ssdb_prefix; if (empty($ssdb) == TRUE) { try { $ssdb = new SimpleSSDB($host, $port); if (empty($pwd) == FALSE) { $ssdb->auth(SSDB_PWD); } $ssdb_prefix = $name . '_'; return $ssdb; } catch (SSDBException $e) { if (DEBUG == TRUE) { die('KVStorageConnect Error: ' . $e->getMessage()); } } return FALSE; } return $ssdb; }
<?php require_once "SSDB.php"; $ssdb = new SimpleSSDB('127.0.0.1', 8888); $DATA_LEN = 100 * 1024; $str = str_pad('', $DATA_LEN); $resp = $ssdb->set('key', $str); $keys = array('seq' => array()); for ($i = 0; $i < 1000; $i++) { $key = sprintf('%010s', $i); $keys['seq'][] = $key; } $REQUESTS = 1000; $stime = 0; $etime = 0; start(); foreach ($keys['seq'] as $key) { $resp = $ssdb->set($key, $str); } output('writeseq'); $ks = $keys['seq']; shuffle($ks); start(); foreach ($ks as $key) { $resp = $ssdb->set($key, $str); } output('writerand'); start(); foreach ($keys['seq'] as $key) { $resp = $ssdb->get($key); if (strlen($resp) != $DATA_LEN) {
<?php include "./SSDB.php"; $pid = '49194475'; $proKey = "gc:prodesc:" . $pid; $ssdb = new SimpleSSDB("192.168.2.188", "8887"); $rs = $ssdb->get($proKey); var_dump($rs);
<?php /** * Copyright (c) 2012, ideawu * All rights reserved. * @author: ideawu * @link: http://www.ideawu.com/ * * SSDB PHP API demo. */ include dirname(__FILE__) . '/SSDB.php'; $host = '127.0.0.1'; $port = 8888; try { $ssdb = new SimpleSSDB($host, $port); //$ssdb->easy(); } catch (Exception $e) { die(__LINE__ . ' ' . $e->getMessage()); } var_dump($ssdb->set('test', time())); var_dump($ssdb->set('test', time())); echo $ssdb->get('test') . "\n"; var_dump($ssdb->del('test')); var_dump($ssdb->del('test')); var_dump($ssdb->get('test')); echo "\n"; var_dump($ssdb->hset('test', 'b', time())); var_dump($ssdb->hset('test', 'b', time())); echo $ssdb->hget('test', 'b') . "\n"; var_dump($ssdb->hdel('test', 'b')); var_dump($ssdb->hdel('test', 'b'));