-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredis.php
executable file
·33 lines (30 loc) · 897 Bytes
/
redis.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
//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_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);
}