-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
109 additions
and
87 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package commands | ||
|
||
import ( | ||
"bytes" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/alash3al/redix/internals/config" | ||
"github.com/alash3al/redix/internals/datastore/contract" | ||
"github.com/tidwall/redcon" | ||
) | ||
|
||
// Context represents the command context | ||
type Context struct { | ||
Conn redcon.Conn | ||
Engine contract.Engine | ||
Cfg *config.Config | ||
Argv [][]byte | ||
Argc int | ||
|
||
sync.RWMutex | ||
} | ||
|
||
// Session fetches the current session map | ||
func (c *Context) Session() map[string]interface{} { | ||
c.RLock() | ||
m := c.Conn.Context().(map[string]interface{}) | ||
c.RUnlock() | ||
|
||
return m | ||
} | ||
|
||
// SessionSet set a k-v into the current session | ||
func (c *Context) SessionSet(k string, v interface{}) { | ||
c.Lock() | ||
|
||
m := c.Conn.Context().(map[string]interface{}) | ||
m[k] = v | ||
c.Conn.SetContext(m) | ||
|
||
c.Unlock() | ||
} | ||
|
||
// SessionGet fetches a value from the current session | ||
func (c *Context) SessionGet(k string) (interface{}, bool) { | ||
val, ok := c.Session()[k] | ||
|
||
return val, ok | ||
} | ||
|
||
// AbsoluteKeyPath returns the full key path relative to the namespace the namespace | ||
func (c *Context) AbsoluteKeyPath(k ...[]byte) []byte { | ||
ns, _ := c.SessionGet("namespace") | ||
return []byte(ns.(string) + strings.TrimLeft(string(bytes.Join(k, []byte("/"))), "/")) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ server { | |
redis { | ||
listen = ":6380" | ||
max_connections = 100 | ||
async = true | ||
} | ||
} | ||
|
||
|