-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from s8sg/inmemory-store
In-memory store
- Loading branch information
Showing
6 changed files
with
98 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
) | ||
|
||
type DefaultStateStore struct { | ||
flowName string | ||
requestId string | ||
cache map[string]string | ||
mux sync.Mutex | ||
} | ||
|
||
// Configure the StateStore with flow name and request ID | ||
func (ss *DefaultStateStore) Configure(flowName string, requestId string) { | ||
} | ||
|
||
// Initialize the StateStore (called only once in a request span) | ||
func (ss *DefaultStateStore) Init() error { | ||
ss.cache = make(map[string]string) | ||
return nil | ||
} | ||
|
||
// Set a value (override existing, or create one) | ||
func (ss *DefaultStateStore) Set(key string, value string) error { | ||
ss.mux.Lock() | ||
ss.cache[key] = value | ||
ss.mux.Unlock() | ||
return nil | ||
} | ||
|
||
// Get a value | ||
func (ss *DefaultStateStore) Get(key string) (string, error) { | ||
ss.mux.Lock() | ||
value, ok := ss.cache[key] | ||
ss.mux.Unlock() | ||
if !ok { | ||
return "", fmt.Errorf("key not found") | ||
} | ||
return value, nil | ||
} | ||
|
||
// Compare and Update a value | ||
func (ss *DefaultStateStore) Update(key string, oldValue string, newValue string) error { | ||
ss.mux.Lock() | ||
value, ok := ss.cache[key] | ||
if !ok { | ||
ss.mux.Unlock() | ||
return fmt.Errorf("key not found") | ||
} | ||
if value != oldValue { | ||
ss.mux.Unlock() | ||
return fmt.Errorf("value doesn't match") | ||
} | ||
ss.cache[key] = newValue | ||
ss.mux.Unlock() | ||
return nil | ||
} | ||
|
||
// Cleanup all the resources in StateStore (called only once in a request span) | ||
func (ss *DefaultStateStore) Cleanup() error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 6 additions & 7 deletions
13
template/faas-flow/vendor/github.com/s8sg/faas-flow/sdk/executor/executor.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.