Skip to content

Commit 8fc9335

Browse files
authored
Çoklu array ile redis kullanımı yapıldı. @ofke
1 parent 853555b commit 8fc9335

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

redis/redis_.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,41 @@ public function setHashAll($hashKey,$values = array()){
9696
}
9797
}
9898

99+
//hmset methodu kullanılarak belirtilen anahtara birçok değer tanımlanır.
100+
//setHashAll fonksiyonundan farklı olarak array içerisinde array içeren değerler gönderilebilir.
101+
public function setHashAllMultiArray($hashKey,$values = array()){
102+
/*
103+
* Örnek Kullanım :
104+
$redis->hmset($key, [
105+
0 =>[
106+
'age' => 44,
107+
'country' => 'finland',
108+
'occupation' => 'software engineer',
109+
'reknown' => 'linux kernel'
110+
],
111+
1 =>[
112+
'age' => 45,
113+
'country' => 'turkey',
114+
'occupation' => 'software engineer',
115+
'reknown' => 'linux kernel'
116+
],
117+
]);
118+
*/
119+
//Array ile gelen data içerisinde kaç array daha barındırıyor bakılıyor.
120+
$boyut = count($values);
121+
//Toplam boyut belirleniyor.
122+
$this->setText($hashKey."boyut",$boyut);
123+
$i=0;
124+
try {
125+
foreach ($values as $key => $value) {
126+
$this->setHashAll($hashKey.$i."tr", $value);
127+
$i++;
128+
}
129+
} catch (Exception $ex) {
130+
return "hata";
131+
}
132+
}
133+
99134
//hget methodunu kullanrak sadece belirtilen anahtara atanan tek değer alınır.
100135
public function getHashSingle($hashKey,$key){
101136
/*
@@ -109,6 +144,21 @@ public function getHashSingle($hashKey,$key){
109144
}
110145
}
111146

147+
//hget methodunu kullanrak sadece belirtilen anahtara atanan tek değer alınır.
148+
public function getHashFullMultiArray($hashKey){
149+
//Redis hafızasına alınan data boyutu
150+
$boyut = $this->getText($hashKey."boyut");
151+
$i = 0;
152+
try {
153+
for($i;$i<$boyut;$i++){
154+
$data[] = $this->redis->hgetall($hashKey.$i."tr");
155+
}
156+
return $data;
157+
} catch (Exception $ex) {
158+
return "hata";
159+
}
160+
}
161+
112162
//hget methodunu kullanrak sadece belirtilen anahtara atanan tek değer alınır.
113163
public function getHashFull($hashKey){
114164
/*

0 commit comments

Comments
 (0)