blob: edd0f6f3530c89d9b2fa5e6f16ba13de7f011a07 [file] [log] [blame]
matheusfillipeabd513e2021-05-11 03:29:11 -03001<?php
Marc Kupietz0215a442023-03-05 18:34:16 +01002 include "User.php";
3 use \User as User;
4
matheusfillipeabd513e2021-05-11 03:29:11 -03005 //Connecting to Redis server on localhost
6 function connect(){
7 include 'config.php';
8 $redis = new Redis();
9 $redis->connect('127.0.0.1', 6379);
10 $redis->auth("$REDIS_PASS");
11 return $redis;
12 }
13 function redis_get($key){
14 $redis = connect();
15 return json_decode($redis->get($key));
16 }
Marc Kupietz0215a442023-03-05 18:34:16 +010017
18 function redis_get_user($key) {
19 $redis = connect();
20 $data = json_decode($redis->get($key));
21 $user = new User($data->user_name, $data->first_name, $data->last_name, $data->email, $data->password, $data->organization);
22
23 return $user;
24 }
25
matheusfillipeabd513e2021-05-11 03:29:11 -030026 function redis_set($key, $data, $timeout=null){
27 $redis = connect();
28 $redis->set($key, json_encode($data), $timeout);
29 }
30
31 function redis_inc_ipdata($ip, $attr, $get=false){
32 $count = redis_get($ip);
33 if ($count){
34 if (isset($count->$attr)) $count->$attr = $count->$attr+1;
35 else $count->$attr = 1;
36 }else $count = (object)[$attr=>1];
37
38 if (!$get) redis_set($ip, $count, 3600);
39 return $count->$attr;
40 }
41
42 function redis_delete($key){
43 $redis = connect();
44 $redis->del($key);
45 }