<?php /* * This file is part of the Predis package. * * (c) Daniele Alessandri <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require 'SharedConfigurations.php'; // redis can set keys and their relative values in one go // using MSET, then the same values can be retrieved with // a single command using MGET. $mkv = array('usr:0001' => 'First user', 'usr:0002' => 'Second user', 'usr:0003' => 'Third user'); $client = new Predis\Client($single_server); $client->mset($mkv); $retval = $client->mget(array_keys($mkv)); print_r($retval); /* OUTPUT: Array ( [0] => First user [1] => Second user [2] => Third user ) */
return -1; } public function getScript() { return <<<LUA local cmd, insert = redis.call, table.insert local increment, results = ARGV[1], { } for idx, key in ipairs(KEYS) do if cmd('exists', key) == 1 then insert(results, idx, cmd('incrby', key, increment)) else insert(results, idx, false) end end return results LUA; } } $client = new Predis\Client($single_server); $client->getProfile()->defineCommand('increxby', 'IncrementExistingKeysBy'); $client->mset('foo', 10, 'foobar', 100); var_export($client->increxby('foo', 'foofoo', 'foobar', 50)); /* array ( 0 => 60, 1 => NULL, 2 => 150, ) */
<?php require_once 'SharedConfigurations.php'; // redis can set keys and their relative values in one go // using MSET, then the same values can be retrieved with // a single command using MGET. $mkv = array('usr:0001' => 'First user', 'usr:0002' => 'Second user', 'usr:0003' => 'Third user'); $redis = new Predis\Client($single_server); $redis->mset($mkv); $retval = $redis->mget(array_keys($mkv)); print_r($retval); /* OUTPUT: Array ( [0] => First user [1] => Second user [2] => Third user ) */
/* * This file is part of the Predis package. * * (c) Daniele Alessandri <*****@*****.**> * * For the full copyright and license info, please view the LICENSE * file that was distributed with this source code. */ require 'SharedConfigurations.php'; // Predis ships with a KeyPrefixProcessor class that is used to transparently // prefix each key before sending commands to Redis, even for complex commands // such as SORT, ZUNIONSTORE and ZINTERSTORE. Key prefixes are useful to create // user-level namespaces for you keyspace, thus eliminating the need for separate // logical databases. $client = new Predis\Client($single_server, array('prefix' => 'nrk:')); $client->mset(array('foo' => 'bar', 'lol' => 'wut')); var_dump($client->mget('foo', 'lol')); /* array(2) { [0]=> string(3) "bar" [1]=> string(3) "wut" } */ var_dump($client->keys('*')); /* array(2) { [0]=> string(7) "nrk:foo" [1]=> string(7) "nrk:lol" } */
use Aws\S3\S3Client; $redis = new Predis\Client(getenv('REDIS_URL')); $s3 = new S3Client(['version' => S3_VERSION, 'region' => S3_REGION]); $message = ""; if (!empty($_POST['submit'])) { if (!empty($_FILES["uploadfile"])) { $filename = $_FILES["uploadfile"]["name"]; $file = $_FILES["uploadfile"]["tmp_name"]; $filetype = $_FILES["uploadfile"]["type"]; $filesize = $_FILES["uploadfile"]["size"]; $filedata = file_get_contents($file); $bucket = $_POST['bucket']; // insert into redis use base64 $base64 = base64_encode(file_get_contents($file)); $filekey = $filename . DATA_SEPARATOR . $filetype . DATA_SEPARATOR . $filesize . DATA_SEPARATOR . time() . DATA_SEPARATOR . $bucket; $redis->mset($filekey, $base64); // create or update imagelist.txt if ($s3->doesObjectExist(S3_BUCKET, IMAGELIST_FILE)) { // exsist $txtfile = $s3->getObject(['Bucket' => S3_BUCKET, 'Key' => IMAGELIST_FILE]); $txtbody = $txtfile['Body'] . $filekey . PHP_EOL; try { $s3->deleteObject(['Bucket' => S3_BUCKET, 'Key' => IMAGELIST_FILE]); $s3->putObject(['Bucket' => S3_BUCKET, 'Key' => IMAGELIST_FILE, 'Body' => $txtbody, 'ACL' => 'public-read-write']); } catch (Aws\Exception\S3Exception $e) { $message .= "There was an error deleting and creating imagelist.txt.\r\n"; } } else { // create imagelist.txt try { $s3->putObject(['Bucket' => S3_BUCKET, 'Key' => IMAGELIST_FILE, 'Body' => $filekey . PHP_EOL, 'ACL' => 'public-read-write']);