Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems on increment, decrement & touch #62

Closed
n-i-m-a opened this issue Jan 13, 2015 · 5 comments
Closed

Problems on increment, decrement & touch #62

n-i-m-a opened this issue Jan 13, 2015 · 5 comments

Comments

@n-i-m-a
Copy link
Contributor

n-i-m-a commented Jan 13, 2015

I was adding a Redis driver when I spotted this:

$object being returned from

   function get($keyword, $option = array()) {
        if($this->is_driver == true) {
            $object = $this->driver_get($keyword,$option);
        } else {
            $object = $this->driver->driver_get($keyword,$option);
        }

        if($object == null) {
            return null;
        }
        return $object['value'];
    }

is not the entire array and only the 'value' so:

    function increment($keyword, $step = 1 , $option = array()) {
        $object = $this->get($keyword);
        if($object == null) {
            return false;
        } else {
            $value = (Int)$object['value'] + (Int)$step;
            $time = $object['expired_time'] - @date("U");
            $this->set($keyword,$value, $time, $option);
            return true;
        }
    }

    function decrement($keyword, $step = 1 , $option = array()) {
        $object = $this->get($keyword);
        if($object == null) {
            return false;
        } else {
            $value = (Int)$object['value'] - (Int)$step;
            $time = $object['expired_time'] - @date("U");
            $this->set($keyword,$value, $time, $option);
            return true;
        }
    }

    function touch($keyword, $time = 300, $option = array()) {
        $object = $this->get($keyword);
        if($object == null) {
            return false;
        } else {
            $value = $object['value'];
            $time = $object['expired_time'] - @date("U") + $time;
            $this->set($keyword, $value,$time, $option);
            return true;
        }
    }

will not work and will also mess up the cached values.

I'm fixing it by passing an option to the get method so it returns the entire array.

Will send a Pull request for both this issue and the Redis driver once resolved and tested.

@khoaofgod
Copy link
Member

I will take a look it when I get home after work. Thanks. Also, if you fix it and tested , you can send me a request.

khoaofgod added a commit that referenced this issue Jan 13, 2015
@khoaofgod khoaofgod self-assigned this Jan 13, 2015
@khoaofgod
Copy link
Member

@n-i-m-a do you have driver for Reddis? because right now on current version we dont have reddis.php , if you have it, put it on this branch.

Thanks.

@n-i-m-a
Copy link
Contributor Author

n-i-m-a commented Jan 13, 2015

I'm doing some final clean-up and tests with it. will send a pull request when done but would be best if someone else would also test it out before merging.

@khoaofgod
Copy link
Member

@n-i-m-a : after you send a pull request and update the driver Reddis.php I will do a test on it right away, since version 2.2 will be release next week, I will merge your Reddis.php driver and put ur name as contribute on next version.

Thanks, bro

@n-i-m-a
Copy link
Contributor Author

n-i-m-a commented Jan 14, 2015

I'll keep you updated on that + have sent an email to discuss some matters on handling the dependencies for redis.

Will close this issue as it has been solved already.

@n-i-m-a n-i-m-a closed this as completed Jan 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants