forked from yash/test-repo
first commit
This commit is contained in:
35
server.js
Normal file
35
server.js
Normal file
@@ -0,0 +1,35 @@
|
||||
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();
|
||||
Reference in New Issue
Block a user