redis cheat sheet

علی ذوالفقار
1401/12/02 16:03:28 (160)
// connect to redis in node.js 
const redis = require('redis');
const redis_client = redis.createClient({url:'redis://user:password@127.0.0.1:6379'});
redis_client.on('error', (err) => console.log('Redis Client Error', err));
redis_client.connect();

// stroe data ( key / value ) in redis with timeout ttl for auto remove in node 
await(redis_client.set( key , value ,  { EX : 300 } ));  // store key , ttl : 5 min 5*60=300 
await(redis_client.set( key , value  )); // no ttl  

// delete data from redis in node.js 
await redis_client.del(KEY); // remove KEY from redis 


// set redis append-only percistance : 
    edit /etc/redis/redis.conf and set the option : 
    appendonly yes

// save percistance every 60 seconds and 10 key change : 
    edit /etc/redis/redis.conf and set the option : 
    save 60 10

// set redis password in /etc/redis/redis.conf : 
    requirepass Rosetta_Stone

// change password via redis-cli
    CONFIG SET requirepass "newpassword"
    CONFIG REWRITE


// increment an integer value of a key by a number : 
INCRBY key 10


// backup
    // TODO :  
// restore 
    // TODO : 

Back