confused about Redis and how it will work -


i following article here , think want go hash route confused if have multiple taxi_car

<?php $redis->hset("taxi_car", "brand", "toyota"); $redis->hset("taxi_car", "model", "yaris"); $redis->hset("taxi_car", "license number", "ro-01-php"); $redis->hset("taxi_car", "year of fabrication", 2010); $redis->hset("taxi_car", "nr_starts", 0); /* $redis->hmset("taxi_car", array( "brand" => "toyota", "model" => "yaris", "license number" => "ro-01-php", "year of fabrication" => 2010, "nr_stats" => 0) ); */ echo "license number: " . $redis->hget("taxi_car", "license number") . "<br>"; // remove license number $redis->hdel("taxi_car", "license number"); // increment number of starts $redis->hincrby("taxi_car", "nr_starts", 1); $taxi_car = $redis->hgetall("taxi_car"); echo "all info taxi car"; echo "<pre>"; var_dump($taxi_car); echo "</pre>"; 

how create database has data taxi_cars in redis. know there no database keys in redis, using relational lingo here express myself. if have 1000 taxi_cars not want have 1000 initial keys. has subset of something. not sure how explain this.

edit

so lets under brand have toyota, honda, suzuki , under have different styles tacoma, accord etc

how go on inserting data , leter on retrieving it. thanks

you should not try map relational model concepts nosql store redis, rather think in term of data structures , access paths.

here number of simple examples:

porting sqlite redis

work keys in redis

how have relations many many in redis

here want store records of car models. first need identify them (i.e. primary key in relational terminology). can store these records in top level dictionary of redis.

you should not store:

taxi_car => hash{ brand" => "toyota", "model" => "yaris", etc ... } 

but:

taxi_car:1 => hash{ brand" => "toyota", "model" => "yaris", etc ... } taxi_car:2 => hash{ brand" => "toyota", "model" => "prius", etc ... } taxi_car:3 => hash{ brand" => "tesla", "model" => "model_s", etc ... } 

now, need anticipate access paths. instance retrieve cars per brand , model, need add sets (to used indexes):

brand:toyota => set{ 1 2 } brand:tesla => set{ 3 } model:yaris => set{ 1 } model:prius => set{ 2 } model:model_s => set{ 3 } 

so can retrieve:

# per brand smembers brand:toyota -> returns 1 2 hgetall taxi_car:1 hgetall taxi_car:2 # per model smembers model:prius -> returns 2 hgetall taxi_car:2 # per brand , per model (a bit useless here), plus associated data # sort used taxi_car data in 1 shot sinterstore tmp brand:toyota model:prius sort tmp nosort taxi_car:*->brand taxi_car:*->model etc ... 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -