Naltox / telegram-node-bot

Node module for creating Telegram bots.
MIT License
723 stars 143 forks source link

Persisting data - set() never called #112

Closed muety closed 8 years ago

muety commented 8 years ago

I wanted to implement persistence with Redis and implemented a custom RedisStorage extending BaseStorage and overriding all of its methods. However, persistence doesn't work. Doing some debugging I found that the RedisStorage's set() method only gets called once, which is at the first time something is saved to the $.userSession. How can I achieve that my set() method gets called every time I modify the $.userSession object?

Also the get() method doesn't seem to work the way I supposed. Given the following implementation:

get(storage, key) {
        return new Promise(function (resolve, reject) {
            db.get(`${storage}_${key}`, (err, data) => {
                if (err) reject(err);
                else resolve(JSON.parse(data) || {})
            });
        });
    }
  1. I manually add some data to the database under the key "userStorage_1234567"
  2. I use a bot command to fetch the data
  3. I manually modify the data in the database
  4. I run the command again

I'd suggest that I get back the updated data, but I don't - it's still the same outdated one as in the first request.

Probably I understood the whole $.userSession concept wrong, so please help me.

Naltox commented 8 years ago

I will publish v4.0 soon, with more clean api for storage

muety commented 8 years ago

Looking forwards to v4.0, hope you're done soon :)

muety commented 8 years ago

Any plans on when v4 will come? :)

Naltox commented 8 years ago

@n1try Hey, very soon, writing docs write now.