Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compat with redis cluster #49

Merged
merged 1 commit into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/module/author.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Author {
final String githubId;
final String name;
final String email;

Author(this.name, this.email);
Author(this.githubId, this.name, this.email);
}
1 change: 1 addition & 0 deletions lib/module/redis/const.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class RedisConst {
static const String defaultHost = "localhost";
static const int defaultPort = 6379;
static const String defaultAddr = "localhost:6379";
static const String defaultUsername = "";
static const String defaultPassword = "";
}
4 changes: 2 additions & 2 deletions lib/persistent/persistent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ class Persistent {
return (await getApi()).codeList();
}

static Future<void> saveRedis(String name, String host, int port, String username, String password) async {
return (await getApi()).saveRedis(name, host, port, username, password);
static Future<void> saveRedis(String name, String addr, String username, String password) async {
return (await getApi()).saveRedis(name, addr, username, password);
}

static Future<void> deleteRedis(int id) async {
Expand Down
2 changes: 1 addition & 1 deletion lib/persistent/persistent_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ abstract class PersistentApi {

Future<List<CodePo>> codeList();

Future<void> saveRedis(String name, String host, int port, String username, String password);
Future<void> saveRedis(String name, String addr, String username, String password);

Future<void> deleteRedis(int id);

Expand Down
16 changes: 7 additions & 9 deletions lib/persistent/persistent_db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ class PersistentDb implements PersistentApi {
'CREATE TABLE code_list(id INTEGER PRIMARY KEY, name TEXT, code TEXT)',
);
await db.execute(
'CREATE TABLE redis_instances(id INTEGER PRIMARY KEY, name TEXT, host TEXT, port INTEGER, username TEXT, password TEXT)',
'CREATE TABLE redis_instances(id INTEGER PRIMARY KEY, name TEXT, addr TEXT, username TEXT, password TEXT)',
);
await db.execute(
'INSERT INTO redis_instances(name, host, port, username, password) VALUES ("example", "${RedisConst.defaultHost}", ${RedisConst.defaultPort}, "${RedisConst.defaultUsername}", "${RedisConst.defaultPassword}")',
'INSERT INTO redis_instances(name, addr, username, password) VALUES ("example", "${RedisConst.defaultAddr}", "${RedisConst.defaultUsername}", "${RedisConst.defaultPassword}")',
);
}

Expand Down Expand Up @@ -385,11 +385,10 @@ class PersistentDb implements PersistentApi {
}

@override
Future<void> saveRedis(String name, String host, int port, String username, String password) async {
Future<void> saveRedis(String name, String addr, String username, String password) async {
var aux = await getInstance();
var list = [name, host, port, username, password];
aux.database
.execute('INSERT INTO redis_instances(name, host, port, username, password) VALUES (?, ?, ?, ?, ?)', list);
var list = [name, addr, username, password];
aux.database.execute('INSERT INTO redis_instances(name, addr, username, password) VALUES (?, ?, ?, ?)', list);
}

@override
Expand All @@ -404,7 +403,7 @@ class PersistentDb implements PersistentApi {
final List<Map<String, dynamic>> maps = await aux.database.query('redis_instances');
return List.generate(maps.length, (i) {
var aux = maps[i];
return RedisInstancePo(aux['id'], aux['name'], aux['host'], aux['port'], aux['username'], aux['password']);
return RedisInstancePo(aux['id'], aux['name'], aux['addr'], aux['username'], aux['password']);
});
}

Expand All @@ -417,7 +416,6 @@ class PersistentDb implements PersistentApi {
return null;
}
var current = maps[0];
return RedisInstancePo(
current['id'], current['name'], current['host'], current['port'], current['username'], current['password']);
return RedisInstancePo(current['id'], current['name'], current['addr'], current['username'], current['password']);
}
}
9 changes: 4 additions & 5 deletions lib/persistent/persistent_memory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class PersistentMemory implements PersistentApi {
throw UnimplementedError();
}

Future<void> saveRedis(String name, String host, int port, String username, String password) {
Future<void> saveRedis(String name, String addr, String username, String password) {
// TODO: implement sqlInstance
throw UnimplementedError();
}
Expand All @@ -233,16 +233,15 @@ class PersistentMemory implements PersistentApi {

Future<List<RedisInstancePo>> redisInstances() async {
return [
new RedisInstancePo(0, "example", RedisConst.defaultHost, RedisConst.defaultPort, RedisConst.defaultUsername,
RedisConst.defaultPassword)
new RedisInstancePo(0, "example", RedisConst.defaultAddr, RedisConst.defaultUsername, RedisConst.defaultPassword)
];
}

Future<RedisInstancePo?> redisInstance(String name) async {
if (name != "example") {
return null;
}
return new RedisInstancePo(0, "example", RedisConst.defaultHost, RedisConst.defaultPort, RedisConst.defaultUsername,
RedisConst.defaultPassword);
return new RedisInstancePo(
0, "example", RedisConst.defaultAddr, RedisConst.defaultUsername, RedisConst.defaultPassword);
}
}
10 changes: 4 additions & 6 deletions lib/persistent/po/redis_instance_po.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
class RedisInstancePo {
final int id;
final String name;
final String host;
final int port;
final String addr;
final String username;
final String password;

RedisInstancePo(this.id, this.name, this.host, this.port, this.username, this.password);
RedisInstancePo(this.id, this.name, this.addr, this.username, this.password);

RedisInstancePo deepCopy() {
return new RedisInstancePo(id, name, host, port, username, password);
return new RedisInstancePo(id, name, addr, username, password);
}

Map<String, dynamic> toMap() {
return {
'id': id,
'name': name,
'host': host,
'port': port,
'addr': addr,
'username': username,
'password': password,
};
Expand Down
10 changes: 5 additions & 5 deletions lib/ui/general/author_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class AuthorScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
List<Author> authors = [
Author('fu_turer', "futurer@outlook.com"),
Author('goflutterjava', "goflutterjava@gmail.com"),
Author('lovehzj', "1922919664@qq.com"),
Author('shoothzj', 'shoothzj@gmail.com'),
Author('zxJin-x', 'jinzhixin096@gmail.com'),
Author('fu_turer', 'Tian Luo', "futurer@outlook.com"),
Author('goflutterjava', 'KeLe He', "goflutterjava@gmail.com"),
Author('lovehzj', 'TingTing Wang', "1922919664@qq.com"),
Author('shoothzj', 'ZhangJian He', 'shoothzj@gmail.com'),
Author('zxJin-x', 'ZhiXin Jin', 'jinzhixin096@gmail.com'),
];

return Scaffold(
Expand Down
13 changes: 5 additions & 8 deletions lib/ui/redis/redis_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class _RedisPageState extends State<RedisPage> {
columns: [
DataColumn(label: Text('Id')),
DataColumn(label: Text('Name')),
DataColumn(label: Text('Host')),
DataColumn(label: Text('Port')),
DataColumn(label: Text('Addr')),
DataColumn(label: Text('Username')),
DataColumn(label: Text('Delete instance')),
],
Expand All @@ -63,8 +62,7 @@ class _RedisPageState extends State<RedisPage> {
cells: [
DataCell(Text(itemRow.id.toString())),
DataCell(Text(itemRow.name)),
DataCell(Text(itemRow.host)),
DataCell(Text(itemRow.port.toString())),
DataCell(Text(itemRow.addr)),
DataCell(Text(itemRow.username)),
DataCellUtil.newDelDataCell(() {
vm.deleteRedis(itemRow.id);
Expand All @@ -86,13 +84,12 @@ class _RedisPageState extends State<RedisPage> {
final vm = Provider.of<RedisInstanceListViewModel>(context, listen: false);
var list = [
FormFieldDef('Instance Name'),
FormFieldDef('Host'),
FormFieldDef('Port'),
FormFieldDef('Addr'),
FormFieldDef('Username'),
FormFieldDef('Password'),
];
return FormUtil.createButton5("Redis Instance", list, context, (name, host, port, username, password) {
vm.createRedis(name, host, int.parse(port), username, password);
return FormUtil.createButton4("Redis Instance", list, context, (name, addr, username, password) {
vm.createRedis(name, addr, username, password);
});
}
}
4 changes: 2 additions & 2 deletions lib/vm/redis/redis_instance_list_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class RedisInstanceListViewModel extends ChangeNotifier {
notifyListeners();
}

Future<void> createRedis(String name, String host, int port, String username, String password) async {
Persistent.saveRedis(name, host, port, username, password);
Future<void> createRedis(String name, String addr, String username, String password) async {
Persistent.saveRedis(name, addr, username, password);
fetchRedisInstances();
}

Expand Down
8 changes: 2 additions & 6 deletions lib/vm/redis/redis_instance_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ class RedisInstanceViewModel {
return this.redisInstancePo.name;
}

String get host {
return this.redisInstancePo.host;
}

int get port {
return this.redisInstancePo.port;
String get addr {
return this.redisInstancePo.addr;
}

String get username {
Expand Down