本文整理汇总了PHP中Redis::sAdd方法的典型用法代码示例。如果您正苦于以下问题:PHP Redis::sAdd方法的具体用法?PHP Redis::sAdd怎么用?PHP Redis::sAdd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Redis
的用法示例。
在下文中一共展示了Redis::sAdd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: it_can_sadd
public function it_can_sadd()
{
$this->redis->sAdd('test', 'test')->shouldBeCalled();
$this->sAdd('test', ['test']);
$this->redis->sAdd('test', 'test')->willThrow(new \RedisException());
$this->shouldThrow(DriverException::class)->during('sAdd', ['test', ['test']]);
}
示例2: gauge
/**
* @inheritdoc
*/
public function gauge($bucket, $value)
{
$time = $this->syncedTime();
$granularities = $this->getGranularities();
foreach ($granularities as $granularity => $settings) {
$key = $this->getKey($bucket, 'gauges', $granularity, $settings, $time);
$field = $this->getField($settings, $time);
$this->redis->hSet($key, $field, $value);
$this->redis->expireAt($key, $time + $settings['ttl']);
}
$this->redis->sAdd('buckets', $bucket);
$this->redis->sAdd(sprintf('types:%s', $bucket), 'gauges');
}
示例3: set
/**
* Saves data in the cache.
*
* @param string $entryIdentifier An identifier for this specific cache entry
* @param string $data The data to be stored
* @param array $tags Tags to associate with this cache entry. If the backend does not support tags, this option can be ignored.
* @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
* @throws \RuntimeException
* @return void
* @api
*/
public function set($entryIdentifier, $data, array $tags = [], $lifetime = null)
{
if ($this->isFrozen()) {
throw new \RuntimeException(sprintf('Cannot add or modify cache entry because the backend of cache "%s" is frozen.', $this->cacheIdentifier), 1323344192);
}
if ($lifetime === null) {
$lifetime = $this->defaultLifetime;
}
$setOptions = [];
if ($lifetime > 0) {
$setOptions['ex'] = $lifetime;
}
$this->redis->multi();
$result = $this->redis->set($this->buildKey('entry:' . $entryIdentifier), $this->compress($data), $setOptions);
if (!$result instanceof \Redis) {
$this->verifyRedisVersionIsSupported();
}
$this->redis->lRem($this->buildKey('entries'), $entryIdentifier, 0);
$this->redis->rPush($this->buildKey('entries'), $entryIdentifier);
foreach ($tags as $tag) {
$this->redis->sAdd($this->buildKey('tag:' . $tag), $entryIdentifier);
$this->redis->sAdd($this->buildKey('tags:' . $entryIdentifier), $tag);
}
$this->redis->exec();
}
示例4: testsGetMembers
public function testsGetMembers()
{
$this->redis->delete('set');
$this->redis->sAdd('set', 'val');
$this->redis->sAdd('set', 'val2');
$this->redis->sAdd('set', 'val3');
$array = array('val', 'val2', 'val3');
$this->assertEquals($array, $this->redis->sGetMembers('set'));
}
示例5: addLink
/**
* @param $siteUrl
* @param $link
* @param array $data
*/
public function addLink($siteUrl, $link, array $data)
{
if (!$this->siteUrl) {
$this->siteUrl = $siteUrl;
}
$data['link'] = $link;
$this->redis->sAdd($this->getSiteKey($siteUrl), $link);
$this->redis->hMset($this->getPageKey($siteUrl, $link), $data);
}
示例6: save
/**
* Save cache.
*
* @param string $id Cache ID
* @param mixed $data Data to save
* @param int $ttl Time to live in seconds
* @param bool $raw Whether to store the raw value (unused)
*
* @return bool TRUE on success, FALSE on failure
*/
public function save($id, $data, $ttl = 60, $raw = false)
{
if (is_array($data) or is_object($data)) {
if (!$this->_redis->sIsMember('_ci_redis_serialized', $id) && !$this->_redis->sAdd('_ci_redis_serialized', $id)) {
return false;
}
isset($this->_serialized[$id]) or $this->_serialized[$id] = true;
$data = serialize($data);
} elseif (isset($this->_serialized[$id])) {
$this->_serialized[$id] = null;
$this->_redis->sRemove('_ci_redis_serialized', $id);
}
return $this->_redis->set($id, $data, $ttl);
}
示例7: hsave
/**
* hSave cache
*
* @param string $id Cache ID
* @param mixed $data Data to save
* @param int $ttl Time to live in seconds
* @param bool $raw Whether to store the raw value (unused)
* @return bool TRUE on success, FALSE on failure
*/
public function hsave($id, $key, $data)
{
if (is_array($data) or is_object($data)) {
if (!$this->_redis->sIsMember('_ci_redis_serialized', $id) && !$this->_redis->sAdd('_ci_redis_serialized', $id)) {
return FALSE;
}
isset($this->_serialized[$id]) or $this->_serialized[$id] = TRUE;
$data = base64_encode(serialize($data));
} elseif (isset($this->_serialized[$id])) {
$this->_serialized[$id] = NULL;
$this->_redis->sRemove('_ci_redis_serialized', $id);
}
return $this->_redis->hSet($id, $key, $data);
}
示例8: register
/**
* @param string $key
* @param int $number
* @param int $ttl
* @return int
*/
public function register($key, $number = -1, $ttl = 0)
{
Assertion::notNull(self::$redis, "Redis connection hasn't been set");
Assertion::string($key, "Number key must be a string");
Assertion::notEq($key, "", "Number key must be a non empty string");
Assertion::integer($number, "Temporal numbers must be integers");
Assertion::notEq($number, 0, "Temporal numbers must be integers different from zero");
Assertion::integer($ttl, "Time to live (ttl) must be an integer");
Assertion::true($ttl >= 0, "Time to live (ttl) must be strictly greater than zero");
$key = $this->identifier . "::" . $key;
self::$redis->sAdd($this->identifier, $key);
$ttl == 0 ? self::$redis->set($key, $number) : self::$redis->set($key, $number, $ttl);
return $this->getCurrentNumber();
}
示例9: save
/**
* Save cache
*
* @param string $id Cache ID
* @param mixed $data Data to save
* @param int $ttl Time to live in seconds
* @param bool $raw Whether to store the raw value (unused)
* @return bool TRUE on success, FALSE on failure
*/
public function save($id, $data, $ttl = 60, $raw = FALSE)
{
if (is_array($data) or is_object($data)) {
if (!$this->_redis->sIsMember('_ci_redis_serialized', $id) && !$this->_redis->sAdd('_ci_redis_serialized', $id)) {
return FALSE;
}
isset($this->_serialized[$id]) or $this->_serialized[$id] = TRUE;
$data = serialize($data);
} elseif (isset($this->_serialized[$id])) {
$this->_serialized[$id] = NULL;
$this->_redis->sRemove('_ci_redis_serialized', $id);
}
return $this->_redis->set($id, $data, $ttl);
}
示例10: save
/**
* Save cache
*
* @param string $id Cache ID
* @param mixed $data Data to save
* @param int $ttl Time to live in seconds
* @param bool $raw Whether to store the raw value (unused)
* @return bool TRUE on success, FALSE on failure
*/
public function save($id, $data, $ttl = 60, $raw = FALSE)
{
// //Tim
// if(!$this->is_supported())
// {
// return false;
// }
if (is_array($data) or is_object($data)) {
if (!$this->_redis->sIsMember('_ci_redis_serialized', $id) && !$this->_redis->sAdd('_ci_redis_serialized', $id)) {
return FALSE;
}
isset($this->_serialized[$id]) or $this->_serialized[$id] = TRUE;
$data = serialize($data);
} elseif (isset($this->_serialized[$id])) {
$this->_serialized[$id] = NULL;
$this->_redis->sRemove('_ci_redis_serialized', $id);
}
return $ttl ? $this->_redis->setex($id, $ttl, $data) : $this->_redis->set($id, $data);
}
示例11: set
/**
* Saves data in the cache.
*
* @param string $entryIdentifier An identifier for this specific cache entry
* @param string $data The data to be stored
* @param array $tags Tags to associate with this cache entry. If the backend does not support tags, this option can be ignored.
* @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
* @throws \RuntimeException
* @return void
* @api
*/
public function set($entryIdentifier, $data, array $tags = array(), $lifetime = NULL)
{
if ($this->isFrozen()) {
throw new \RuntimeException(sprintf('Cannot add or modify cache entry because the backend of cache "%s" is frozen.', $this->cacheIdentifier), 1323344192);
}
if ($lifetime === NULL) {
$lifetime = $this->defaultLifetime;
}
$setOptions = array();
if ($lifetime > 0) {
$setOptions['ex'] = $lifetime;
}
$this->redis->multi();
$this->redis->set($this->buildKey('entry:' . $entryIdentifier), $data, $setOptions);
$this->redis->rPush($this->buildKey('entries'), $entryIdentifier);
foreach ($tags as $tag) {
$this->redis->sAdd($this->buildKey('tag:' . $tag), $entryIdentifier);
$this->redis->sAdd($this->buildKey('tags:' . $entryIdentifier), $tag);
}
$this->redis->exec();
}
示例12: array
$redis->connect('127.0.0.1');
$redis->select(2);
// HSET
for ($i = 0; $i <= rand(1000, 10000); $i++) {
$incr = $redis->incr('test:incr:hset');
$data = array();
for ($j = 0; $j <= rand(10, 500); $j++) {
$data['field' . $j] = md5($j);
}
$redis->hMset('test:' . $incr . ':hset', $data);
}
// SET
for ($i = 0; $i <= rand(1000, 10000); $i++) {
$incr = $redis->incr('test:incr:set');
for ($j = 0; $j <= rand(10, 100); $j++) {
$redis->sAdd('test:' . $incr . ':set', $j);
}
}
// LIST
for ($i = 0; $i <= rand(1000, 10000); $i++) {
$incr = $redis->incr('test:incr:list');
for ($j = 0; $j <= rand(10, 100); $j++) {
$redis->rPush('test:' . $incr . ':list', $j);
}
}
// STRING
for ($i = 0; $i <= rand(1000, 10000); $i++) {
$incr = $redis->incr('test:incr:string');
for ($j = 0; $j <= rand(10, 100); $j++) {
$redis->set('test:' . $incr . ':string', $j);
}
示例13: array
/**
* Update manufacture
* @param array $data - associative array with data to store
* @return boolean
*/
function update_country($id, $data)
{
$query = $this->db->get_where('countries', array('ID' => $id));
$short_name = $query->row()->short_name;
$start_words_arr = explode("\n", $this->input->post('start_words'));
$error = false;
$this->db->query('BEGIN;SAVEPOINT spcountryUPD;');
$this->db->where('ID', $id);
$this->db->update('countries', $data);
$report = array();
$report['error'] = $this->db->_error_number();
$report['message'] = $this->db->_error_message();
if ($report['error'] == '') {
if (isset($start_words_arr)) {
$new_keys_insert = array();
foreach ($start_words_arr as $row) {
if ($row == "") {
continue;
}
$new_keys_insert[] = trim($row);
}
if (isset($new_keys_insert) and count($new_keys_insert) > 0) {
$redis = new Redis();
$redis->connect('127.0.0.1');
foreach ($new_keys_insert as $insert) {
$redis->sAdd("keys_status:{$short_name}:1", strtolower($insert));
}
$redis->close();
}
}
} else {
$error = true;
}
if ($error) {
$this->db->query('ROLLBACK TO SAVEPOINT spcountryUPD;');
} else {
$this->db->query('COMMIT;');
}
return !$error;
}
示例14: checkSerializer
private function checkSerializer($mode)
{
$this->redis->delete('key');
$this->assertTrue($this->redis->getOption(Redis::OPT_SERIALIZER) === Redis::SERIALIZER_NONE);
// default
$this->assertTrue($this->redis->setOption(Redis::OPT_SERIALIZER, $mode) === TRUE);
// set ok
$this->assertTrue($this->redis->getOption(Redis::OPT_SERIALIZER) === $mode);
// get ok
// lPush, rPush
$a = array('hello world', 42, TRUE, array('<tag>' => 1729));
$this->redis->delete('key');
$this->redis->lPush('key', $a[0]);
$this->redis->rPush('key', $a[1]);
$this->redis->rPush('key', $a[2]);
$this->redis->rPush('key', $a[3]);
// lGetRange
$this->assertTrue($a === $this->redis->lGetRange('key', 0, -1));
// lGet
$this->assertTrue($a[0] === $this->redis->lGet('key', 0));
$this->assertTrue($a[1] === $this->redis->lGet('key', 1));
$this->assertTrue($a[2] === $this->redis->lGet('key', 2));
$this->assertTrue($a[3] === $this->redis->lGet('key', 3));
// lRemove
$this->assertTrue($this->redis->lRemove('key', $a[3]) === 1);
$this->assertTrue(array_slice($a, 0, 3) === $this->redis->lGetRange('key', 0, -1));
// lSet
$a[0] = array('k' => 'v');
// update
$this->assertTrue(TRUE === $this->redis->lSet('key', 0, $a[0]));
$this->assertTrue($a[0] === $this->redis->lGet('key', 0));
// lInsert
$this->assertTrue($this->redis->lInsert('key', Redis::BEFORE, $a[0], array(1, 2, 3)) === 4);
$this->assertTrue($this->redis->lInsert('key', Redis::AFTER, $a[0], array(4, 5, 6)) === 5);
$a = array(array(1, 2, 3), $a[0], array(4, 5, 6), $a[1], $a[2]);
$this->assertTrue($a === $this->redis->lGetRange('key', 0, -1));
// sAdd
$this->redis->delete('key');
$s = array(1, 'a', array(1, 2, 3), array('k' => 'v'));
$this->assertTrue(1 === $this->redis->sAdd('key', $s[0]));
$this->assertTrue(1 === $this->redis->sAdd('key', $s[1]));
$this->assertTrue(1 === $this->redis->sAdd('key', $s[2]));
$this->assertTrue(1 === $this->redis->sAdd('key', $s[3]));
// variadic sAdd
$this->redis->delete('k');
$this->assertTrue(3 === $this->redis->sAdd('k', 'a', 'b', 'c'));
$this->assertTrue(1 === $this->redis->sAdd('k', 'a', 'b', 'c', 'd'));
// sRemove
$this->assertTrue(1 === $this->redis->sRemove('key', $s[3]));
$this->assertTrue(0 === $this->redis->sRemove('key', $s[3]));
// variadic
$this->redis->delete('k');
$this->redis->sAdd('k', 'a', 'b', 'c', 'd');
$this->assertTrue(2 === $this->redis->sRem('k', 'a', 'd'));
$this->assertTrue(2 === $this->redis->sRem('k', 'b', 'c', 'e'));
$this->assertTrue(FALSE === $this->redis->exists('k'));
// sContains
$this->assertTrue(TRUE === $this->redis->sContains('key', $s[0]));
$this->assertTrue(TRUE === $this->redis->sContains('key', $s[1]));
$this->assertTrue(TRUE === $this->redis->sContains('key', $s[2]));
$this->assertTrue(FALSE === $this->redis->sContains('key', $s[3]));
unset($s[3]);
// sMove
$this->redis->delete('tmp');
$this->redis->sMove('key', 'tmp', $s[0]);
$this->assertTrue(FALSE === $this->redis->sContains('key', $s[0]));
$this->assertTrue(TRUE === $this->redis->sContains('tmp', $s[0]));
unset($s[0]);
// sorted sets
$z = array('z0', array('k' => 'v'), FALSE, NULL);
$this->redis->delete('key');
// zAdd
$this->assertTrue(1 === $this->redis->zAdd('key', 0, $z[0]));
$this->assertTrue(1 === $this->redis->zAdd('key', 1, $z[1]));
$this->assertTrue(1 === $this->redis->zAdd('key', 2, $z[2]));
$this->assertTrue(1 === $this->redis->zAdd('key', 3, $z[3]));
// zDelete
$this->assertTrue(1 === $this->redis->zDelete('key', $z[3]));
$this->assertTrue(0 === $this->redis->zDelete('key', $z[3]));
unset($z[3]);
// check that zDelete doesn't crash with a missing parameter (GitHub issue #102):
$this->assertTrue(FALSE === @$this->redis->zDelete('key'));
// variadic
$this->redis->delete('k');
$this->redis->zAdd('k', 0, 'a');
$this->redis->zAdd('k', 1, 'b');
$this->redis->zAdd('k', 2, 'c');
$this->assertTrue(2 === $this->redis->zDelete('k', 'a', 'c'));
$this->assertTrue(1.0 === $this->redis->zScore('k', 'b'));
$this->assertTrue($this->redis->zRange('k', 0, -1, true) == array('b' => 1.0));
// zRange
$this->assertTrue($z === $this->redis->zRange('key', 0, -1));
// zScore
$this->assertTrue(0.0 === $this->redis->zScore('key', $z[0]));
$this->assertTrue(1.0 === $this->redis->zScore('key', $z[1]));
$this->assertTrue(2.0 === $this->redis->zScore('key', $z[2]));
// zRank
$this->assertTrue(0 === $this->redis->zRank('key', $z[0]));
$this->assertTrue(1 === $this->redis->zRank('key', $z[1]));
$this->assertTrue(2 === $this->redis->zRank('key', $z[2]));
//.........这里部分代码省略.........
示例15: sAdd
/**
* Add a value to a set
*
* @param string $key
* @param string $value
*/
public function sAdd($key, $value)
{
$this->_redis->sAdd($key, $value);
}