FluxaORM: A Golang ORM for MySQL and Redis
Guide
Plugins
GitHub
Guide
Plugins
GitHub
    • Introduction
    • Registry
    • Data pools
    • Entities
    • Entity fields
    • MySQL Indexes
    • Engine
    • ORM
    • Entity Schema
    • Schema Update
    • CRUD
    • Async flush
    • Searching for Entities
    • Redis Search Engine
    • MySQL Queries
    • Local Cache
    • Context Cache
    • Fake Delete
    • Dirty Streams
    • Redis Operations
    • Distributed Lock
    • Virtual Entities
    • Event Broker
    • Queries Log
    • Plugins
    • Log tables

Virtual Entities

By default every FluxaORM Entity is stored in MySQL. However, you can define entity as virtual and store it only in Redis or local cache.

Defining Virtual Entities

To mark Entity as virtual, you must add the virtual tag to the entity definition:

type MyVirtualEntity struct {
	ID            uint64     `orm:"virtual;redisCache"`
	Age           uint8      
	Name          string     
}

Warning

Don't forget to add the redisCache or localCache tag to the entity definition. Otherwise an error will be thrown.

Primary Key

You must define a primary key (ID) for virtual entities by setting ID value in your code when virtual entity is created.

row := fluxaorm.NewEntity[MyVirtualEntity](ctx)
row.ID // zero
row.ID = 1
ctx.Flush()

// OR
row := fluxaorm.NewEntityWithID[MyVirtualEntity](ctx, 1)
ctx.Flush()

Virtual Entity with Redis Search

Virtual entities can be indexed in Redis Search:

type MyVirtualEntity struct {
	ID            uint64     `orm:"virtual;redisCache;redisSearch=default"`
	Age           uint8      `orm:"searchable;sortable"`
	Name          string     `orm:"searchable"`
}

And later you can search for entities using Redis Search:

query = fluxaorm.NewRedisSearchQuery()
query.AddFilterNumber("Age", 18)
rows, total := fluxaorm.RedisSearch[MyVirtualEntity](ctx, query, nil)

Indexing virtual entities is not supported using built-in schema.ReindexRedisIndex mechanism. This code will throw an error:

schema := GetEntitySchema[MyVirtualEntity](orm)
schema.ReindexRedisIndex(ctx) // throws error

You must fill index by yourself using fluxaorm.NewEntity() method.

Edit this page
Last Updated: 11/17/25, 1:01 PM
Prev
Distributed Lock
Next
Event Broker