Skip to content
immudb docker run -d --net host -it --name immudb codenotary/immudb:latest

Expiration

It’s possible to achieve data expiration by using the ExpirableSet function. It provides logical deletion, it means that it is not physically deleted from db, but it’s not possible to query it anymore after deletion.

Go

 1package main
 2
 3import (
 4	"context"
 5	"log"
 6	"strings"
 7	"time"
 8
 9	immudb "github.com/codenotary/immudb/pkg/client"
10)
11
12func main() {
13	opts := immudb.DefaultOptions().
14		WithAddress("localhost").
15		WithPort(3322)
16
17	client := immudb.NewClient().WithOptions(opts)
18	err := client.OpenSession(
19		context.TODO(),
20		[]byte(`immudb`),
21		[]byte(`immudb`),
22		"defaultdb",
23	)
24	if err != nil {
25		log.Fatal(err)
26	}
27
28	defer client.CloseSession(context.TODO())
29
30	_, err = client.ExpirableSet(
31		context.TODO(),
32		[]byte("expirableKey"),
33		[]byte("expirableValue"),
34		time.Now(),
35	)
36	if err != nil {
37		log.Fatal(err)
38	}
39
40	// the following will raise an error with key not found
41	_, err = client.Get(
42		context.TODO(),
43		[]byte("expirableKey"),
44	)
45	if err == nil || !strings.Contains(err.Error(), "key not found") {
46		log.Fatalf("expecting key not found error: %v", err)
47	}
48}

Java

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Java sdk github project

.NET

1
2var client = new ImmuClient();
3await client.Open("immudb", "immudb", "defaultdb");
4
5await client.ExpirableSet("key1", "value1", DateTime.Now.AddDays(1));
6
7Entry entry = await client.VerifiedGet("key1");
8Console.WriteLine(entry.ToString());
9await client.Close();

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Java sdk github project

Python

 1from immudb import ImmudbClient
 2from datetime import datetime, timedelta
 3import time
 4
 5URL = "localhost:3322"  # immudb running on your machine
 6LOGIN = "immudb"        # Default username
 7PASSWORD = "immudb"     # Default password
 8DB = b"defaultdb"       # Default database name (must be in bytes)
 9
10def main():
11    client = ImmudbClient(URL)
12    client.login(LOGIN, PASSWORD, database = DB)
13    client.expireableSet(b"TEST", b"test", datetime.now() + timedelta(seconds=3))
14    print(client.get(b"TEST")) # b"test"
15    time.sleep(4)
16    try:
17        print(client.get(b"TEST"))
18    except:
19        pass # Key not found, because it expires, raises Exception
20
21if __name__ == "__main__":
22    main()

Node.js

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Node.js sdk github project

Others

If you’re using another development language, please refer to the immugw option.

Edit this page on GitHub Last updated