0812
This commit is contained in:
33
lib/services/redis_service.dart
Normal file
33
lib/services/redis_service.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class RedisService {
|
||||
static final RedisService _instance = RedisService._internal();
|
||||
|
||||
factory RedisService() => _instance;
|
||||
|
||||
RedisService._internal();
|
||||
|
||||
Future<void> setKeyValue(String key, Object value) async {
|
||||
final uri = Uri.parse('http://143.64.185.20:18606/redis/set');
|
||||
await http.post(
|
||||
uri,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: json.encode({'key': key, 'value': value}),
|
||||
);
|
||||
}
|
||||
|
||||
Future<String?> getValue(String key) async {
|
||||
try {
|
||||
final uri = Uri.parse('http://143.64.185.20:18606/redis/get?key=$key');
|
||||
final response = await http.get(uri);
|
||||
if (response.statusCode == 200) {
|
||||
return json.decode(response.body);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user