forked from yash/test-repo
36 lines
759 B
JavaScript
36 lines
759 B
JavaScript
import Redis from 'ioredis';
|
|
|
|
// Create a new Redis client (default localhost:6379)
|
|
const redis = new Redis({
|
|
host: '72.60.220.57',
|
|
port: 6379,
|
|
username: 'default',
|
|
password: '4~pI27tEpI4(',
|
|
|
|
});
|
|
|
|
async function run() {
|
|
try {
|
|
// Set a key
|
|
// await redis.set('username', 'yash946');
|
|
|
|
// Get the key
|
|
const value = await redis.get('username');
|
|
console.log('Fetched from Redis:', value);
|
|
|
|
// Set a key with expiry (in seconds)
|
|
await redis.set('session', 'xyz123', 'EX', 20); // expires in 10 seconds
|
|
|
|
// Get all keys
|
|
const keys = await redis.keys('*');
|
|
console.log('All keys:', keys);
|
|
|
|
// Close the connection`
|
|
redis.disconnect();
|
|
} catch (err) {
|
|
console.error('Redis error:', err);
|
|
}
|
|
}
|
|
|
|
run();
|