Code Monkey home page Code Monkey logo

mysql-redis's People

Contributors

gi-singh avatar kwalski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mysql-redis's Issues

Refresh cache problem?

Hello @kwalski !
I followed your instructions regarding setting async version of MysqlRedis:
const { MysqlRedisAsync, HashTypes, Caching } = require("mysql-redis");
const redis = asyncRedis.createClient(settings.REDIS_PORT, settings.REDIS_HOST);
const pool = mysql.createPool({
host: settings.MYSQL_HOST,
user: settings.MYSQL_USER,
password: settings.MYSQL_PASS,
database: settings.MYSQL_DB
});
const promisePool = pool.promise();
const defaultCacheOptions = {
expire: settings.REDIS_CACHE_RETENTION,
keyPrefix: "sql.",
caching: Caching.CACHE
};
const mysqlRedis = new MysqlRedisAsync(
promisePool,
redis,
defaultCacheOptions
);

and then I execute simple query:
query = "SELECT * FROM categories where id=2;"

with async function
[queryOutput, queryDetails]=await mysqlRedis.query(query,
{
keyPrefix: 'sql.',
expire: settings.REDIS_CACHE_RETENTION,
caching: cachingOption
});

exchanging cachingOption with either
Caching.CACHE
or
Caching.REFRESH

I understand that if CACHE is used it uses Redis, if REFRESH it should update Redis with mysql data and return data from mysql

So now the problem...

I did query with Caching.CACHE and it created entry in Redis:

127.0.0.1:6379> keys *
1) "sql.M/LnlpXD5l24tMjRGgSX5w=="

All good

Then I updated DB manually with some small change...

again executing with Caching.CACHE and it gets (now outdated) data from Redis...
so far - ALL GOOD

so now I execute the same function but with Caching.REFRESH
and what should happen here?
from what I see it creates another entry in Redis

127.0.0.1:6379> keys *

1) "sql.Dg/8759875Xj3gS8cOzUbw=="
2) "sql.M/LnlpXD5l24tMjRGgSX5w=="

and it shows valid (updated) data from DB

but then when I switch back to Caching.CACHE it uses first entry (outdated) from Redis and displays wrong data...

shouldn't it be taken from new Redis entry?
Did I misunderstand something?

Mysql connection not release

Hi,
Thanks for this ,
I use this for socket.io, but i found that the connection not release, may i know how can i release connection after used?

My code before

const db = function () {
const redisOptions = {};
        const cacheOptions = {
            expire: 2629746,// seconds, defaults to 30 days
            keyPrefix: "sql.", // default
            hashType: HashTypes.blake2b512, //default
            caching: Caching.SKIP //default
        };
        const pool = mysql.createPool({
            connectionLimit: 2,
            host: env.DB_HOST,
            user: env.DB_USERNAME,
            password: env.DB_PASSWORD,
            database: env.DB_DATABASE
        }).promise();
        const redis = asyncRedis.createClient();
        return new MysqlRedisAsync(
            pool,
            redis,
            cacheOptions
        );
}

[data, fields] = db.query('SELECT * FROM USERS');
console.log(data)

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.