-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Redis integration for URL shortening and counter management
- Loading branch information
1 parent
b6df6c2
commit 9c2aebd
Showing
5 changed files
with
168 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package database | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"strconv" | ||
|
||
//"github.com/SartajBhuvaji/database" | ||
"github.com/joho/godotenv" | ||
) | ||
|
||
func databaseInitialize() { | ||
err := godotenv.Load() | ||
if err != nil { | ||
log.Fatalf("Error loading .env file: %v", err) | ||
} | ||
|
||
var redisHost string = os.Getenv("REDIS_HOST") | ||
var redisPassword string = os.Getenv("REDIS_PASSWORD") | ||
redisDB, err := strconv.Atoi(os.Getenv("REDIS_DB")) | ||
if err != nil { | ||
log.Fatalf("Error converting REDIS_DB to int: %v", err) | ||
} | ||
|
||
// Create a new RedisClient | ||
redisClient := NewRedisClient(redisHost, redisPassword, redisDB) | ||
//redisClient := database.NewRedisClient(redisHost, redisPassword, redisDB) | ||
|
||
defer redisClient.Close() | ||
|
||
// Test connection | ||
if err := redisClient.Ping(); err != nil { | ||
fmt.Printf("Could not connect to Redis: %v\n", err) | ||
return | ||
} else { | ||
fmt.Println("Connected to Redis") | ||
} | ||
|
||
// Set the counter to 1 | ||
redisClient.SetCounter("counter", 1) | ||
fmt.Println("Counter set to 1") | ||
} | ||
|
||
func main() { | ||
databaseInitialize() | ||
} | ||
|
||
// TO run : go run init.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters