Exemplo n.º 1
0
 public function testScalars()
 {
     // Basic get/set
     $this->credis->set('foo', 'FOO');
     $this->assertEquals('FOO', $this->credis->get('foo'));
     $this->assertFalse($this->credis->get('nil'));
     // Empty string
     $this->credis->set('empty', '');
     $this->assertEquals('', $this->credis->get('empty'));
     // UTF-8 characters
     $utf8str = str_repeat("quarter: ¼, micro: µ, thorn: Þ, ", 500);
     $this->credis->set('utf8', $utf8str);
     $this->assertEquals($utf8str, $this->credis->get('utf8'));
     // Array
     $this->assertTrue($this->credis->mSet(array('bar' => 'BAR', 'apple' => 'red')));
     $mGet = $this->credis->mGet(array('foo', 'bar', 'empty'));
     $this->assertTrue(in_array('FOO', $mGet));
     $this->assertTrue(in_array('BAR', $mGet));
     $this->assertTrue(in_array('', $mGet));
     // Non-array
     $mGet = $this->credis->mGet('foo', 'bar');
     $this->assertTrue(in_array('FOO', $mGet));
     $this->assertTrue(in_array('BAR', $mGet));
     // Delete strings, null response
     $this->assertEquals(2, $this->credis->del('foo', 'bar'));
     $this->assertFalse($this->credis->get('foo'));
     $this->assertFalse($this->credis->get('bar'));
     // Long string
     $longString = str_repeat(md5('asd'), 4096);
     // 128k (redis.h REDIS_INLINE_MAX_SIZE = 64k)
     $this->assertTrue($this->credis->set('long', $longString));
     $this->assertEquals($longString, $this->credis->get('long'));
 }
Exemplo n.º 2
0
 public function testConnectionStrings()
 {
     $this->credis->close();
     $this->credis = new Credis_Client('tcp://' . $this->config[0]->host . ':' . $this->config[0]->port);
     $this->assertEquals($this->credis->getHost(), $this->config[0]->host);
     $this->assertEquals($this->credis->getPort(), $this->config[0]->port);
     $this->credis = new Credis_Client('tcp://' . $this->config[0]->host);
     $this->assertEquals($this->credis->getPort(), $this->config[0]->port);
     $this->credis = new Credis_Client('tcp://' . $this->config[0]->host . ':' . $this->config[0]->port . '/abc123');
     $this->assertEquals('abc123', $this->credis->getPersistence());
     $this->credis = new Credis_Client(realpath(__DIR__) . '/redis.sock', 0, null, 'persistent');
     $this->credis->connect();
     $this->credis->set('key', 'value');
     $this->assertEquals('value', $this->credis->get('key'));
 }
 /**
  * 根据ID获得对应的缓存值
  * @param string $id
  * @return mixed
  */
 public function get($id)
 {
     $key = $this->_getKeyName($id);
     return unserialize($this->_client->get($key));
 }
Exemplo n.º 4
0
Arquivo: credis.php Projeto: yfix/yf
#!/usr/bin/php
<?php 
$config = ['git_urls' => ['https://github.com/colinmollenhour/credis.git' => 'credis/'], 'require_once' => ['credis/Client.php', 'credis/Cluster.php', 'credis/Sentinel.php'], 'example' => function () {
    $client = new Credis_Client(getenv('REDIS_HOST') ?: '127.0.0.1', getenv('REDIS_PORT') ?: 6379);
    $client->set('testme_key', 'testme_val');
    $value = $client->get('testme_key');
    print ($value == 'testme_val' ? 'OK' : 'ERROR') . PHP_EOL;
}];
if ($return_config) {
    return $config;
}
require_once __DIR__ . '/_yf_autoloader.php';
new yf_autoloader($config);
require_once __DIR__ . '/vendor/autoload.php';
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Guzzle\Http\Client;
$app = new Application();
$app['debug'] = true;
$app->get('/load', function (Request $request) use($app) {
    $data = verifySignedRequest($request->get('signed_payload'));
    if (empty($data)) {
        return 'Invalid signed_payload.';
    }
    $redis = new Credis_Client('localhost');
    $key = getUserKey($data['store_hash'], $data['user']['email']);
    $user = json_decode($redis->get($key), true);
    if (empty($user)) {
        return 'Invalid user.';
    }
    return 'Welcome ' . json_encode($user);
});
$app->get('/auth/callback', function (Request $request) use($app) {
    $payload = array('client_id' => clientId(), 'client_secret' => clientSecret(), 'redirect_uri' => callbackUrl(), 'grant_type' => 'authorization_code', 'code' => $request->get('code'), 'scope' => $request->get('scope'), 'context' => $request->get('context'));
    $client = new Client(bcAuthService());
    $req = $client->post('/oauth2/token', array(), $payload, array('exceptions' => false));
    $resp = $req->send();
    if ($resp->getStatusCode() == 200) {
        $data = $resp->json();
        list($context, $storeHash) = explode('/', $data['context'], 2);
        $key = getUserKey($storeHash, $data['user']['email']);
        $redis = new Credis_Client('localhost');