Coder Social home page Coder Social logo

rmi_php's Introduction

RMI TOOLS - Redis Multiple Index Tools

Rmi is basic Redis tool manager for php. Rmi has three tools.

  • RmiLimit: Limitation for ZINDEX Data. For example: users last 10 match results, products last 5 purchasers. (LIMIT Option for ZREMRANGEBYSCORE Command)
  • RmiCache: Cache for RmiLimit Data with your own pattern and lifetime.
  • RmiStorage: Hash based data set and get with your own pattern.

Rmi use phpredis for connect to Redis

Options

Required Fields:

  • type: Name of Data. matchresult, leaderboard, purchaseitem
  • patterns: Pattern settings of Rmi Tools. You can select which one to use or use all of tools.

Use all tools

'patterns' => array(
			Rmi::REDIS_KEY_LIMIT => '[id]',
			Rmi::REDIS_KEY_CACHE => '[paged][perpage]',
			Rmi::REDIS_KEY_STORAGE => '[key][id]'
		)

You can use only RmiLimit and RmiCache

'patterns' => array(
			Rmi::REDIS_KEY_LIMIT => '[id]',
			Rmi::REDIS_KEY_CACHE => '[paged][perpage]'
		)

Optional Fields:

  • keys: RmiStorage Keys. You can not use into pattern. Rmi use every key in REDIS_KEY_STORAGE pattern ([key][id])
  • max: RmiLimit Maximum Data to store per Pattern Key (id)
  • paged: Default is 1. Offset data generates this variable.
  • perpage: Default is 10. Limit data generates this variable.

Pattern Keys:

  • id: the key use in REDIS_KEY_LIMIT pattern ([id]) but you can use own key and variable.

Basic Usage

  1. Generate Redis Configration
$config = array(
		// host, port, auth, db
		array('127.0.0.1', 6379, null, 0)
	);
  1. Generate Handle Data (Options)
$handleData = array(
		'type' => 'matchresult',
		'patterns' => array(
			Rmi::REDIS_KEY_LIMIT => '[id]',
			Rmi::REDIS_KEY_CACHE => '[paged][perpage]',
			Rmi::REDIS_KEY_STORAGE => '[key][id]'
		),
		'id' => 123123,
		'keys' => array(
			'goal' => Rmi::RMI_STORAGE_INCR,
			'win' => Rmi::RMI_STORAGE_INCR,
			'user_info' => Rmi::RMI_STORAGE_JSON_ARRAY,
			'due_count' => Rmi::RMI_STORAGE_DECR,
			'matchtime' => Rmi::RMI_STORAGE_TIMESTAMP,
			'blocktime' => Rmi::RMI_STORAGE_EXPIRE
		),
		'max' => 10,
		'paged' => 1,
		'perpage' => 10
	);
  1. Init RmiManager
$rmiManager = new Rmi($config, $handleData);
  1. Use RmiLimit Update and Find
$rmiManager->updateByLimit(array('key'=>'value', 'id' => $i));

$limitData = $rmiManager->findByLimit();
  1. Use RmiCache Update and Find
$cacheData = $rmiManager->findByCache();
if(!$cacheData) {
	$cacheData = $rmiManager->findByLimit();
	$rmiManager->updateByCache($cacheData, 60);
}
  1. Use RmiStorage Update, Delete and Find
$rmiManager->updateByStorage(array(
		'goal' => 4,
		'win' => 1,
		'matchtime' => time(),
		'due_count' => 2,
		'blocktime' => 25,
		'user_info' => array(
			'name' => 'User1',
			'fulname' => 'First Second Name'
		)
));
$hashData = $rmiManager->findByStorage();
$rmiManager->deleteByStorage('due_count');
$rmiManager->deleteByStorage(array('blocktime'));
  1. Catch Exception
try
{

} catch (RmiException $rmiException) {
	echo $rmiException->getRmiMessage();
}

rmi_php's People

Contributors

uretgec avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.