Overview

Namespaces

  • None
  • Wei
    • Validator

Classes

  • Apc
  • App
  • ArrayCache
  • Asset
  • Base
  • BaseCache
  • BaseController
  • Bicache
  • Cache
  • Config
  • Cookie
  • Couchbase
  • Counter
  • Db
  • DbCache
  • E
  • Env
  • Error
  • FileCache
  • Gravatar
  • Http
  • Lock
  • Logger
  • Memcache
  • Memcached
  • MongoCache
  • Password
  • PhpError
  • PhpFileCache
  • Pinyin
  • Record
  • Redis
  • Request
  • Response
  • Router
  • SafeUrl
  • Session
  • Soap
  • T
  • Ua
  • Upload
  • Url
  • Uuid
  • Validate
  • View
  • WeChatApp
  • Wei
  • Overview
  • Namespace
  • Class

Class Redis

A cache service that stored data in Redis

Wei\Base
Extended by Wei\BaseCache
Extended by Wei\Redis
Namespace: Wei
Author: Twin Huang twinhuang@qq.com
Located at Redis.php
Methods summary
public
# __construct( array $options = array() )

Constructor

Constructor

Parameters

$options

Throws

InvalidArgumentException
When option "wei" is not an instance of "Wei\Wei"

Overrides

Wei\Base::__construct()
public mixed
# __invoke( string $key = null, mixed $value = null, integer $expire = 0 )

Returns the redis object, retrieve or store an item

Returns the redis object, retrieve or store an item

Parameters

$key
The name of item
$value
The value of item
$expire
The expire seconds, defaults to 0, means never expired

Returns

mixed

Overrides

Wei\BaseCache::__invoke()
public boolean
# connect( )

Connect the redis server and set redis options

Connect the redis server and set redis options

Returns

boolean
true on success, false on error
public mixed
# get( string $key, integer $expire = null, callable $fn = null )

Retrieve an item

Retrieve an item

Parameters

$key
The name of item
$expire
The expire seconds of callback return value
$fn
The callback to execute when cache not found

Returns

mixed

Throws

RuntimeException
When set cache return false
public boolean
# set( string $key, mixed $value, integer $expire = 0 )

Store an item

Store an item

Parameters

$key
The name of item
$value
The value of item
$expire
The expire seconds, defaults to 0, means never expired

Returns

boolean
public array
# getMulti( array $keys )

Retrieve multiple items

Retrieve multiple items

Parameters

$keys
The name of items

Returns

array

Overrides

Wei\BaseCache::getMulti()
public array
# setMulti( array $items, integer $expire = 0 )

Store multiple items

Store multiple items

Note: 1. The "$expire" parameter is not support by redis MSET command 2. The elements in returning values are all true or false, see links for more detail

Parameters

$items
$keys The name of items
$expire

Returns

array

Link

http://redis.io/commands/mset
https://github.com/nicolasff/phpredis/blob/master/redis_array.c#L844

Overrides

Wei\BaseCache::setMulti()
public boolean
# remove( string $key )

Remove an item

Remove an item

Parameters

$key
The name of item

Returns

boolean
public boolean
# exists( string $key )

Check if an item is exists

Check if an item is exists

Parameters

$key

Returns

boolean
public boolean
# add( string $key, mixed $value, integer $expire = 0 )

Add an item

Add an item

Parameters

$key
The name of item
$value
The value of item
$expire
The expire seconds, defaults to 0, means never expired

Returns

boolean
public boolean
# replace( string $key, mixed $value, integer $expire = 0 )

Note: This method is not an atomic operation

Note: This method is not an atomic operation

Parameters

$key
The name of item
$value
The value of item
$expire
The expire seconds, defaults to 0, means never expired

Returns

boolean
public integer|false
# incr( string $key, integer $offset = 1 )

Increment an item

Increment an item

Parameters

$key
The name of item
$offset
The value to increased

Returns

integer|false
Returns the new value on success, or false on failure
public boolean
# clear( )

Clear all items

Clear all items

Returns

boolean
public Redis
# getObject( )

Get the redis object

Get the redis object

Returns

Redis
public
# setObject( Wei\Redis $object )

Set the redis object

Set the redis object

Parameters

$object

Returns


$this
Methods inherited from Wei\BaseCache
decr(), getFileContent(), getNamespace(), processGetResult(), setNamespace()
Methods inherited from Wei\Base
__call(), __get(), getOption(), setOption()
Properties summary
protected Redis $object

The redis object

The redis object

#
protected string $host

The host, or the path to a unix domain socket

The host, or the path to a unix domain socket

# '127.0.0.1'
protected integer $port

The port of the host

The port of the host

# 6379
protected float|integer $timeout

The timeout seconds

The timeout seconds

# 0.0
protected boolean $persistent

Whether persistent connection or not

Whether persistent connection or not

# true
protected string $auth

A password to authenticate the connection

A password to authenticate the connection

#
protected array $options

The options for \Redis::setOptions()

The options for \Redis::setOptions()

# array( \Redis::OPT_SERIALIZER => \Redis::SERIALIZER_PHP )
Properties inherited from Wei\BaseCache
$namespace
Properties inherited from Wei\Base
$providers, $wei
Wei Framework API documentation generated by ApiGen