Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
ffdyndns
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Freifunk Luebeck
ffdyndns
Merge requests
!2
Draft:
#7
alternative kv db
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Draft:
#7
alternative kv db
#7_alternative_kv_db
into
master
Overview
0
Commits
10
Pipelines
8
Changes
6
Open
Philipp Rothmann
requested to merge
#7_alternative_kv_db
into
master
3 years ago
Overview
0
Commits
10
Pipelines
8
Changes
6
Expand
0
0
Merge request reports
Compare
master
version 8
48eaf002
3 years ago
version 7
d514eeda
3 years ago
version 6
af81490c
3 years ago
version 5
63d35392
3 years ago
version 4
1ff8ce99
3 years ago
version 3
a613f46a
3 years ago
version 2
8245dfc3
3 years ago
version 1
17872a92
3 years ago
master (base)
and
version 3
latest version
48eaf002
10 commits,
3 years ago
version 8
48eaf002
11 commits,
3 years ago
version 7
d514eeda
10 commits,
3 years ago
version 6
af81490c
9 commits,
3 years ago
version 5
63d35392
7 commits,
3 years ago
version 4
1ff8ce99
6 commits,
3 years ago
version 3
a613f46a
4 commits,
3 years ago
version 2
8245dfc3
3 commits,
3 years ago
version 1
17872a92
2 commits,
3 years ago
6 files
+
72
−
3
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
6
Search (e.g. *.vue) (Ctrl+P)
src/db2.rs
0 → 100644
+
44
−
0
Options
extern
crate
redis
;
use
log
::
info
;
use
redis
::
Commands
;
use
redis
::
FromRedisValue
;
use
redis
::
RedisError
;
use
redis
::
RedisResult
;
use
redis
::
ToRedisArgs
;
use
serde_json
as
json
;
use
std
::
path
::
PathBuf
;
use
crate
::
db
::
Domain
;
use
crate
::
sha256
;
pub
struct
Database
{
conn
:
redis
::
Connection
,
}
impl
Database
{
pub
fn
new
(
path
:
PathBuf
)
->
Result
<
Self
,
RedisError
>
{
let
client
=
redis
::
Client
::
open
(
"redis://127.0.0.1/"
)
?
;
// TODO extract path
let
c
=
client
.get_connection
()
?
;
Ok
(
Database
{
conn
:
c
})
// TODO Error handling
}
pub
fn
insert_new_domain
(
&
mut
self
,
d
:
&
Domain
)
{
let
value
=
json
::
to_vec
(
&
d
)
.unwrap
();
let
key
=
sha256!
(
&
d
.domainname
);
let
_
:
()
=
self
.conn.set
::
<
String
,
Vec
<
u8
>
,
_
>
(
key
,
value
)
.unwrap
();
// TODO Error handling
}
pub
fn
get_domain
(
&
mut
self
,
domain
:
&
String
)
->
Option
<
Domain
>
{
let
r
:
Vec
<
u8
>
=
self
.conn.get
::
<
String
,
Vec
<
u8
>>
(
sha256!
(
domain
))
.unwrap
();
// TODO Error handling
json
::
from_slice
(
&
r
)
.unwrap
()
}
}
#[test]
fn
it_saves_domain
()
{
let
mut
db
=
Database
::
new
(
PathBuf
::
from
(
"redis://127.0.0.1"
))
.unwrap
();
let
mut
d
=
Domain
::
new
(
String
::
from
(
"kaputt.cloud"
));
db
.insert_new_domain
(
&
mut
d
);
let
res
=
db
.get_domain
(
&
String
::
from
(
"kaputt.cloud"
))
.unwrap
();
assert_eq!
(
d
.token
,
res
.token
);
}
Loading