blob: 45c00b0358401f94505d0eac2347ea8af49b1493 [file] [log] [blame]
<?php
include "User.php";
use \User as User;
//Connecting to Redis server on localhost
function connect(){
include 'config.php';
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->auth("$REDIS_PASS");
return $redis;
}
function redis_get($key){
$redis = connect();
return json_decode($redis->get($key));
}
function redis_get_user($key) {
$redis = connect();
$data = json_decode($redis->get($key), true);
if ($data && gettype($data) == "array") {
$user = new User();
$user->init_from_array($data);
#foreach ($data as $key => $value) $user->{$key} = $value;
#if (isset($data->password)) $user->set_password($data->password);
#$user = new User($data->username, $data->first_name, $data->last_name, $data->email, $data->password, $data->organization);
return $user;
} else {
return null;
}
}
function redis_set($key, $data, $timeout=null){
$redis = connect();
$redis->set($key, json_encode($data), $timeout);
}
function redis_inc_ipdata($ip, $attr, $get=false){
$count = redis_get($ip);
if ($count){
if (isset($count->$attr)) $count->$attr = $count->$attr+1;
else $count->$attr = 1;
}else $count = (object)[$attr=>1];
if (!$get) redis_set($ip, $count, 3600);
return $count->$attr;
}
function redis_delete($key){
$redis = connect();
$redis->del($key);
}